I would like to find an efficient way to check if a given "Walk" through a graph is valid.
Such a function should accept a Graph (nodes, edges) and a string of node names, and should output True if nodes can be visited in the given sequence according to the graph and false if not.
Preferably, I would use the NetworkX library, since I already use it to store and represent the graph.
Something resembling this:
""" G:
Q1 -> Q1
Q1 -> Q2
Q2 -> Q2
"""
accepts(G, ["Q1", "Q1", "Q2"])
>> True
accepts(G, ["Q2", "Q2", "Q2"])
>> True
accepts(G, ["Q2", "Q2", "Q1"])
>> False
accepts(G, ["Q1", "Q2", "Q1"])
>> False
accepts(G, ["Q1", "Q1", "Q2", "Q1"])
>> False
This would be used for a automata class. To basically check for membership of a string given a language represented by the graph.