Getting all nodes and transitions in a Graph

22 views
Skip to first unread message

Teck Ping Khoo

unread,
Aug 7, 2019, 1:39:04 PM8/7/19
to LearnLib Q&A
Hi everyone

I would like to get all the nodes and transitions in a graph. Referring to the code below, getNodes() will return a collection of nodes. 
Please let me know the best practice for returning a collection of transitions. 

Thanks!
Teck Ping

import net.automatalib.graphs.Graph

...
hyp = lstar.getHypothesisModel();
Graph<?,?> graphHyp = hyp.transitionGraphView(sigma);
Collection<?> collNodes = graphHyp.getNodes();

Carlos Diego Nascimento Damasceno

unread,
Aug 7, 2019, 1:45:16 PM8/7/19
to Teck Ping Khoo, LearnLib Q&A
Dear Teck Ping Khoo,

What I usually do is to iterate over the set of states and, for each symbol, I use the getTransition() method to find valid transitions and put them in a hash table.

--
You received this message because you are subscribed to the Google Groups "LearnLib Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to learnlib-qa...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/learnlib-qa/8b36f501-8678-4c67-95c4-c9a258d53e48%40googlegroups.com.

Markus Frohme

unread,
Aug 9, 2019, 2:55:47 AM8/9/19
to Teck Ping Khoo, LearnLib Q&A
Dear Teck,


the Graph interface represents just a very simple collection of connected
nodes. So on your graphHyp you could call #getOutgoingEdges(node) to get
edge-objects representing the connections, or #getAdjancentTargets(node)
to directly get the connected successor nodes. For this, I would suggest
to either write a utility function that binds the generic types or use the
proper types from the #transitionGraphView method, because wildcards (?)
get messy quickly.

If you require to retain information about the properties of the
hypothesis, certain sub-interfaces (e.g. FSAs or MealyMachines) specialize
the return type of the #transitionGraphView method to a UniversalGraph,
which maintains information about state- and edge properties.

If you want more of a "direct access" datastructure, e.g. something like
"give me the successor(s) for input i", I would suggest to stick to the
TransitionSystem type (which Automaton, DFA, MealyMachine, etc. are
sub-classes of) and simply use its #getTransition / #getSuccessor
functions.


Kind regards,
Markus

Teck Ping Khoo

unread,
Aug 13, 2019, 5:20:35 AM8/13/19
to LearnLib Q&A
Dear Diego and Markus

Thanks for your guidance!

For me, using GraphDOT to write the DOT description of the hypothesis to a file works well, as below:


import net.automatalib.serialization.dot.GraphDOT;

...

GraphDOT.write(a_hyp, a_alphabet, fileWriterInst);




I get something like below:

digraph g {

s0 [shape="circle" label="0"];
s0 -> s0 [label="a"];
s0 -> s0 [label="b"];
s0 -> s0 [label="w"];

__start0 [label="" shape="none" width="0" height="0"];
__start0 -> s0;

Regards
Teck Ping

Teck Ping Khoo

unread,
Oct 24, 2019, 6:08:51 AM10/24/19
to LearnLib Q&A
Hi Markus

Can you provide an example of how to use the getSuccessor() and getTransition() functions? I think I should start with the code below, get the initial state, and then continuously call these functions to walk the automata. I read the API docs and kept finding the type "S" for the state type, but could not find any example of how to use it. 

DFA<?, String> hyp = lstar.getHypothesisModel();
??? = hyp.getInitialState();

I wish to walk the hypothesis automata and recover accepting traces up to a certain length to test on the SUL, as a form of equivalence query. If all these traces are also accepted by the SUL, I take it that the hypothesis and the SUL are equal. If a certain trace accepted by the hypothesis but not the SUL, I will feed this trace back to the L* instance to continue the algorithm. Therefore, just writing the hypothesis to a file in graphviz format is not enough. 

Thanks!
Teck Ping



On Friday, August 9, 2019 at 2:55:47 PM UTC+8, Markus Frohme wrote:

Markus Frohme

unread,
Oct 25, 2019, 9:21:15 AM10/25/19
to Teck Ping Khoo, LearnLib Q&A
Hi Teck Ping,


Java wildcards are a double-edged sword. It's nice to not have to care
about implementation details, but sometimes managing them is a little bit
inconvenient. In Java, you can reference wildcard types by dynamically
binding them in e.g. functions. We have a wiki page regarding this topic
[0]. Does this help?

As for you question about generating traces: Do you require any custom
generation logic? For the most common types of traces (e.g. state- or
transition coverages) there already exist utility methods in the Automata
class [1].


Kind regards,
Markus


[0] - https://github.com/LearnLib/learnlib/wiki/Dealing-with-wildcards
[1] -
http://learnlib.github.io/automatalib/maven-site/latest/apidocs/net/automatalib/util/automata/Automata.html
Reply all
Reply to author
Forward
0 new messages