blegat / HybridSystems.jl

Hybrid Systems definitions in Julia
Other
28 stars 5 forks source link

Add getter function for transitions #38

Closed mforets closed 4 years ago

mforets commented 4 years ago

A function to return the transition associated to a pair of source / target modes is missing (or i didn't find it). Something like:

julia> a = LightAutomaton(2);

julia> add_transition!(a, 1, 1, 1) # Add a self-loop of label 1 for state 1
HybridSystems.LightTransition{LightGraphs.SimpleGraphs.SimpleEdge{Int64}}(Edge 1 => 1, 1)

julia> get_transition(a, 1, 1)
HybridSystems.LightTransition{LightGraphs.SimpleGraphs.SimpleEdge{Int64}}(Edge 1 => 1, 1)

I'm assuming that there is only on transition between modes i -> j (or two if you swap j -> i). Does the assumption hold? Otherwise, get_transition should have an extra argument.

mforets commented 4 years ago

In fact this is available combining out_transitions and target as shown below and it's probably the way to go. I still find it useful to have get_transition though.

for t in out_transitions(a, 1)
    println(target(a, t))
end
1
blegat commented 4 years ago

There may be several transitions. You can get the unique edges with e = HybridSystems.edge_object(a, src, dst). Then the transitions are [LightTransition(e, id) for id in a.Σ[e]]. I agree that it would be nice to have a utility for that.

mforets commented 4 years ago

Thanks! I noticed that it is actually [LightTransition(e, id) for id in values(a.Σ[e])] because a.Σ[e] is a dictionary while LightTransition's id expects an Int.

OTOH should the new function return an iterator? In that case i think that the implementation would be:

function get_transitions(A::LightAutomaton{GT, ET}, q, r) where {GT, ET}
    e = edge_object(A, q, r)
    LightTransitionIterator(A, [e])
end
blegat commented 4 years ago

Yes, that's even better :)