Loading 3.4_13-lifo.py +15 −3 Original line number Diff line number Diff line Loading @@ -17,10 +17,22 @@ def depth_first_search(start_node): for node1 in move_anyY(node): paths.append(Cons(node1, path)) def is_goal(_): def is_goal(x): # zavisi na resenem problemu return False return x == "E" graph = dict(A=["B", "E", "F"], B=["C"], F=["C"], C=["D"], D=["E"]) def move_anyY(x): # zavisi na resenem problemu yield x if x in graph: for y in graph[x]: yield y # demonstracni vypis if __name__ == "__main__": print("Depth-First Search") print("Volani next(solution('A')) : %s" % next(solution('A'))) 3.4_13-lifo.py.out +2 −0 Original line number Diff line number Diff line Depth-First Search Volani next(solution('A')) : ['E', 'D', 'C', 'F', 'A'] 3.4_13.py +15 −3 Original line number Diff line number Diff line Loading @@ -15,10 +15,22 @@ def depth_first_search(akumulator_path, node): for path in depth_first_search(akumulator_path1, node1): yield path def is_goal(_): def is_goal(x): # zavisi na resenem problemu return False return x == "E" graph = dict(A=["B", "E", "F"], B=["C"], F=["C"], C=["D"], D=["E"]) def move_anyY(x): # zavisi na resenem problemu yield x if x in graph: for y in graph[x]: yield y # demonstracni vypis if __name__ == "__main__": print("Depth-First Search") print("Volani next(solution('A')) : %s" % next(solution('A'))) 3.4_13.py.out +2 −0 Original line number Diff line number Diff line Depth-First Search Volani next(solution('A')) : ['E', 'D', 'C', 'B', 'A'] 3.5_15-lifo.py +19 −3 Original line number Diff line number Diff line Loading @@ -18,10 +18,26 @@ def depth_first_search(start_node, max_depth): for node1 in move_anyY(node): paths.append((Cons(node1, path), remaining_depth-1)) def is_goal(_): def is_goal(x): # zavisi na resenem problemu return False return x == "E" graph = dict(A=["B", "E", "F"], B=["C"], F=["C"], C=["D"], D=["E"]) def move_anyY(x): # zavisi na resenem problemu yield x if x in graph: for y in graph[x]: yield y # demonstracni vypis if __name__ == "__main__": print("Depth-First Search") print("Volani next(solution('A')) : %s" % next(solution('A'))) print("Volani next(depth_first_search('A', 3)) : %s" % \ next(depth_first_search('A', 3))) print("Volani next(depth_first_search('A', 4)) : %s" % \ next(depth_first_search('A', 4))) Loading
3.4_13-lifo.py +15 −3 Original line number Diff line number Diff line Loading @@ -17,10 +17,22 @@ def depth_first_search(start_node): for node1 in move_anyY(node): paths.append(Cons(node1, path)) def is_goal(_): def is_goal(x): # zavisi na resenem problemu return False return x == "E" graph = dict(A=["B", "E", "F"], B=["C"], F=["C"], C=["D"], D=["E"]) def move_anyY(x): # zavisi na resenem problemu yield x if x in graph: for y in graph[x]: yield y # demonstracni vypis if __name__ == "__main__": print("Depth-First Search") print("Volani next(solution('A')) : %s" % next(solution('A')))
3.4_13-lifo.py.out +2 −0 Original line number Diff line number Diff line Depth-First Search Volani next(solution('A')) : ['E', 'D', 'C', 'F', 'A']
3.4_13.py +15 −3 Original line number Diff line number Diff line Loading @@ -15,10 +15,22 @@ def depth_first_search(akumulator_path, node): for path in depth_first_search(akumulator_path1, node1): yield path def is_goal(_): def is_goal(x): # zavisi na resenem problemu return False return x == "E" graph = dict(A=["B", "E", "F"], B=["C"], F=["C"], C=["D"], D=["E"]) def move_anyY(x): # zavisi na resenem problemu yield x if x in graph: for y in graph[x]: yield y # demonstracni vypis if __name__ == "__main__": print("Depth-First Search") print("Volani next(solution('A')) : %s" % next(solution('A')))
3.4_13.py.out +2 −0 Original line number Diff line number Diff line Depth-First Search Volani next(solution('A')) : ['E', 'D', 'C', 'B', 'A']
3.5_15-lifo.py +19 −3 Original line number Diff line number Diff line Loading @@ -18,10 +18,26 @@ def depth_first_search(start_node, max_depth): for node1 in move_anyY(node): paths.append((Cons(node1, path), remaining_depth-1)) def is_goal(_): def is_goal(x): # zavisi na resenem problemu return False return x == "E" graph = dict(A=["B", "E", "F"], B=["C"], F=["C"], C=["D"], D=["E"]) def move_anyY(x): # zavisi na resenem problemu yield x if x in graph: for y in graph[x]: yield y # demonstracni vypis if __name__ == "__main__": print("Depth-First Search") print("Volani next(solution('A')) : %s" % next(solution('A'))) print("Volani next(depth_first_search('A', 3)) : %s" % \ next(depth_first_search('A', 3))) print("Volani next(depth_first_search('A', 4)) : %s" % \ next(depth_first_search('A', 4)))