Пример #1
0
 def successors(node):
     if isinstance(node, ChooseKTNode):
         return [
             UFTNode(node.uf_tree, k) for k in range(2, node.max_k + 1)
             # if gen.get_num_uf(node.uf_tree, k, goal)
         ]
     if isinstance(node, MaxKTNode):
         ret = [
             MaxKTNode(c, node.max_k) for c in gen.uf_tree_successors_up_to(
                 node.uf_tree, node.max_k, goal)
         ]
         return ret
     if isinstance(node, UFTNode):
         return [
             UFTNode(c, node.k)
             for c in gen.uf_tree_successors(node.uf_tree, node.k, goal)
         ]
     assert False
Пример #2
0
def construct_root_node(args, env):
    if args.app_tree == APP_T_CHOOSE_K:
        root = ChooseKTNode(uf_factory(env), args.k)
    elif args.app_tree == APP_T_FIXED_K:
        root = UFTNode(uf_factory(env), args.k)
    elif args.app_tree == APP_T_MAX_K:
        root = MaxKTNode(uf_factory(env), args.k)
    elif args.stack:
        root = StackNode([])
    else:
        assert False
    return root
Пример #3
0
    def finish(node):
        assert isinstance(node, UFTNode)

        if smart:
            if node.uf_tree.is_finished():
                return node
        else:
            if node.uf_tree.typ is not None:
                assert False
                # sem to nikdy nedojde???
                assert node.uf_tree.is_finished()
                return node

        # TODO this branch is not done
        # it is possible to do the same as in MacxKTNode
        assert not isinstance(node, ChooseKTNode)

        if isinstance(node, MaxKTNode):
            finished = gen.gen_one_uf_up_to(node.uf_tree, node.max_k, goal)
            assert finished is not None
            finished_tree, k = finished
            ret = UFTNode(finished_tree, k)
        elif isinstance(node, UFTNode):
            finished_tree = gen.gen_one_uf(node.uf_tree, node.k, goal)
            ret = UFTNode(finished_tree, node.k)
        else:
            assert False

        # this means that the node we are to finish
        # is not populated (no such tree exists)
        # in such case, we should not even be called
        assert ret.uf_tree is not None
        if smart:
            assert ret.uf_tree.is_finished()
        else:
            assert ret.uf_tree.typ is not None
        return ret
Пример #4
0
    def advance(node, finished_node):
        assert isinstance(node, UFTNode) or isinstance(node, ChooseKTNode)
        assert isinstance(finished_node, UFTNode)
        if not smart:
            new_uf_tree = dfs_advance_skeleton(node.uf_tree,
                                               finished_node.uf_tree)
        else:
            new_uf_tree = None
            succs = node.uf_tree.successors_typed(gen.gamma, 0)
            if succs:
                for t, _, __ in succs:
                    if t.is_skeleton_of(finished_node.uf_tree):
                        assert t is not None
                        new_uf_tree = t
                        break
                assert new_uf_tree is not None

        if new_uf_tree is None:
            return None
        if isinstance(node, MaxKTNode):
            return MaxKTNode(new_uf_tree, node.max_k)
        if isinstance(node, UFTNode):
            return UFTNode(new_uf_tree, finished_node.k)
Пример #5
0
 def test_mcts(self):
     env = domain_parity_apptree.make_env_app_tree()
     node = MCTNode(UFTNode(UnfinishedLeaf(), 3))
     run_basic_mcts(node, env, 1, 3)
Пример #6
0
 def test_nmcs(self):
     env = domain_parity_apptree.make_env_app_tree()
     node = UFTNode(UnfinishedLeaf(), 3)
     run_basic_nmcs(node, env, 0)