Beispiel #1
0
    def setUp(self):
        puzzle6_graph = {
            1: frozenset([2]),
            2: frozenset([1, 3, 4, 5]),
            3: frozenset([2, 4, 6]),
            4: frozenset([2, 3, 5, 6]),
            5: frozenset([2, 4, 6]),
            6: frozenset([3, 4, 5, 7]),
            7: frozenset([6]),
        }
        puzzle6_node_colors = {
            1: 'b',
            2: 'r',
            3: 'y',
            4: 'b',
            5: 'y',
            6: 'r',
            7: 'b',
        }
        puzzle6_moves_left = 3

        print("### Puzzle 6 initial state:")
        print(puzzle6_graph)
        print(puzzle6_node_colors)

        self.puzzle6_step0 = kami2.PuzzleState(puzzle6_graph,
                                               puzzle6_node_colors,
                                               puzzle6_moves_left)
        self.puzzle6 = kami2.Kami2Puzzle(self.puzzle6_step0)
Beispiel #2
0
    5: 'w',
    6: 'o',
    7: 'o',
    8: 'b',
    9: 'c',
    10: 'w',
    11: 'o',
    12: 'b',
    13: 'o',
    14: 'b',
    15: 'o',
    16: 'b'
}
puzzle17_moves_left = 4

puzzle17_step0 = kami2.PuzzleState(puzzle17_graph, puzzle17_node_colors,
                                   puzzle17_moves_left)
puzzle17 = kami2.Kami2Puzzle(puzzle17_step0)


def main():
    print("Solving using DFS:")
    search.DepthFirstSearch().solve(puzzle17)

    print("Solving using UCS:")
    search.UniformCostSearch().solve(puzzle17)

    print("Solving using A* (# colors heuristic):")
    informed_search.AStarSearch(
        informed_search.num_colors_heuristic).solve(puzzle17)

    print("Solving using A* (color distance heuristic):")
Beispiel #3
0
    24: 'dg',
    25: 'dg',
    26: 'y',
    27: 'y',
    28: 'r',
    29: 'y',
    30: 'g',
    31: 'dg',
    32: 'y',
    33: 'dg',
    34: 'r',
    35: 'y'
}
puzzle54_moves_left = 7

puzzle54_step0 = kami2.PuzzleState(puzzle54_graph, puzzle54_node_colors, puzzle54_moves_left)
puzzle54 = kami2.Kami2Puzzle(puzzle54_step0)

def main():
    # print("Solving using DFS:")
    # search.DepthFirstSearch().solve(puzzle54)

    # print("Solving using UCS:")
    # search.UniformCostSearch().solve(puzzle54)

    # print("Solving using A* (# colors heuristic):")
    # informed_search.AStarSearch(informed_search.num_colors_heuristic).solve(puzzle54)

    # num states explored: 952, actions:  [(4, 'y'), (16, 'r'), (24, 'r'), (30, 'r'), (30, 'y'), (30, 'dg'), (30, 'g')]
    print("Solving using A* (color distance heuristic):")
    informed_search.AStarSearch(informed_search.color_distance_heuristic).solve(puzzle54)
Beispiel #4
0
    18: 'dr',
    19: 'dr',
    20: 'dr',
    21: 'dr',
    22: 'dr',
    23: 'dr',
    24: 'dr',
    25: 'p',
    26: 'g',
    27: 'p',
    28: 'r',
    29: 'dr'
}
puzzle98_moves_left = 6

puzzle98_step0 = kami2.PuzzleState(puzzle98_graph, puzzle98_node_colors, puzzle98_moves_left)
puzzle98 = kami2.Kami2Puzzle(puzzle98_step0)

def main():
    # print("Solving using DFS:")
    # search.DepthFirstSearch().solve(puzzle98)

    # print("Solving using A* (# colors heuristic):")
    # informed_search.AStarSearch(informed_search.num_colors_heuristic).solve(puzzle98)

    print("Solving using A* (color distance heuristic):")
    informed_search.AStarSearch(informed_search.color_distance_heuristic).solve(puzzle98)

if __name__ == "__main__":
    main()
Beispiel #5
0
    42: 'r',
    43: 'r',
    44: 'g',
    45: 'g',
    46: 'g',
    47: 'g',
    48: 'g',
    49: 'y',
    50: 'y',
    51: 'y',
    52: 'y',
    53: 'y'
}
puzzle71_moves_left = 5

puzzle71_step0 = kami2.PuzzleState(puzzle71_graph, puzzle71_node_colors, puzzle71_moves_left)
puzzle71 = kami2.Kami2Puzzle(puzzle71_step0)

def main():
    # print("Solving using DFS:")
    # search.DepthFirstSearch().solve(puzzle71)

    # print("Solving using UCS:")
    # search.UniformCostSearch().solve(puzzle71)

    # 6242 states explored, solution:  [(2, 'g'), (2, 'y'), (12, 'y'), (12, 'r'), (12, 'g')]
    # print("Solving using A* (# colors heuristic):")
    # informed_search.AStarSearch(informed_search.num_colors_heuristic).solve(puzzle71)

    # 281 states explored, solution:  [(2, 'g'), (2, 'y'), (12, 'y'), (12, 'r'), (12, 'g')]
    print("Solving using A* (color distance heuristic):")
Beispiel #6
0
    8: 'b',
    9: 'b',
    10: 'b',
    11: 'o',
    12: 'g',
    13: 'o',
    14: 'o',
    15: 'o',
    16: 'b',
    17: 'b',
    18: 'b',
    19: 'g'
}
puzzle33_moves_left = 4

puzzle33_step0 = kami2.PuzzleState(puzzle33_graph, puzzle33_node_colors, puzzle33_moves_left)
puzzle33 = kami2.Kami2Puzzle(puzzle33_step0)

def main():
    # print("Solving using DFS:")
    # search.DepthFirstSearch().solve(puzzle33)

    # print("Solving using UCS:")
    # search.UniformCostSearch().solve(puzzle33)

    print("Solving using A* (# colors heuristic):")
    informed_search.AStarSearch(informed_search.num_colors_heuristic).solve(puzzle33)

    print("Solving using A* (color distance heuristic):")
    informed_search.AStarSearch(informed_search.color_distance_heuristic).solve(puzzle33)