Commit 9cf25cea authored by Bentriou Mahmoud's avatar Bentriou Mahmoud
Browse files

Another rewriting of LHA methods. Improves readability and avoid an

allocation per next_state!. Now update_state! functions returns a Symbol
as location instead of modifying a vector.
parent 5d8c423e
......@@ -4,7 +4,7 @@ function create_automaton_F(m::ContinuousTimeModel, x1::Float64, x2::Float64, t1
@assert sym_obs in m.g "$(sym_obs) is not observed."
@assert (x1 <= x2) "x1 > x2 impossible for F automaton."
@assert (t1 <= t2) "t1 > t2 impossible for F automaton."
# Locations
locations = [:l0, :l1, :l2, :l3]
......@@ -12,7 +12,7 @@ function create_automaton_F(m::ContinuousTimeModel, x1::Float64, x2::Float64, t1
@everywhere true_inv_predicate(x::Vector{Int}) = true
Λ_F = Dict(:l0 => getfield(Main, :true_inv_predicate), :l1 => getfield(Main, :true_inv_predicate),
:l2 => getfield(Main, :true_inv_predicate), :l3 => getfield(Main, :true_inv_predicate))
## Init and final loc
locations_init = [:l0]
locations_final = [:l2]
......@@ -34,7 +34,7 @@ function create_automaton_F(m::ContinuousTimeModel, x1::Float64, x2::Float64, t1
for loc in locations
map_edges[loc] = Dict{Location, Vector{Edge}}()
end
idx_obs_var = getfield(m, :map_var_idx)[sym_obs]
idx_var_n = map_var_automaton_idx[:n]
idx_var_d = map_var_automaton_idx[:d]
......@@ -54,78 +54,72 @@ function create_automaton_F(m::ContinuousTimeModel, x1::Float64, x2::Float64, t1
# "cc" as check_constraints and "us" as update_state
# l0 => l1
@everywhere $(func_name(:cc, :l0, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true
@everywhere $(func_name(:us, :l0, :l1, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = :l1;
S_values[$(idx_var_n)] = x[$(idx_obs_var)];
@everywhere $(func_name(:us, :l0, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(S_values[$(idx_var_n)] = x[$(idx_obs_var)];
setindex!(S_values, Inf, $(idx_var_d));
setindex!(S_values, getfield(Main, $(Meta.quot(sym_isabs_func)))(p, x), $(idx_var_isabs)))
setindex!(S_values, getfield(Main, $(Meta.quot(sym_isabs_func)))(p, x), $(idx_var_isabs));
:l1)
# l1 loc
# l1 => l2
#=
@everywhere $(func_name(:cc, :l1, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
S_time >= $t1 &&
($x1 <= S_values[$(idx_var_n)] <= $x2)
@everywhere $(func_name(:us, :l1, :l2, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = :l2;
setindex!(S_values, 0, $(idx_var_d)))
=#
@everywhere $(func_name(:us, :l1, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, 0, $(idx_var_d));
:l2) =#
#=
@everywhere $(func_name(:cc, :l1, :l2, 3))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
istrue(S_values[$(idx_var_isabs)]) && S_time <= $t2
@everywhere $(func_name(:us, :l1, :l2, 3))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = :l2)
@everywhere $(func_name(:us, :l1, :l2, 3))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(:l2)
=#
@everywhere $(func_name(:cc, :l1, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
S_time >= $t1 &&
S_values[$(idx_var_d)] == 0
@everywhere $(func_name(:us, :l1, :l2, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = :l2)
@everywhere $(func_name(:us, :l1, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(:l2)
@everywhere $(func_name(:cc, :l1, :l2, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(S_time >= $t2) &&
(S_values[$(idx_var_n)] < $x1 || S_values[$(idx_var_n)] > $x2)
@everywhere $(func_name(:us, :l1, :l2, 2))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = :l2;)
@everywhere $(func_name(:us, :l1, :l2, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(:l2;)
#setindex!(S_values, min(abs(S_values[$(idx_var_n)] - $x1), abs(S_values[$(idx_var_n)] - $x2)), $(idx_var_d)))
# l1 => l3
@everywhere $(func_name(:cc, :l1, :l3, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(S_time <= $t1) &&
(S_values[$(idx_var_n)] < $x1 || S_values[$(idx_var_n)] > $x2)
@everywhere $(func_name(:us, :l1, :l3, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = :l3;
setindex!(S_values, min(sqrt((S_time - $t1)^2 + (S_values[$(idx_var_n)] - $x2)^2),
sqrt((S_time - $t1)^2 + (S_values[$(idx_var_n)] - $x1)^2)), $(idx_var_d)))
@everywhere $(func_name(:us, :l1, :l3, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, min(sqrt((S_time - $t1)^2 + (S_values[$(idx_var_n)] - $x2)^2),
sqrt((S_time - $t1)^2 + (S_values[$(idx_var_n)] - $x1)^2)), $(idx_var_d));
:l3)
@everywhere $(func_name(:cc, :l1, :l3, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
($x1 <= S_values[$(idx_var_n)] <= $x2)
@everywhere $(func_name(:us, :l1, :l3, 2))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = :l3;
setindex!(S_values, 0, $(idx_var_d)))
@everywhere $(func_name(:us, :l1, :l3, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, 0, $(idx_var_d));
:l3)
@everywhere $(func_name(:cc, :l1, :l3, 3))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(S_time >= $t1) &&
(S_values[$(idx_var_n)] < $x1 || S_values[$(idx_var_n)] > $x2)
@everywhere $(func_name(:us, :l1, :l3, 3))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = :l3;
val_min = min(S_values[$(idx_var_d)],
@everywhere $(func_name(:us, :l1, :l3, 3))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(val_min = min(S_values[$(idx_var_d)],
min(abs(S_values[$(idx_var_n)] - $x1), abs(S_values[$(idx_var_n)] - $x2)));
setindex!(S_values, val_min, $(idx_var_d)))
setindex!(S_values, val_min, $(idx_var_d));
:l3)
# l3 loc
# l3 => l1
@everywhere $(func_name(:cc, :l3, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true
@everywhere $(func_name(:us, :l3, :l1, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = :l1;
S_values[$(idx_var_n)] = x[$(idx_obs_var)];
setindex!(S_values, getfield(Main, $(Meta.quot(sym_isabs_func)))(p, x), $(idx_var_isabs)))
@everywhere $(func_name(:us, :l3, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(S_values[$(idx_var_n)] = x[$(idx_obs_var)];
setindex!(S_values, getfield(Main, $(Meta.quot(sym_isabs_func)))(p, x), $(idx_var_isabs));
:l1)
# l3 => l2
@everywhere $(func_name(:cc, :l3, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(S_time >= $t2 || istrue(S_values[$(idx_var_isabs)]))
@everywhere $(func_name(:us, :l3, :l2, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = :l2)
@everywhere $(func_name(:us, :l3, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(:l2)
end
eval(meta_elementary_functions)
......@@ -148,12 +142,12 @@ function create_automaton_F(m::ContinuousTimeModel, x1::Float64, x2::Float64, t1
edge2 = Edge(nothing, getfield(Main, func_name(:cc, :l1, :l3, 2)), getfield(Main, func_name(:us, :l1, :l3, 2)))
edge3 = Edge(nothing, getfield(Main, func_name(:cc, :l1, :l3, 3)), getfield(Main, func_name(:us, :l1, :l3, 3)))
map_edges[:l1][:l3] = [edge1, edge2, edge3]
# l3 loc
# l3 => l1
edge1 = Edge([:ALL], getfield(Main, func_name(:cc, :l3, :l1, 1)), getfield(Main, func_name(:us, :l3, :l1, 1)))
map_edges[:l3][:l1] = [edge1]
# l3 => l2
edge1 = Edge(nothing, getfield(Main, func_name(:cc, :l3, :l2, 1)), getfield(Main, func_name(:us, :l3, :l2, 1)))
map_edges[:l3][:l2] = [edge1]
......
......@@ -54,62 +54,62 @@ function create_automaton_G(m::ContinuousTimeModel, x1::Float64, x2::Float64, t1
# l0 loc
# l0 => l1
@everywhere $(func_name(:cc, :l0, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true
@everywhere $(func_name(:us, :l0, :l1, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l1");
setindex!(S_values, 0, $(idx_var_d));
@everywhere $(func_name(:us, :l0, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, 0, $(idx_var_d));
setindex!(S_values, x[$(idx_obs_var)], $(idx_var_n));
setindex!(S_values, true, $(idx_var_in));
setindex!(S_values, getfield(Main, $(Meta.quot(sym_isabs_func)))(p, x), $(idx_var_isabs)))
setindex!(S_values, getfield(Main, $(Meta.quot(sym_isabs_func)))(p, x), $(idx_var_isabs));
:l1)
# l1 => l3
@everywhere $(func_name(:cc, :l1, :l3, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
S_time <= $t1 &&
S_values[$(idx_var_n)] < $x1 || S_values[$(idx_var_n)] > $x2
@everywhere $(func_name(:us, :l1, :l3, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l3");
setindex!(S_values, min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d));
setindex!(S_values, false, $(idx_var_in)))
@everywhere $(func_name(:us, :l1, :l3, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d));
setindex!(S_values, false, $(idx_var_in));
:l3)
@everywhere $(func_name(:cc, :l1, :l3, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(S_time <= $t1) &&
($x1 <= S_values[$(idx_var_n)] <= $x2)
@everywhere $(func_name(:us, :l1, :l3, 2))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l3");
setindex!(S_values, 0, $(idx_var_d));
setindex!(S_values, false, $(idx_var_in)))
@everywhere $(func_name(:us, :l1, :l3, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, 0, $(idx_var_d));
setindex!(S_values, false, $(idx_var_in));
:l3)
@everywhere $(func_name(:cc, :l1, :l3, 3))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
!istrue(S_values[$(idx_var_in)]) &&
($t1 <= S_time <= $t2) &&
($x1 <= S_values[$(idx_var_n)] <= $x2)
@everywhere $(func_name(:us, :l1, :l3, 3))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l3");
setindex!(S_values, S_values[$(idx_var_d)] * (S_time - $t1), $(idx_var_d));
setindex!(S_values, 0.0, $(idx_var_tprime)))
@everywhere $(func_name(:us, :l1, :l3, 3))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S_values[$(idx_var_d)] * (S_time - $t1), $(idx_var_d));
setindex!(S_values, 0.0, $(idx_var_tprime));
:l3)
@everywhere $(func_name(:cc, :l1, :l3, 4))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
istrue(S_values[$(idx_var_in)]) &&
($t1 <= S_time <= $t2) &&
($x1 <= S_values[$(idx_var_n)] <= $x2)
@everywhere $(func_name(:us, :l1, :l3, 4))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l3");
setindex!(S_values, 0.0, $(idx_var_tprime)))
@everywhere $(func_name(:us, :l1, :l3, 4))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, 0.0, $(idx_var_tprime));
:l3)
# l1 => l4
@everywhere $(func_name(:cc, :l1, :l4, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
!istrue(S_values[$(idx_var_in)]) &&
($t1 <= S_time <= $t2) &&
(S_values[$(idx_var_n)] < $x1 || S_values[$(idx_var_n)] > $x2)
@everywhere $(func_name(:us, :l1, :l4, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l4");
setindex!(S_values, S_values[$(idx_var_d)] + S_values[$(idx_var_d)] * (S_time - $t1), $(idx_var_d)))
@everywhere $(func_name(:us, :l1, :l4, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S_values[$(idx_var_d)] + S_values[$(idx_var_d)] * (S_time - $t1), $(idx_var_d));
:l4)
@everywhere $(func_name(:cc, :l1, :l4, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
istrue(S_values[$(idx_var_in)]) &&
($t1 <= S_time <= $t2) &&
(S_values[$(idx_var_n)] < $x1 || S_values[$(idx_var_n)] > $x2)
@everywhere $(func_name(:us, :l1, :l4, 2))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l4"))
@everywhere $(func_name(:us, :l1, :l4, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(:l4)
# l1 => l2
......@@ -117,76 +117,76 @@ function create_automaton_G(m::ContinuousTimeModel, x1::Float64, x2::Float64, t1
@everywhere $(func_name(:cc, :l1, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
istrue(S_values[$(idx_var_in)]) &&
S_time >= $t2
@everywhere $(func_name(:us, :l1, :l2, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l2"))
@everywhere $(func_name(:us, :l1, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(:l2)
@everywhere $(func_name(:cc, :l1, :l2, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
!istrue(S_values[$(idx_var_in)]) &&
S_time >= $t2
@everywhere $(func_name(:us, :l1, :l2, 2))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l2");
setindex!(S_values, S_values[$(idx_var_d)] * ($t2 - $t1), $(idx_var_d)))
@everywhere $(func_name(:us, :l1, :l2, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S_values[$(idx_var_d)] * ($t2 - $t1), $(idx_var_d));
:l2)
@everywhere $(func_name(:cc, :l1, :l2, 3))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
istrue(S_values[$(idx_var_isabs)]) &&
S_time <= $t1
@everywhere $(func_name(:us, :l1, :l2, 3))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l2");
setindex!(S_values, ($t2 - $t1) * min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d)))
@everywhere $(func_name(:us, :l1, :l2, 3))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, ($t2 - $t1) * min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d));
:l2)
@everywhere $(func_name(:cc, :l1, :l2, 4))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
istrue(S_values[$(idx_var_isabs)]) &&
($t1 <= S_time <= $t2)
@everywhere $(func_name(:us, :l1, :l2, 4))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l2");
setindex!(S_values, S_values[$(idx_var_d)] + ($t2 - S_time) * min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d)))
@everywhere $(func_name(:us, :l1, :l2, 4))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S_values[$(idx_var_d)] + ($t2 - S_time) * min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d));
:l2)
=#
# l3 => l1
@everywhere $(func_name(:cc, :l3, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true
@everywhere $(func_name(:us, :l3, :l1, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l1");
setindex!(S_values, x[$(idx_obs_var)], $(idx_var_n));
setindex!(S_values, getfield(Main, $(Meta.quot(sym_isabs_func)))(p, x), $(idx_var_isabs)))
@everywhere $(func_name(:us, :l3, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, x[$(idx_obs_var)], $(idx_var_n));
setindex!(S_values, getfield(Main, $(Meta.quot(sym_isabs_func)))(p, x), $(idx_var_isabs));
:l1)
# l4 => l1
@everywhere $(func_name(:cc, :l4, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true
@everywhere $(func_name(:us, :l4, :l1, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l1");
setindex!(S_values, S_values[$(idx_var_d)] + S_values[$(idx_var_tprime)] * min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d));
@everywhere $(func_name(:us, :l4, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S_values[$(idx_var_d)] + S_values[$(idx_var_tprime)] * min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d));
setindex!(S_values, 0.0, $(idx_var_tprime));
setindex!(S_values, x[$(idx_obs_var)], $(idx_var_n));
setindex!(S_values, true, $(idx_var_in));
setindex!(S_values, getfield(Main, $(Meta.quot(sym_isabs_func)))(p, x), $(idx_var_isabs)))
setindex!(S_values, getfield(Main, $(Meta.quot(sym_isabs_func)))(p, x), $(idx_var_isabs));
:l1)
# l3 => l2
@everywhere $(func_name(:cc, :l3, :l2, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
istrue(S_values[$(idx_var_in)]) &&
(S_time >= $t2 || istrue(S_values[$(idx_var_isabs)]))
@everywhere $(func_name(:us, :l3, :l2, 2))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l2");
setindex!(S_values, S_values[$(idx_var_d)] * ($t2 - $t1), $(idx_var_d)))
@everywhere $(func_name(:us, :l3, :l2, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S_values[$(idx_var_d)] * ($t2 - $t1), $(idx_var_d));
:l2)
@everywhere $(func_name(:cc, :l3, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
!istrue(S_values[$(idx_var_in)]) &&
(S_time >= $t2 || istrue(S_values[$(idx_var_isabs)]))
@everywhere $(func_name(:us, :l3, :l2, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l2"))
@everywhere $(func_name(:us, :l3, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(:l2)
# l4 => l2
@everywhere $(func_name(:cc, :l4, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(istrue(S_values[$(idx_var_isabs)]))
@everywhere $(func_name(:us, :l4, :l2, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l2");
setindex!(S_values, S_values[$(idx_var_d)] + ($t2 - S_time) * min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d));
setindex!(S_values, 0.0, $(idx_var_tprime)))
@everywhere $(func_name(:us, :l4, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S_values[$(idx_var_d)] + ($t2 - S_time) * min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d));
setindex!(S_values, 0.0, $(idx_var_tprime));
:l2)
@everywhere $(func_name(:cc, :l4, :l2, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(S_time >= $t2)
@everywhere $(func_name(:us, :l4, :l2, 2))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l2");
setindex!(S_values, S_values[$(idx_var_d)] + S_values[$(idx_var_tprime)] * min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d));
setindex!(S_values, 0.0, $(idx_var_tprime)))
@everywhere $(func_name(:us, :l4, :l2, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S_values[$(idx_var_d)] + S_values[$(idx_var_tprime)] * min(abs($x1 - S_values[$(idx_var_n)]), abs($x2 - S_values[$(idx_var_n)])), $(idx_var_d));
setindex!(S_values, 0.0, $(idx_var_tprime));
:l2)
end
eval(meta_elementary_functions)
......
This diff is collapsed.
......@@ -35,7 +35,7 @@ function create_euclidean_distance_automaton(m::ContinuousTimeModel, timeline::A
idx_var_n = map_var_automaton_idx[:n]
idx_var_d = map_var_automaton_idx[:d]
idx_var_idx = map_var_automaton_idx[:idx]
nbr_rand = rand(1:1000)
basename_func = "$(replace(m.name, ' '=>'_'))_$(nbr_rand)"
basename_func = replace(basename_func, '-'=>'_')
......@@ -45,11 +45,11 @@ function create_euclidean_distance_automaton(m::ContinuousTimeModel, timeline::A
# l0 loc
# l0 => l1
@everywhere $(func_name(:cc, :l0, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true
@everywhere $(func_name(:us, :l0, :l1, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l1");
setindex!(S_values, x[$(idx_obs_var)], $(idx_var_n));
@everywhere $(func_name(:us, :l0, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, x[$(idx_obs_var)], $(idx_var_n));
setindex!(S_values, 0.0, $(idx_var_d));
setindex!(S_values, 1.0, $(idx_var_idx)))
setindex!(S_values, 1.0, $(idx_var_idx));
:l1)
# l1 loc
# l1 => l1
......@@ -58,23 +58,25 @@ function create_euclidean_distance_automaton(m::ContinuousTimeModel, timeline::A
(tml = $(Tuple(timeline));
tml_idx = tml[convert(Int, S_values[$(idx_var_idx)])];
S_values[$(idx_var_t)] >= tml_idx)
@everywhere $(func_name(:us, :l1, :l1, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
@everywhere $(func_name(:us, :l1, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(y_obs = $(Tuple(observations));
y_obs_idx = y_obs[convert(Int, S_values[$(idx_var_idx)])];
setindex!(S_values, S_values[$(idx_var_d)] + (S_values[$(idx_var_n)] - y_obs_idx)^2,
$(idx_var_d));
setindex!(S_values, S_values[$(idx_var_idx)] + 1.0, $(idx_var_idx)))
$(idx_var_d));
setindex!(S_values, S_values[$(idx_var_idx)] + 1.0, $(idx_var_idx));
:l1)
@everywhere $(func_name(:cc, :l1, :l1, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true
@everywhere $(func_name(:us, :l1, :l1, 2))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, x[$(idx_obs_var)], $(idx_var_n)))
@everywhere $(func_name(:us, :l1, :l1, 2))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, x[$(idx_obs_var)], $(idx_var_n));
:l1)
# l1 => l2
@everywhere $(func_name(:cc, :l1, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
S_values[$(idx_var_idx)] >= ($nbr_observations + 1)
@everywhere $(func_name(:us, :l1, :l2, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l2");
setindex!(S_values, sqrt(S_values[$(idx_var_d)]), $(idx_var_d)))
@everywhere $(func_name(:us, :l1, :l2, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, sqrt(S_values[$(idx_var_d)]), $(idx_var_d));
:l2)
end
eval(meta_elementary_functions)
......@@ -89,15 +91,15 @@ function create_euclidean_distance_automaton(m::ContinuousTimeModel, timeline::A
edge1 = Edge([:ALL], getfield(Main, func_name(:cc, :l1, :l1, 1)), getfield(Main, func_name(:us, :l1, :l2, 1)))
map_edges[:l1][:l1] = [edge1]
for i = 1:nbr_observations
meta_edge_i = quote
@everywhere $(func_name(:cc, :l1, :l1, 1+i))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
S[:t] >= $(timeline[i])
@everywhere $(func_name(:us, :l1, :l1, 1+i))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S[:d] + (S[:n] - $(observations[i]))^2, $(idx_var_d));
setindex!(S_values, S[:idx] + 1.0, $(idx_var_idx)))
end
eval(meta_edge_i)
push!(map_edges[:l1][:l1], Edge(nothing, getfield(Main, func_name(:cc, :l1, :l1, 1+i)), getfield(Main, func_name(:us, :l1, :l1, 1+i))))
meta_edge_i = quote
@everywhere $(func_name(:cc, :l1, :l1, 1+i))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
S[:t] >= $(timeline[i])
@everywhere $(func_name(:us, :l1, :l1, 1+i))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S[:d] + (S[:n] - $(observations[i]))^2, $(idx_var_d));
setindex!(S_values, S[:idx] + 1.0, $(idx_var_idx)))
end
eval(meta_edge_i)
push!(map_edges[:l1][:l1], Edge(nothing, getfield(Main, func_name(:cc, :l1, :l1, 1+i)), getfield(Main, func_name(:us, :l1, :l1, 1+i))))
end
=#
edge1 = Edge(nothing, getfield(Main, func_name(:cc, :l1, :l1, 1)), getfield(Main, func_name(:us, :l1, :l1, 1)))
......
......@@ -28,13 +28,13 @@ function create_euclidean_distance_automaton_2(m::ContinuousTimeModel, timeline:
for loc in locations
flow[loc] = vector_flow
end
## Edges
map_edges = Dict{Location, Dict{Location, Vector{Edge}}}()
for loc in locations
map_edges[loc] = Dict{Location, Vector{Edge}}()
end
idx_obs_var = getfield(m, :map_var_idx)[sym_obs]
to_idx(var::Symbol) = map_var_automaton_idx[var]
nbr_rand = rand(1:1000)
......@@ -47,24 +47,25 @@ function create_euclidean_distance_automaton_2(m::ContinuousTimeModel, timeline:
# l0 loc
# l0 => l1
@everywhere $(func_name(:cc, :l0, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true
@everywhere $(func_name(:us, :l0, :l1, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("l1");
setindex!(S_values, x[$(idx_obs_var)], $(to_idx(:n)));
setindex!(S_values, 0.0, $(to_idx(:d))))
@everywhere $(func_name(:us, :l0, :l1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, x[$(idx_obs_var)], $(to_idx(:n)));
setindex!(S_values, 0.0, $(to_idx(:d)));
:l1)
# lnbr_obs => lfinal
@everywhere $(func_name(:cc, loc_nbr_obs, :lfinal, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
S_values[$(to_idx(:t))] >= $(timeline[nbr_observations])
@everywhere $(func_name(:us, loc_nbr_obs, :lfinal, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = Symbol("lfinal");
setindex!(S_values, S_values[$(to_idx(:d))] + (S_values[$(to_idx(:n))]-$(observations[nbr_observations]))^2,
$(to_idx(:d)));
setindex!(S_values, sqrt(S_values[$(to_idx(:d))]), $(to_idx(:d))))
@everywhere $(func_name(:us, loc_nbr_obs, :lfinal, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S_values[$(to_idx(:d))] + (S_values[$(to_idx(:n))]-$(observations[nbr_observations]))^2,
$(to_idx(:d)));
setindex!(S_values, sqrt(S_values[$(to_idx(:d))]), $(to_idx(:d)));
:lfinal)
# lnbr_obs => lnbr_obs
@everywhere $(func_name(:cc, loc_nbr_obs, loc_nbr_obs, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true
@everywhere $(func_name(:us, loc_nbr_obs, loc_nbr_obs, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, x[$(idx_obs_var)], $(to_idx(:n))))
@everywhere $(func_name(:us, loc_nbr_obs, loc_nbr_obs, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, x[$(idx_obs_var)], $(to_idx(:n)));
$(Meta.quot(loc_nbr_obs)))
end
eval(meta_elementary_functions)
# l0 loc
......@@ -88,14 +89,15 @@ function create_euclidean_distance_automaton_2(m::ContinuousTimeModel, timeline:
# Defined below
@everywhere $(func_name(:cc, loci, locip1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
S_values[$(to_idx(:t))] >= $(timeline[i])
@everywhere $(func_name(:us, loci, locip1, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(ptr_loc[1] = $(Meta.quot(locip1));
setindex!(S_values, S_values[$(to_idx(:d))] + (S_values[$(to_idx(:n))]-$(observations[i]))^2,
$(to_idx(:d))))
@everywhere $(func_name(:us, loci, locip1, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, S_values[$(to_idx(:d))] + (S_values[$(to_idx(:n))]-$(observations[i]))^2,
$(to_idx(:d)));
$(Meta.quot(locip1)))
@everywhere $(func_name(:cc, loci, loci, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) = true
@everywhere $(func_name(:us, loci, loci, 1))(ptr_loc::Vector{Symbol}, S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =
(setindex!(S_values, x[$(idx_obs_var)], $(to_idx(:n))))
@everywhere $(func_name(:us, loci, loci, 1))(S_time::Float64, S_values::Vector{Float64}, x::Vector{Int}, p::Vector{Float64}) =