def test_dfs1(): result = depthFirstSearch([[2, 3], [2], [1, 4]], visitOrder=range(5)) nodeIDs = list(n.nodeID for n in result) assert nodeIDs == [0, 3, 2, 4, 1] preClocks = list(n.preClock for n in result) assert preClocks == [0, 7, 1, 4, 2] postClocks = list(n.postClock for n in result) assert postClocks == [9, 8, 6, 5, 3]
def test_dfs1b(): result = depthFirstSearch([[2, 3], [2], [1, 4]]) nodeIDs = list(n.nodeID for n in result) assert nodeIDs == [0, 1, 2, 3, 4] preClocks = list(n.preClock for n in result) assert preClocks == [8, 4, 5, 2, 0] postClocks = list(n.postClock for n in result) assert postClocks == [9, 7, 6, 3, 1] componentIDs = list(n.connectedComponentID for n in result) assert componentIDs == [3, 2, 2, 1, 0]
def test_dfs3(): result = depthFirstSearch(fig3_9_a()) nodeIDs = list(n.nodeID for n in result) assert nodeIDs == [0, 1, 4, 2, 5, 3, 6, 7, 10, 11, 9, 8] componentIDs = list(n.connectedComponentID for n in result) preClocks = list(n.preClock for n in result) assert preClocks == [22, 18, 19, 14, 15, 12, 0, 1, 2, 3, 4, 5] postClocks = list(n.postClock for n in result) assert postClocks == [23, 21, 20, 17, 16, 13, 11, 10, 9, 8, 7, 6] componentIDs = list(n.connectedComponentID for n in result) assert componentIDs == [4, 3, 3, 2, 2, 1, 0, 0, 0, 0, 0, 0]
def test_dfs2b(): result = depthFirstSearch([ [1, 2], [0], [0], [4], [3], ]) nodeIDs = list(n.nodeID for n in result) assert nodeIDs == [0, 2, 1, 3, 4] componentIDs = list(n.connectedComponentID for n in result) preClocks = list(n.preClock for n in result) assert preClocks == [4, 7, 5, 0, 1] postClocks = list(n.postClock for n in result) assert postClocks == [9, 8, 6, 3, 2] componentIDs = list(n.connectedComponentID for n in result) assert componentIDs == [1, 1, 1, 0, 0]
def test_dfs2(): result = depthFirstSearch([ [1, 2], [0], [0], [4], [3], ], visitOrder=range(5)) nodeIDs = list(n.nodeID for n in result) assert nodeIDs == [3, 4, 0, 2, 1] componentIDs = list(n.connectedComponentID for n in result) preClocks = list(n.preClock for n in result) assert preClocks == [6, 7, 0, 3, 1] postClocks = list(n.postClock for n in result) assert postClocks == [9, 8, 5, 4, 2] componentIDs = list(n.connectedComponentID for n in result) assert componentIDs == [1, 1, 0, 0, 0]
'path_to_goal': None, 'cost_of_path': None, 'nodes_expanded': None, 'search_depth': None, 'max_search_depth': None, 'running_time': None, 'max_ram_usage': None } algOutput = None if alg == 'bfs': algOutput = breadthFirstSearch(root, GOAL_STATE) pass elif alg == 'dfs': algOutput = depthFirstSearch(root, GOAL_STATE) pass elif alg == 'ast': algOutput = aStarSearch(root, GOAL_STATE) pass else: print('Argument unknown') output['path_to_goal'], output['max_search_depth'], output[ 'nodes_expanded'] = algOutput output['cost_of_path'] = len(output['path_to_goal']) output['search_depth'] = len(output['path_to_goal']) output['running_time'] = round(default_timer() - start, 10) # output['max_ram_usage'] = getrusage(RUSAGE_SELF).ru_maxrss / 1000000 f = open('output.txt', 'w+')