Created
January 31, 2013 18:47
-
-
Save Satshabad/4685253 to your computer and use it in GitHub Desktop.
Worklist algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def worklist(graph, s, get_edge_state): | |
q = [s] | |
v = set() | |
enter_state = {} | |
old = None | |
while q: | |
curr = q.pop(0) | |
state = get_edge_state(old, curr) | |
for adj in graph[curr]: | |
if adj not in q and adj not in v: | |
q.append(adj) | |
elif get_edge_state(curr, adj) != enter_state[adj]: | |
q.append(adj) | |
v.add(curr) | |
old = curr | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment