示例#1
0
def test_iterative_deepening_graph_search():
    """
    Test iterative deepening graph search.
    """
    for goal in range(1, 10):
        p = AnnotatedProblem(EasyProblem(0, goal))
        sol = next(iterative_deepening_search(p, graph=True))
        assert sol.state_node.state == goal
        assert p.nodes_expanded == sum([i * 2 for i in range(1, goal + 1)])
        assert p.goal_tests == sum([i + 1 for i in range(1, goal + 1)]) + 1

    p = EasyProblem(0, 10)
    try:
        next(iterative_deepening_search(p, graph=True, max_depth_limit=5))
        assert False
    except StopIteration:
        pass
示例#2
0
def test_iterative_deepening_graph_search():
    """
    Test iterative deepening graph search.
    """
    for goal in range(1, 10):
        p = AnnotatedProblem(EasyProblem(0, goal))
        sol = next(iterative_deepening_search(p, graph=True))
        assert sol.state_node.state == goal
        assert p.nodes_expanded == sum([i * 2 for i in range(1, goal + 1)])
        assert p.goal_tests == sum([i + 1 for i in range(1, goal + 1)]) + 1
示例#3
0
def test_iterative_deepening_tree_search():
    """
    Test iterative deepening tree search.
    """
    for goal in range(1, 10):
        p = AnnotatedProblem(EasyProblem(0, goal))
        sol = next(iterative_deepening_search(p, graph=False))
        assert sol.state_node.state == goal
        assert (p.nodes_expanded == sum(
            [pow(2, i + 1) - 2 for i in range(1, goal)]) + (goal * 2))
        assert (
            p.goal_tests == sum([pow(2, i + 1) - 2
                                 for i in range(1, goal)]) + (goal * 2) + 1)

    p = EasyProblem(0, 10)
    try:
        next(iterative_deepening_search(p, graph=False, max_depth_limit=5))
        assert False
    except StopIteration:
        pass
示例#4
0
    def fc_plan(self, goals, max_depth=5, epsilon=0.0):
        """
        A strategy of expanding forward from the initial state.
        """
        index = build_index(self.facts)

        fc_problem = FC_Problem(initial=(frozenset(self.facts),
                                         frozenset(goals)),
                                extra=(self.operators, index, epsilon))

        for solution in iterative_deepening_search(fc_problem,
                                                   max_depth_limit=max_depth +
                                                   1):
            yield solution
示例#5
0
 def iterative_deepening(self, x):
     return iterative_deepening_search(x)