As a personal easter project I'm trying to implement some model-based testing at work. I've got a graph implemented in python and I need to traverse all edges / do all transitions of the graph, at least once. Traversing an edge twice or more does not matter, but I need to start and end in the same node and get a sequence of edges/transitions back.
Simpler algorithm > shortest sequence.
I've looked around and found a lot of algorithms, but I couldn't find one / a combination that works for me. It would be great if someone could point me in the right direction or give me some tips on how to do this.
My graph implementation looks like this:
graph = {
A : {'IDLE': 't8', 'B': 't2', 'C': 't4'},
B : {'A': 't3', 'C': 't4', 'IDLE': 't6'},
C : {'A': 't5', 'IDLE': 't7', 'B': 't2'},
IDLE : {'A': 't1'}
}
As you can see from the example, DFS doesn't go through all edges. The vertices and edges, which depth-first search has visited is a tree. This tree contains all vertices of the graph (if it is connected) and is called graph spanning tree. This tree exactly corresponds to the recursive calls of DFS.
In BFS, all nodes are going to be visited. The minimum spanning tree contains a minimal number of edges to connect all the nodes. So, the BFS traversal will traverse all the edges in order to visit all the nodes.
An edge (or link) of a network (or graph) is one of the connections between the nodes (or vertices) of the network. Edges can be directed, meaning they point from one node to the next, as illustrated by the arrows in the first figure below.
Depth-first search (DFS) is an algorithm for searching a graph or tree data structure. The algorithm starts at the root (top) node of a tree and goes as far as it can down a given branch (path), then backtracks until it finds an unexplored path, and then explores it.
Approach 1
You can change your graph G into a new graph G' where each edge in G becomes a node in G'. Make an edge from t1 to t2 in G' if "A -> t1 -> B -> t2 -> C" is possible in G for some A,B and C.
Then you need to find a path cover in G'.
Approach 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With