Exemplo n.º 1
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
Exemplo n.º 2
0
    def advance(node, finished_node):
        assert isinstance(node, StackNode)
        assert isinstance(finished_node, StackNode)
        assert is_finished(finished_node)

        f_stack, stack = finished_node.stack, node.stack

        assert stack == f_stack[:len(stack)]
        if len(f_stack) <= len(stack):
            assert f_stack == stack
            return None

        stack = copy.copy(stack)
        stack.append(f_stack[len(stack)])
        return StackNode(stack)
Exemplo n.º 3
0
 def test_mcts(self):
     env = domain_parity_stack.make_env_stack()
     node = MCTNode(StackNode([]))
     run_basic_mcts(node, env, 1, 3)
Exemplo n.º 4
0
 def test_nmcs(self):
     env = domain_parity_stack.make_env_stack()
     node = StackNode([])
     run_basic_nmcs(node, env, 0)
Exemplo n.º 5
0
 def successors(node):
     assert isinstance(node, StackNode)
     return [
         StackNode(stack) for stack in raw_successors(node.stack, max_k)
     ]
Exemplo n.º 6
0
    def finish(node):
        assert isinstance(node, StackNode)

        return StackNode(raw_finish(node.stack, max_k))
Exemplo n.º 7
0
 def test_mcts(self):
     env = domain_koza_stack.make_env_stack(5)
     node = MCTNode(StackNode([]))
     run_basic_mcts(node, env)
Exemplo n.º 8
0
 def test_nmcs(self):
     env = domain_koza_stack.make_env_stack(10)
     node = StackNode([])
     run_basic_nmcs(node, env)
Exemplo n.º 9
0
from mcts import MCTNode, mct_search
from nmcs import nested_mc_search
from domain_koza_apptree import make_env_app_tree
from domain_koza_stack import make_env_stack
from tree_node import ChooseKTNode, StackNode
from tree_stats import TreeStats
from utils import experiment_eval

if __name__ == "__main__":
    make_env = make_env_app_tree
    #make_env = lambda: make_env_stack(20)

    if False:
        # MCTS - one run
        env = make_env()
        # tracer_deco.enable_tracer = True
        # random.seed(5)
        tree_stats = TreeStats()

        # root = MCTNode(ChooseKTNode(UnfinishedLeaf(), 5))
        root = MCTNode(StackNode([]))
        mct_search(root, expand_visits=8, num_steps=4000,
                   fitness=env.fitness,
                   finish=env.finish,
                   is_finished=env.is_finished,
                   successors=env.successors,
                   tree_stats=tree_stats)
        print('=' * 20)
        print(root.pretty_str())
        print(tree_stats.pretty_str())