# MIT 6.034 Lab 1: Search from tester import make_test, get_tests from search import UndirectedGraph, Edge from lab1 import (generic_dfs, generic_bfs, generic_hill_climbing, generic_best_first, generic_branch_and_bound, generic_branch_and_bound_with_heuristic, generic_branch_and_bound_with_extended_set, generic_a_star, is_admissible, is_consistent, TEST_GENERIC_BEAM, TEST_HEURISTICS) lab_number = 1 from read_graphs import get_graphs all_graphs = get_graphs() GRAPH_0 = all_graphs['GRAPH_0'] GRAPH_1 = all_graphs['GRAPH_1'] GRAPH_2 = all_graphs['GRAPH_2'] GRAPH_3 = all_graphs['GRAPH_3'] GRAPH_FOR_HEURISTICS = all_graphs['GRAPH_FOR_HEURISTICS'] GRAPH_FOR_HEURISTICS_TRICKY = all_graphs['GRAPH_FOR_HEURISTICS_TRICKY'] ########################################################################## ### OFFLINE TESTS (HARDCODED ANSWERS) #### PART 1: Helper Functions ######################################### make_test( type='FUNCTION', #TEST 1 getargs=[GRAPH_1, ['a', 'c', 'b', 'd']], testanswer=lambda val, original_val=None: val == 11, expected_val=11,
from search import Edge, UndirectedGraph, do_nothing_fn, make_generic_search import read_graphs all_graphs = read_graphs.get_graphs() GRAPH_0 = all_graphs['GRAPH_0'] GRAPH_1 = all_graphs['GRAPH_1'] GRAPH_2 = all_graphs['GRAPH_2'] GRAPH_3 = all_graphs['GRAPH_3'] GRAPH_FOR_HEURISTICS = all_graphs['GRAPH_FOR_HEURISTICS'] #Change this to True if you want to run additional local tests for debugging: RUN_ADDITIONAL_TESTS = False #### PART 1: Helper Functions ######################################### def path_length(graph, path): l = 0 for i in range(len(path) - 1): l += graph.get_edge(path[i], path[i + 1]).length return l def has_loops(path): i = set() for j in path: if j not in i: i.add(j) else: return True return False
from search import Edge, UndirectedGraph, do_nothing_fn, make_generic_search import read_graphs all_graphs = read_graphs.get_graphs() GRAPH_0 = all_graphs['GRAPH_0'] GRAPH_1 = all_graphs['GRAPH_1'] GRAPH_2 = all_graphs['GRAPH_2'] GRAPH_3 = all_graphs['GRAPH_3'] GRAPH_FOR_HEURISTICS = all_graphs['GRAPH_FOR_HEURISTICS'] #Change this to True if you want to run additional local tests for debugging: RUN_ADDITIONAL_TESTS = False #### PART 1: Helper Functions ######################################### def path_length(graph, path): if len(path)<=1: return 0 else: return graph.get_edge(path[0],path[1]).length+path_length(graph, path[1:]) def has_loops(path): nodes=set(path) if len(nodes)<len(path): return True else: return False def extensions(graph, path): ext=[] neighbors=graph.get_neighbors(path[len(path)-1])
# MIT 6.034 Lab 2: Search from tester import make_test, get_tests from lab2 import (generic_dfs, generic_bfs, generic_hill_climbing, generic_best_first, generic_beam, generic_branch_and_bound, generic_branch_and_bound_with_heuristic, generic_branch_and_bound_with_extended_set, generic_a_star, is_admissible, is_consistent, a_star, TEST_GENERIC_BEAM, TEST_HEURISTICS) from read_graphs import get_graphs all_graphs = get_graphs() GRAPH_0 = all_graphs['GRAPH_0'] GRAPH_1 = all_graphs['GRAPH_1'] GRAPH_2 = all_graphs['GRAPH_2'] GRAPH_3 = all_graphs['GRAPH_3'] GRAPH_FOR_HEURISTICS = all_graphs['GRAPH_FOR_HEURISTICS'] ########################################################################## ### OFFLINE TESTS (HARDCODED ANSWERS) #### PART 1: Helper Functions ######################################### make_test(type = 'FUNCTION', #TEST 1 getargs = [GRAPH_1, ['a', 'c', 'b', 'd']], testanswer = lambda val, original_val=None: val == 11, expected_val = 11, name = 'path_length') make_test(type = 'FUNCTION', #TEST 2