Ejemplo n.º 1
0
def main():
    num_blocks = 7
    s0 = gen_blocks_state(num_blocks, .8, start_state=True) 
    print(s0.stacks)
    #s0.display()

    g = gen_blocks_state(num_blocks, .8)
    #g.display()

    goal = pyhop2.Multigoal('random goal')
    goal.pos = g.pos

    import sys
    sys.setrecursionlimit(400)
    print(pyhop2.find_plan(s0, [goal]))
Ejemplo n.º 2
0
    ('station', 'downtown'): 2
}

# prototypical initial state
state0 = pyhop2.State()
state0.loc = {
    'alice': 'home_a',
    'bob': 'home_b',
    'taxi1': 'downtown',
    'taxi2': 'station'
}
state0.cash = {'alice': 20, 'bob': 15}
state0.owe = {'alice': 0}

# initial goal
goal1 = pyhop2.Multigoal('goal1')
goal1.loc = {'alice': 'park'}

# another initial goal
goal2 = pyhop2.Multigoal('goal2')
goal2.loc = {'bob': 'park'}

# bigger initial goal
goal3 = pyhop2.Multigoal('goal3')
goal3.loc = {'alice': 'park', 'bob': 'park'}

###############################################################################
# Helper functions:


def taxi_rate(dist):
Ejemplo n.º 3
0
def main():
    # If we've changed to some other domain, this will change us back.
    print(f"Changing current domain to {__name__}, if it isn't that already.")
    pyhop2.set_current_domain(__name__)

    pyhop2.print_domain()

    print("\nLet's call find_plan on some simple things that should fail.\n")

    state1 = pyhop2.State('state1')
    state1.pos = {'a': 'b', 'b': 'table', 'c': 'table'}
    state1.clear = {'c': True, 'b': False, 'a': True}
    state1.holding = {'hand': False}

    state1.display('Initial state is')

    plan = pyhop2.find_plan(state1, [('pickup', 'a')], verbose=1)
    check_result(plan, False)

    plan = pyhop2.find_plan(state1, [('pickup', 'b')], verbose=1)
    check_result(plan, False)

    plan = pyhop2.find_plan(state1, [('pos', 'b', 'hand')], verbose=1)
    check_result(plan, False)

    pause()
    print("""
Next, some simple things that should succeed. As a reminder, in state1,
block a is on block b, block b is on the table, and block c is on the table.
""")

    plan = pyhop2.find_plan(state1, [('pickup', 'c')], verbose=1)
    check_result(plan, [('pickup', 'c')])

    plan = pyhop2.find_plan(state1, [('unstack', 'a', 'b')], verbose=1)
    check_result(plan, [('unstack', 'a', 'b')])

    plan = pyhop2.find_plan(state1, [('pos', 'a', 'hand')], verbose=1)
    check_result(plan, [('unstack', 'a', 'b')])

    plan = pyhop2.find_plan(state1, [('pos', 'c', 'hand')], verbose=1)
    check_result(plan, [('pickup', 'c')])

    plan = pyhop2.find_plan(state1, [('pos', 'a', 'table')], verbose=1)
    check_result(plan, [('unstack', 'a', 'b'), ('putdown', 'a')])
    pause()

    print("""
A Multigoal is a data structure that specifies desired values for some of the
state variables. In blocks_tasks.py there are examples of tasks whose arguments
are multigoals, but here we give the multigoals directly to find_plan.

Below, goal1a says we want the blocks in the configuration "c on b on a", and
goal1a says we want "c on b on a on the table". goal1a and goal1b have the same
set of solutions, because the "a on the table" will be achieved anyway.
""")

    state1.display("Initial state is")

    goal1a = pyhop2.Multigoal('goal1a')
    goal1a.pos = {'c': 'b', 'b': 'a', 'a': 'table'}

    goal1a.display()

    goal1b = pyhop2.Multigoal('goal1b')
    goal1b.pos = {'c': 'b', 'b': 'a'}

    goal1b.display()

    expected = [('unstack', 'a', 'b'), ('putdown', 'a'), ('pickup', 'b'),
                ('stack', 'b', 'a'), ('pickup', 'c'), ('stack', 'c', 'b')]

    plan1 = pyhop2.find_plan(state1, [goal1a], verbose=1)
    check_result(plan1, expected)

    plan2 = pyhop2.find_plan(state1, [goal1b], verbose=1)
    check_result(plan2, expected)
    pause()

    print("""
Run find_plan on two more planning problems. Like before, goal2a omits some
of the conditions in goal2a, but both goals should produce the same plan.
""")

    state2 = pyhop2.State('state2')
    state2.pos = {'a': 'c', 'b': 'd', 'c': 'table', 'd': 'table'}
    state2.clear = {'a': True, 'c': False, 'b': True, 'd': False}
    state2.holding = {'hand': False}

    state2.display('Initial state is')

    goal2a = pyhop2.Multigoal('goal2a')
    goal2a.pos = {'b': 'c', 'a': 'd', 'c': 'table', 'd': 'table'}
    goal2a.clear = {'a': True, 'c': False, 'b': True, 'd': False}
    goal2a.holding = {'hand': False}

    goal2a.display()

    goal2b = pyhop2.Multigoal('goal2b')
    goal2b.pos = {'b': 'c', 'a': 'd'}

    goal2b.display()

    ### goal2b omits some of the conditions of goal2a,
    ### but those conditions will need to be achieved anyway.

    expected = [('unstack', 'a', 'c'), ('putdown', 'a'), ('unstack', 'b', 'd'),
                ('stack', 'b', 'c'), ('pickup', 'a'), ('stack', 'a', 'd')]

    plan1 = pyhop2.find_plan(state2, [goal2a], verbose=1)
    check_result(plan1, expected)

    plan2 = pyhop2.find_plan(state2, [goal2b], verbose=1)
    check_result(plan2, expected)
    pause()

    print(
        "\nRun find_plan on problem bw_large_d from the SHOP distribution:\n")

    state3 = pyhop2.State('state3')
    state3.pos = {
        1: 12,
        12: 13,
        13: 'table',
        11: 10,
        10: 5,
        5: 4,
        4: 14,
        14: 15,
        15: 'table',
        9: 8,
        8: 7,
        7: 6,
        6: 'table',
        19: 18,
        18: 17,
        17: 16,
        16: 3,
        3: 2,
        2: 'table'
    }
    state3.clear = {x: False for x in range(1, 20)}
    state3.clear.update({1: True, 11: True, 9: True, 19: True})
    state3.holding = {'hand': False}

    state3.display('Initial state is')

    goal3 = pyhop2.Multigoal('goal3')
    goal3.pos = {
        15: 13,
        13: 8,
        8: 9,
        9: 4,
        4: 'table',
        12: 2,
        2: 3,
        3: 16,
        16: 11,
        11: 7,
        7: 6,
        6: 'table'
    }
    goal3.clear = {17: True, 15: True, 12: True}

    goal3.display()

    expected = [('unstack', 1, 12), ('putdown', 1), ('unstack', 19, 18),
                ('putdown', 19), ('unstack', 18, 17), ('putdown', 18),
                ('unstack', 17, 16), ('putdown', 17), ('unstack', 9, 8),
                ('putdown', 9), ('unstack', 8, 7), ('putdown', 8),
                ('unstack', 11, 10), ('stack', 11, 7), ('unstack', 10, 5),
                ('putdown', 10), ('unstack', 5, 4), ('putdown', 5),
                ('unstack', 4, 14), ('putdown', 4), ('pickup', 9),
                ('stack', 9, 4), ('pickup', 8), ('stack', 8, 9),
                ('unstack', 14, 15), ('putdown', 14), ('unstack', 16, 3),
                ('stack', 16, 11), ('unstack', 3, 2), ('stack', 3, 16),
                ('pickup', 2), ('stack', 2, 3), ('unstack', 12, 13),
                ('stack', 12, 2), ('pickup', 13), ('stack', 13, 8),
                ('pickup', 15), ('stack', 15, 13)]

    plan = pyhop2.find_plan(state3, [goal3], verbose=1)
    check_result(plan, expected)
    pause()

    print("""
Call run_lazy_lookahead on the following problem, with verbose=1:
""")

    state2.display(heading='Initial state is')
    goal2b.display(heading='Goal is')

    new_state = pyhop2.run_lazy_lookahead(state2, [goal2b], verbose=1)

    pause()

    print(
        "The goal should now be satisfied, so the planner should return an empty plan:\n"
    )

    plan = pyhop2.find_plan(new_state, [goal2b], verbose=1)
    check_result(plan, [])

    print("No more examples")
Ejemplo n.º 4
0
    s.stacks = [['0', '1', '2'], [], [], [], [], []]
    return s


"""state/goal generation parameters"""
num_blocks = 7
stack_prob = .5
max_stacks = 6
"""random initial state and goal"""
s_rand = gen.gen_blocks_state(num_blocks,
                              stack_prob,
                              max_stacks,
                              start_state=True)
g_rand = gen.gen_blocks_state(num_blocks, stack_prob, max_stacks)
"""creating multigoal from random goal state"""
g = pyhop2.Multigoal()
g.pos = g_rand.pos
""" 
NOTE 1: Do no add the 'clear' dict to the goal;
The methods are not set up to solve state.clear[b1] == False
the 'clear' dict can be inferred from the 'pos' dict.
"""
# g.clear = g_rand.clear
"""
NOTE 2: The methods are only intended to solve complete plans,
so I'm not sure if trying to plan for a goal in which not all 
blocks from the initial state have a declared position will work.
"""
"""Finding a solution, the displaying the initial state and goal"""
"""
You can either pass a [multigoal] as the todo