-
Bentriou Mahmoud authored
The solution is to use FunctionWrappers.jl which provides a high interface for C function pointers. All tests passed.
Bentriou Mahmoud authoredThe solution is to use FunctionWrappers.jl which provides a high interface for C function pointers. All tests passed.
lha.jl 25.10 KiB
length_var(A::LHA) = length(getfield(A, :map_var_automaton_idx))
get_value(S::StateLHA, x::Vector{Int}, var::VariableModel) = x[getfield(getfield(S, :A), :map_var_model_idx)[var]]
get_value(A::LHA, x::Vector{Int}, var::VariableModel) = x[getfield(A, :map_var_model_idx)[var]]
copy(S::StateLHA) = StateLHA(getfield(S, :A), getfield(S, :loc), copy(getfield(S, :values)), getfield(S, :time))
# Not overring getproperty, setproperty to avoid a conversion Symbol => String for the dict key
# From the variable automaton var symbol this function get the index in S.values
get_idx_var_automaton(S::StateLHA, var::VariableAutomaton) = getfield(getfield(S, :A), :map_var_automaton_idx)[var]
get_value(S::StateLHA, idx_var::Int) = getfield(S, :values)[idx_var]
get_state_lha_value(A::LHA, values::Vector{Float64}, var::VariableAutomaton) = values[A.map_var_automaton_idx[var]]
getindex(S::StateLHA, var::VariableAutomaton) = getindex(getfield(S, :values), get_idx_var_automaton(S, var))
setindex!(S::StateLHA, val::Float64, var::VariableAutomaton) = setindex!(getfield(S, :values), val, get_idx_var_automaton(S, var))
getindex(S::StateLHA, l_var::Vector{VariableAutomaton}) = [S[var] for var in l_var]
setindex!(S::StateLHA, val::Int, var::VariableAutomaton) = S[var] = convert(Float64, val)
setindex!(S::StateLHA, val::Bool, var::VariableAutomaton) = S[var] = convert(Float64, val)
function Base.show(io::IO, A::LHA)
print(io, "$(Symbol(typeof(A))) automaton (LHA)\n")
print(io, "- initial locations : $(join(A.locations_init,','))\n")
print(io, "- final locations : $(join(A.locations_final,','))\n")
print(io, "- labeling prop Λ :\n")
for loc in keys(A.Λ)
print(io, "* $loc: $(Symbol(A.Λ[loc]))\n")
end
print(io, "- variables :\n")
for (var, idx) in A.map_var_automaton_idx
print(io, "* $var (index = $idx in variables space)\n")
end
print(io, "- flow :\n")
for (loc, flow_loc) in A.flow
print(io, "* $loc: $flow_loc\n")
end
print(io, "- edges :\n")
for from_loc in keys(A.map_edges)
for to_loc in keys(A.map_edges[from_loc])
edges = A.map_edges[from_loc][to_loc]
print(io, "* $from_loc => $to_loc ($(length(edges))): $(join(edges,','))\n")
end
end
print(io, "- constants :\n")
for (name_constant, val_constant) in A.constants
print(io, "* $name_constant: $val_constant\n")
end
print(io, "- transitions : $(join(A.transitions,','))\n")
end
function Base.show(io::IO, S::StateLHA)
print(io, "State of LHA\n")
print(io, "- location: $(S.loc)\n")
print(io, "- variables:\n")
for (var, idx) in (S.A).map_var_automaton_idx
print(io, "* $var = $(S.values[idx]) (idx = $idx)\n")
end
print(io, "- time: $(S.time)")
end
function Base.show(io::IO, E::Edge)
print(io, "($(typeof(E)): ")
print(io, (E.transitions == nothing) ? "Asynchronous #)" : ("Synchronized with " * join(E.transitions,',') * ")"))
end
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]