From 0ffb9f9d326f15f91adc056a112c93d8ce0fe233 Mon Sep 17 00:00:00 2001 From: Mahmoud Bentriou <mahmoud.bentriou@centralesupelec.fr> Date: Tue, 23 Feb 2021 18:57:40 +0100 Subject: [PATCH] I tried to optimize with multiple dispatch and types but it doesn't work. --- automata/automaton_G_and_F.jl | 231 +++++++++++++++++----------------- core/lha.jl | 2 +- 2 files changed, 119 insertions(+), 114 deletions(-) diff --git a/automata/automaton_G_and_F.jl b/automata/automaton_G_and_F.jl index db892ae..ba05cab 100644 --- a/automata/automaton_G_and_F.jl +++ b/automata/automaton_G_and_F.jl @@ -1,6 +1,7 @@ # Creation of the automaton types -@everywhere @eval abstract type EdgeAutomatonGandF <: Edge end +#@everywhere @eval abstract type EdgeAutomatonGandF <: Edge end +@everywhere struct EdgeAutomatonGandF{T} <: Edge transitions::Union{Nothing,Vector{Symbol}} end @everywhere @eval $(MarkovProcesses.generate_code_lha_type_def(:AutomatonGandF, :EdgeAutomatonGandF)) function create_automaton_G_and_F(m::ContinuousTimeModel, x1::Float64, x2::Float64, t1::Float64, t2::Float64, sym_obs_G::VariableModel, @@ -57,20 +58,24 @@ function create_automaton_G_and_F(m::ContinuousTimeModel, x1::Float64, x2::Float to_idx(var::Symbol) = map_var_automaton_idx[var] id = MarkovProcesses.newid() - basename_func = "$(model_name)_$(id)" - edge_name(from_loc::Location, to_loc::Location, edge_number::Int) = - Symbol("Edge_$(lha_name)_$(basename_func)_$(from_loc)$(to_loc)_$(edge_number)") + #Symbol("Edge_$(lha_name)_$(basename_func)_$(from_loc)$(to_loc)_$(edge_number)") + function generate_edge_type(from_loc::Location, to_loc::Location, edge_number::Int) + tag_type = Symbol("$(from_loc)$(to_loc)_$(edge_number)_$(model_name)_$(id)") + @eval type = EdgeAutomatonGandF{$(Meta.quot(tag_type))} + return @eval($type) + end ## check_constraints & update_state! @everywhere @eval begin + #return quote istrue(val::Float64) = convert(Bool, val) ## Edges check constraint and update state functions # l0G loc # l0G => l1G - @everywhere struct $(edge_name(:l0G, :l1G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l0G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true - @everywhere $(update_state!)(edge::$(edge_name(:l0G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l0G, :l1G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l0G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true + $(update_state!)(edge::$(generate_edge_type(:l0G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = 0; S_values[$(to_idx(:n))] = x[$(idx_obs_var_G)]; S_values[$(to_idx(:in))] = true; @@ -79,125 +84,125 @@ function create_automaton_G_and_F(m::ContinuousTimeModel, x1::Float64, x2::Float # l1G loc # l1G => l3G - @everywhere struct $(edge_name(:l1G, :l3G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1G, :l3G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1G, :l3G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1G, :l3G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = S_time <= $t1 && S_values[$(to_idx(:n))] < $x1 || S_values[$(to_idx(:n))] > $x2 - @everywhere $(update_state!)(edge::$(edge_name(:l1G, :l3G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1G, :l3G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = min(abs($x1 - S_values[$(to_idx(:n))]), abs($x2 - S_values[$(to_idx(:n))])); S_values[$(to_idx(:in))] = false; :l3G) - @everywhere struct $(edge_name(:l1G, :l3G, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1G, :l3G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1G, :l3G, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1G, :l3G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_time <= $t1) && ($x1 <= S_values[$(to_idx(:n))] <= $x2) - @everywhere $(update_state!)(edge::$(edge_name(:l1G, :l3G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1G, :l3G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = 0; S_values[$(to_idx(:in))] = false; :l3G) - @everywhere struct $(edge_name(:l1G, :l3G, 3)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1G, :l3G, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1G, :l3G, 3)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1G, :l3G, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = !istrue(S_values[$(to_idx(:in))]) && ($t1 <= S_time <= $t2) && ($x1 <= S_values[$(to_idx(:n))] <= $x2) - @everywhere $(update_state!)(edge::$(edge_name(:l1G, :l3G, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1G, :l3G, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] * (S_time - $t1); S_values[$(to_idx(:tprime))] = 0.0; :l3G) - @everywhere struct $(edge_name(:l1G, :l3G, 4)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1G, :l3G, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1G, :l3G, 4)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1G, :l3G, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = istrue(S_values[$(to_idx(:in))]) && ($t1 <= S_time <= $t2) && ($x1 <= S_values[$(to_idx(:n))] <= $x2) - @everywhere $(update_state!)(edge::$(edge_name(:l1G, :l3G, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1G, :l3G, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:tprime))] = 0.0; :l3G) # l1G => l4G - @everywhere struct $(edge_name(:l1G, :l4G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1G, :l4G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1G, :l4G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1G, :l4G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = !istrue(S_values[$(to_idx(:in))]) && ($t1 <= S_time <= $t2) && (S_values[$(to_idx(:n))] < $x1 || S_values[$(to_idx(:n))] > $x2) - @everywhere $(update_state!)(edge::$(edge_name(:l1G, :l4G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1G, :l4G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] + S_values[$(to_idx(:d))] * (S_time - $t1); :l4G) - @everywhere struct $(edge_name(:l1G, :l4G, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1G, :l4G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1G, :l4G, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1G, :l4G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = istrue(S_values[$(to_idx(:in))]) && ($t1 <= S_time <= $t2) && (S_values[$(to_idx(:n))] < $x1 || S_values[$(to_idx(:n))] > $x2) - @everywhere $(update_state!)(edge::$(edge_name(:l1G, :l4G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1G, :l4G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (:l4G) # l1G => l2G #= - @everywhere struct $(edge_name(:l1G, :l2G, 3)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1G, :l2G, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1G, :l2G, 3)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1G, :l2G, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = istrue(S_values[$(to_idx(:isabs))]) && S_time <= $t1 - @everywhere $(update_state!)(edge::$(edge_name(:l1G, :l2G, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1G, :l2G, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = ($t2 - $t1) * min(abs($x1 - S_values[$(to_idx(:n))]), abs($x2 - S_values[$(to_idx(:n))])); :l2G) - @everywhere struct $(edge_name(:l1G, :l2G, 4)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1G, :l2G, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1G, :l2G, 4)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1G, :l2G, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = istrue(S_values[$(to_idx(:isabs))]) && ($t1 <= S_time <= $t2) - @everywhere $(update_state!)(edge::$(edge_name(:l1G, :l2G, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1G, :l2G, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] + ($t2 - S_time) * min(abs($x1 - S_values[$(to_idx(:n))]), abs($x2 - S_values[$(to_idx(:n))])); :l2G) - @everywhere struct $(edge_name(:l1G, :l2G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1G, :l2G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = istrue(S_values[$(to_idx(:in))]) && S_time >= $t2 - @everywhere $(update_state!)(edge::$(edge_name(:l1G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (:l2G) - @everywhere struct $(edge_name(:l1G, :l2G, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1G, :l2G, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = !istrue(S_values[$(to_idx(:in))]) && S_time >= $t2 - @everywhere $(update_state!)(edge::$(edge_name(:l1G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] * ($t2 - $t1); :l2G) =# # l3G loc # l3G => l1G - @everywhere struct $(edge_name(:l3G, :l1G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l3G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true - @everywhere $(update_state!)(edge::$(edge_name(:l3G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l3G, :l1G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l3G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true + $(update_state!)(edge::$(generate_edge_type(:l3G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:n))] = x[$(idx_obs_var_G)]; S_values[$(to_idx(:isabs))] = $(m.isabsorbing)(p, x); :l1G) # l3G => l2G - @everywhere struct $(edge_name(:l3G, :l2G, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l3G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l3G, :l2G, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l3G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = istrue(S_values[$(to_idx(:in))]) && (S_time >= $t2 || istrue(S_values[$(to_idx(:isabs))])) - @everywhere $(update_state!)(edge::$(edge_name(:l3G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l3G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] * ($t2 - $t1); :l2G) - @everywhere struct $(edge_name(:l3G, :l2G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l3G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l3G, :l2G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l3G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = !istrue(S_values[$(to_idx(:in))]) && (S_time >= $t2 || istrue(S_values[$(to_idx(:isabs))])) - @everywhere $(update_state!)(edge::$(edge_name(:l3G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l3G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (:l2G) # l4G loc # l4G => l1G - @everywhere struct $(edge_name(:l4G, :l1G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l4G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true - @everywhere $(update_state!)(edge::$(edge_name(:l4G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l4G, :l1G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l4G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true + $(update_state!)(edge::$(generate_edge_type(:l4G, :l1G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] + S_values[$(to_idx(:tprime))] * min(abs($x1 - S_values[$(to_idx(:n))]), abs($x2 - S_values[$(to_idx(:n))])); S_values[$(to_idx(:tprime))] = 0.0; S_values[$(to_idx(:n))] = x[$(idx_obs_var_G)]; @@ -206,103 +211,103 @@ function create_automaton_G_and_F(m::ContinuousTimeModel, x1::Float64, x2::Float :l1G) # l4G => l2G - @everywhere struct $(edge_name(:l4G, :l2G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l4G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l4G, :l2G, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l4G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (istrue(S_values[$(to_idx(:isabs))])) - @everywhere $(update_state!)(edge::$(edge_name(:l4G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l4G, :l2G, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] + ($t2 - S_time) * min(abs($x1 - S_values[$(to_idx(:n))]), abs($x2 - S_values[$(to_idx(:n))])); :l2G) - @everywhere struct $(edge_name(:l4G, :l2G, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l4G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l4G, :l2G, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l4G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_time >= $t2) - @everywhere $(update_state!)(edge::$(edge_name(:l4G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l4G, :l2G, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] + S_values[$(to_idx(:tprime))] * min(abs($x1 - S_values[$(to_idx(:n))]), abs($x2 - S_values[$(to_idx(:n))])); :l2G) # Connection between the two automata: l2G => l1F - @everywhere struct $(edge_name(:l2G, :l1F, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l2G, :l1F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true - @everywhere $(update_state!)(edge::$(edge_name(:l2G, :l1F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l2G, :l1F, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l2G, :l1F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true + $(update_state!)(edge::$(generate_edge_type(:l2G, :l1F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:n))] = x[$(idx_obs_var_F)]; S_values[$(to_idx(:dprime))] = Inf; S_values[$(to_idx(:isabs))] = $(m.isabsorbing)(p, x); :l1F) - # l1F loc : we construct the edges of the form l1F => (..) + # l1F loc : we con#struct the edges of the form l1F => (..) # l1F => l2F - @everywhere struct $(edge_name(:l1F, :l2F, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1F, :l2F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1F, :l2F, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1F, :l2F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = S_time >= $t3 && S_values[$(to_idx(:dprime))] == 0 - @everywhere $(update_state!)(edge::$(edge_name(:l1F, :l2F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1F, :l2F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (#S_values[$(to_idx(:dprime))] = 0; :l2F) - @everywhere struct $(edge_name(:l1F, :l2F, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1F, :l2F, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1F, :l2F, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1F, :l2F, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_time >= $t4) && (S_values[$(to_idx(:n))] < $x3 || S_values[$(to_idx(:n))] > $x4) - @everywhere $(update_state!)(edge::$(edge_name(:l1F, :l2F, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1F, :l2F, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (#S_values[$(to_idx(:dprime))] = min(abs(S_values[$(to_idx(:n))] - $x3), abs(S_values[$(to_idx(:n))] - $x4)); S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] + S_values[$(to_idx(:dprime))]; :l2F) #= - @everywhere struct $(edge_name(:l1F, :l2F, 3)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1F, :l2F, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1F, :l2F, 3)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1F, :l2F, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = istrue(S_values[$(to_idx(:isabs))]) && S_time <= $t4 - @everywhere $(update_state!)(edge::$(edge_name(:l1F, :l2F, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1F, :l2F, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] + S_values[$(to_idx(:dprime))]; :l2F) - @everywhere struct $(edge_name(:l1F, :l2F, 4)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1F, :l2F, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1F, :l2F, 4)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1F, :l2F, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = S_time >= $t3 && S_values[$(to_idx(:dprime))] == 0 - @everywhere $(update_state!)(edge::$(edge_name(:l1F, :l2F, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1F, :l2F, 4)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (:l2F) =# # l1F => l3F - @everywhere struct $(edge_name(:l1F, :l3F, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1F, :l3F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1F, :l3F, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1F, :l3F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_time <= $t3) && (S_values[$(to_idx(:n))] < $x3 || S_values[$(to_idx(:n))] > $x4) - @everywhere $(update_state!)(edge::$(edge_name(:l1F, :l3F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1F, :l3F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:dprime))] = min(sqrt((S_time - $t3)^2 + (S_values[$(to_idx(:n))] - $x4)^2), sqrt((S_time - $t3)^2 + (S_values[$(to_idx(:n))] - $x3)^2)); :l3F) - @everywhere struct $(edge_name(:l1F, :l3F, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1F, :l3F, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1F, :l3F, 2)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1F, :l3F, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = ($x3 <= S_values[$(to_idx(:n))] <= $x4) - @everywhere $(update_state!)(edge::$(edge_name(:l1F, :l3F, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1F, :l3F, 2)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:dprime))] = 0; :l3F) - @everywhere struct $(edge_name(:l1F, :l3F, 3)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l1F, :l3F, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l1F, :l3F, 3)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l1F, :l3F, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_time >= $t3) && (S_values[$(to_idx(:n))] < $x3 || S_values[$(to_idx(:n))] > $x4) - @everywhere $(update_state!)(edge::$(edge_name(:l1F, :l3F, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l1F, :l3F, 3)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:dprime))] = min(S_values[$(to_idx(:dprime))], min(abs(S_values[$(to_idx(:n))] - $x3), abs(S_values[$(to_idx(:n))] - $x4))); :l3F) # l3F loc # l3F => l1F - @everywhere struct $(edge_name(:l3F, :l1F, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l3F, :l1F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true - @everywhere $(update_state!)(edge::$(edge_name(:l3F, :l1F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l3F, :l1F, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l3F, :l1F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true + $(update_state!)(edge::$(generate_edge_type(:l3F, :l1F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:n))] = x[$(idx_obs_var_F)]; S_values[$(to_idx(:isabs))] = $(m.isabsorbing)(p, x); :l1F) # l3F => l2F - @everywhere struct $(edge_name(:l3F, :l2F, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end - $(check_constraints)(edge::$(edge_name(:l3F, :l2F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + #struct $(generate_edge_type(:l3F, :l2F, 1)) <: $(edge_type) transitions::Union{Nothing,Vector{Symbol}} end + $(check_constraints)(edge::$(generate_edge_type(:l3F, :l2F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_time >= $t4 || istrue(S_values[$(to_idx(:isabs))])) - @everywhere $(update_state!)(edge::$(edge_name(:l3F, :l2F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = + $(update_state!)(edge::$(generate_edge_type(:l3F, :l2F, 1)), S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = (S_values[$(to_idx(:d))] = S_values[$(to_idx(:d))] + S_values[$(to_idx(:dprime))]; :l2F) end @@ -315,77 +320,77 @@ function create_automaton_G_and_F(m::ContinuousTimeModel, x1::Float64, x2::Float # l0G loc # l0G => l1G - edge1 = $(edge_name(:l0G, :l1G, 1))(nothing) + edge1 = $(generate_edge_type(:l0G, :l1G, 1))(nothing) map_edges[:l0G][:l1G] = [edge1] # l1G => l3G - edge1 = $(edge_name(:l1G, :l3G, 1))(nothing) - edge2 = $(edge_name(:l1G, :l3G, 2))(nothing) - edge3 = $(edge_name(:l1G, :l3G, 3))(nothing) - edge4 = $(edge_name(:l1G, :l3G, 4))(nothing) + edge1 = $(generate_edge_type(:l1G, :l3G, 1))(nothing) + edge2 = $(generate_edge_type(:l1G, :l3G, 2))(nothing) + edge3 = $(generate_edge_type(:l1G, :l3G, 3))(nothing) + edge4 = $(generate_edge_type(:l1G, :l3G, 4))(nothing) map_edges[:l1G][:l3G] = [edge1, edge2, edge3, edge4] # l1G => l4G - edge1 = $(edge_name(:l1G, :l4G, 1))(nothing) - edge2 = $(edge_name(:l1G, :l4G, 2))(nothing) + edge1 = $(generate_edge_type(:l1G, :l4G, 1))(nothing) + edge2 = $(generate_edge_type(:l1G, :l4G, 2))(nothing) map_edges[:l1G][:l4G] = [edge1, edge2] # l1G => l2G #= - edge1 = $(edge_name(:l1G, :l2G, 1))(nothing) - edge2 = $(edge_name(:l1G, :l2G, 2))(nothing) - edge3 = $(edge_name(:l1G, :l2G, 3))(nothing) - edge4 = $(edge_name(:l1G, :l2G, 4))(nothing) + edge1 = $(generate_edge_type(:l1G, :l2G, 1))(nothing) + edge2 = $(generate_edge_type(:l1G, :l2G, 2))(nothing) + edge3 = $(generate_edge_type(:l1G, :l2G, 3))(nothing) + edge4 = $(generate_edge_type(:l1G, :l2G, 4))(nothing) map_edges[:l1G][:l2G] = [edge3, edge4, edge1, edge2] =# # l3G loc # l3G => l1G - edge1 = $(edge_name(:l3G, :l1G, 1))([:ALL]) + edge1 = $(generate_edge_type(:l3G, :l1G, 1))([:ALL]) map_edges[:l3G][:l1G] = [edge1] # l3G => l2G - edge1 = $(edge_name(:l3G, :l2G, 1))(nothing) - edge2 = $(edge_name(:l3G, :l2G, 2))(nothing) + edge1 = $(generate_edge_type(:l3G, :l2G, 1))(nothing) + edge2 = $(generate_edge_type(:l3G, :l2G, 2))(nothing) map_edges[:l3G][:l2G] = [edge1, edge2] # l4 loc # l4G => l1G - edge1 = $(edge_name(:l4G, :l1G, 1))([:ALL]) + edge1 = $(generate_edge_type(:l4G, :l1G, 1))([:ALL]) map_edges[:l4G][:l1G] = [edge1] # l4G => l2G - edge1 = $(edge_name(:l4G, :l2G, 1))(nothing) - edge2 = $(edge_name(:l4G, :l2G, 2))(nothing) + edge1 = $(generate_edge_type(:l4G, :l2G, 1))(nothing) + edge2 = $(generate_edge_type(:l4G, :l2G, 2))(nothing) map_edges[:l4G][:l2G] = [edge1,edge2] # l2G loc # l2G => l1F : Transition from autF to autG - edge1 = $(edge_name(:l2G, :l1F, 1))(nothing) + edge1 = $(generate_edge_type(:l2G, :l1F, 1))(nothing) map_edges[:l2G][:l1F] = [edge1] # l1F loc # l1F => l3F - edge1 = $(edge_name(:l1F, :l2F, 1))(nothing) - edge2 = $(edge_name(:l1F, :l2F, 2))(nothing) + edge1 = $(generate_edge_type(:l1F, :l2F, 1))(nothing) + edge2 = $(generate_edge_type(:l1F, :l2F, 2))(nothing) map_edges[:l1F][:l2F] = [edge1, edge2] - #edge3 = $(edge_name(:l1F, :l2F, 3))(nothing) - #edge4 = $(edge_name(:l1F, :l2F, 4))(nothing) + #edge3 = $(generate_edge_type(:l1F, :l2F, 3))(nothing) + #edge4 = $(generate_edge_type(:l1F, :l2F, 4))(nothing) #map_edges[:l1F][:l2F] = [edge1, edge4, edge3, edge2] # l1F => l3F - edge1 = $(edge_name(:l1F, :l3F, 1))(nothing) - edge2 = $(edge_name(:l1F, :l3F, 2))(nothing) - edge3 = $(edge_name(:l1F, :l3F, 3))(nothing) + edge1 = $(generate_edge_type(:l1F, :l3F, 1))(nothing) + edge2 = $(generate_edge_type(:l1F, :l3F, 2))(nothing) + edge3 = $(generate_edge_type(:l1F, :l3F, 3))(nothing) map_edges[:l1F][:l3F] = [edge1, edge2, edge3] # l3F loc # l3F => l1F - edge1 = $(edge_name(:l3F, :l1F, 1))([:ALL]) + edge1 = $(generate_edge_type(:l3F, :l1F, 1))([:ALL]) map_edges[:l3F][:l1F] = [edge1] # l3F => l2F - edge1 = $(edge_name(:l3F, :l2F, 1))(nothing) + edge1 = $(generate_edge_type(:l3F, :l2F, 1))(nothing) map_edges[:l3F][:l2F] = [edge1] end diff --git a/core/lha.jl b/core/lha.jl index 6e73375..8f5fcc5 100644 --- a/core/lha.jl +++ b/core/lha.jl @@ -67,7 +67,7 @@ function Base.copyto!(Sdest::StateLHA, Ssrc::StateLHA) Sdest.A = Ssrc.A Sdest.loc = Ssrc.loc for i = eachindex(Sdest.values) - Sdest.values[i] = Ssrc.values[i] + Sdest.values[i] = Ssrc.values[i] end Sdest.time = Ssrc.time end -- GitLab