Skip to content
Snippets Groups Projects
Commit e297f287 authored by Bentriou Mahmoud's avatar Bentriou Mahmoud
Browse files

rewriting parts of core/lha

parent 190833bb
No related branches found
No related tags found
No related merge requests found
......@@ -155,7 +155,7 @@ function next_state!(Snplus1::StateLHA, A::LHA,
Sn::StateLHA, xn::Vector{Int}, p::Vector{Float64}; verbose::Bool = false)
# En fait d'apres observation de Cosmos, après qu'on ait lu la transition on devrait stop.
edge_candidates = Vector{Edge}(undef, 2)
first_round::Bool = true
#first_round::Bool = true
detected_event::Bool = false
turns = 0
......@@ -167,7 +167,8 @@ function next_state!(Snplus1::StateLHA, A::LHA,
end
# In terms of values not reference, Snplus1 == Sn
# First, we check the asynchronous transitions
while first_round || length(edge_candidates) > 0
#while first_round || length(edge_candidates) > 0
while true
turns += 1
#edge_candidates = empty!(edge_candidates)
current_loc = getfield(Snplus1, :loc)
......@@ -179,10 +180,13 @@ function next_state!(Snplus1::StateLHA, A::LHA,
ind_edge, detected_event = _get_edge_index(edge_candidates, nbr_candidates, detected_event, nothing)
# Update the state with the chosen one (if it exists)
# Should be xn here
#first_round = false
if ind_edge > 0
getfield(edge_candidates[ind_edge], :update_state!)(Snplus1, xn, p)
else
if verbose println("No edge fired") end
break
end
first_round = false
if verbose
@show turns
@show edge_candidates
......@@ -190,9 +194,6 @@ function next_state!(Snplus1::StateLHA, A::LHA,
println("After update")
@show Snplus1
end
if (ind_edge == 0)
break
end
# For debug
#=
if turns > 100
......@@ -227,8 +228,9 @@ function next_state!(Snplus1::StateLHA, A::LHA,
@show Snplus1
end
# Now firing an edge according to the event
first_round = true
while first_round || length(edge_candidates) > 0
#first_round = true
#while first_round || length(edge_candidates) > 0
while true
turns += 1
current_loc = getfield(Snplus1, :loc)
edges_from_current_loc = getfield(A, :map_edges)[current_loc]
......@@ -237,23 +239,34 @@ function next_state!(Snplus1::StateLHA, A::LHA,
# Search the one we must chose
ind_edge, detected_event = _get_edge_index(edge_candidates, nbr_candidates, detected_event, tr_nplus1)
# Update the state with the chosen one (if it exists)
if verbose
@show turns
@show edge_candidates
@show ind_edge, detected_event, nbr_candidates
end
#first_round = false
if ind_edge > 0
getfield(edge_candidates[ind_edge], :update_state!)(Snplus1, xnplus1, p)
end
first_round = false
if ind_edge == 0 || detected_event
if verbose
if detected_event
println("Synchronized with $(tr_nplus1)")
@show turns
@show edge_candidates
@show ind_edge, detected_event, nbr_candidates
println("After update")
@show detected_event
@show Snplus1
else
println("No edge fired")
end
end
break
end
if verbose
@show turns
@show edge_candidates
@show ind_edge, detected_event, nbr_candidates
println("After update")
@show detected_event
@show Snplus1
end
if (ind_edge == 0 || detected_event)
break
end
# For debug
#=
if turns > 100
......
......@@ -13,7 +13,7 @@ observe_all!(ER)
test_all = true
# SIR model
nbr_sim = 20
nbr_sim = 10
for i = 1:nbr_sim
set_param!(SIR, [:ki, :kr], [rand(Uniform(5E-5, 3E-3)), rand(Uniform(5E-3, 0.2))])
let tml_obs, y_obs, sync_SIR, σ, test, test2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment