Skip to content

Commit

Permalink
Fix higher dimensional bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmskov committed Sep 1, 2023
1 parent 6fcdf07 commit be2f410
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/abstraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ function grid_generator(L, U, δ)
end

function calculate_explicit_states(grid, grid_spacing)
# initialize an array of 2x2 matrices
# initialize an array of nx2 matrices
n = length(grid_spacing)
states = Array{Array{Float64,2},1}(undef, length(grid))
for (i, grid_point) in enumerate(grid)
states[i] = [grid_point[1] grid_point[1] + grid_spacing[1]; grid_point[2] grid_point[2] + grid_spacing[2]]
state = zeros(Float64, n, 2)
for j in 1:n
state[j,1] = grid_point[j]
state[j,2] = grid_point[j] + grid_spacing[j]
end
states[i] = state
end
return states
end
Expand Down
19 changes: 17 additions & 2 deletions src/refinement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,34 @@ function uniform_refinement(state)
return new_states
end

function refine_states!(explicit_states, states_to_refine)
function refine_states!(explicit_states, states_to_refine; min_size=0.001)
new_states = []
state_map_dict = Dict()
new_state_idx = length(explicit_states) - length(states_to_refine) + 1
states_skipped = []
for state_idx in states_to_refine
if !all(explicit_states[state_idx][:,2] - explicit_states[state_idx][:,1] .> min_size)
push!(states_skipped, state_idx)
continue
end
refined_states = uniform_refinement(explicit_states[state_idx])
push!(new_states, refined_states...)
state_map_dict[state_idx] = new_state_idx:1:(new_state_idx+length(refined_states)-1)
new_state_idx += length(refined_states)
end

if length(states_skipped) > 0
states_to_refine = setdiff(states_to_refine, states_skipped)
@warn "Skipped $(length(states_skipped)) states because they were too small."
end

deleteat!(explicit_states, states_to_refine)
explicit_states = push!(explicit_states, new_states...)
return state_map_dict
end

function refine_images!(explicit_states, state_images, states_to_refine, user_defined_map)
dim_factor = size(state_images[1],1)^2
dim_factor = 2^size(state_images[1],1)
original_state_num = length(explicit_states) - dim_factor*length(states_to_refine) # this should be the length of the original images...
@assert length(state_images) == original_state_num + length(states_to_refine)

Expand Down Expand Up @@ -182,6 +193,10 @@ function refine_transitions(explicit_states, state_index_dict, state_images, sta

if all(state_images[unrefined_state_index] .== 0)
# cannot reuse the lower-bound when we are splitting states
if warn_count < 5
@warn "Zero-valued image!"
warn_count += 1
end
Plow_new[new_index, target_indeces] .= 0
Phigh_new[new_index, target_indeces] .= Phigh[unrefined_state_index, original_target_index]
else
Expand Down

0 comments on commit be2f410

Please sign in to comment.