Beispiel #1
0
def main():
    s0 = simple_state()
    g = s0.copy()
    g.pos['e'] = 'table'
    g.pos['f'] = 'e'
    g.pos['b'] = 'h'
    g.stacks[0] = [
        'a',
        'c',
    ]
    g.stacks[1] = ['f', 'e']
    g.stacks[3] = ['h', 'b']
    num_blocks = 7
    stacking_prob = .5

    s_rand = gen.gen_blocks_state(num_blocks, stacking_prob, max_stacks, True)
    g_rand = gen.gen_blocks_state(num_blocks, stacking_prob, max_stacks)

    print(gen.gen_list_representation(s0, _current_domain.max_stacks))
    print(gen.gen_list_representation(g, _current_domain.max_stacks))
    print(pyhop2.find_plan(s0, [('solve_goal', g)]))
    print(pyhop2.find_plan_GBFS(s0, [('solve_goal', g)], gen_strong_h(g)))
    #print(pyhop2.find_plan(s_rand, [('solve_goal', g_rand)]))


# main()
Beispiel #2
0
def is_level_done(state, goal, level):
    list_goal = gen.gen_list_representation(goal, _current_domain.max_stacks)
    for stack in list_goal:
        if len(stack) > level:
            curr_block = stack[level]
            if state.pos[curr_block] != goal.pos[curr_block]:
                return False
    return True
Beispiel #3
0
 def h(state, todo):
     goal_stacks = gen.gen_list_representation(goal, max_stacks)
     h_val = sum(list(map(len, goal_stacks)))
     for stack in goal_stacks:
         for block in stack:
             if state.pos[block] == goal.pos[block]:
                 h_val -= 1
             else:
                 break
     return h_val
Beispiel #4
0
def m_multi_stack_aux(state, goal, stack: int):
    """
    This helps the multigoal method by building a specific stack
    which is present in the goal.
    """
    list_goal = gen.gen_list_representation(goal, state.max_stacks)
    to_do = []
    for stack in list_goal:
        for block in stack:
            if goal.pos[block] == 'table':
                to_do += [('dissolve_smallest_incorrect_stack', goal)]
            to_do += [('pos', block, goal.pos[block])]
    #to_do += [goal]
    return to_do
def m_multi_level(state, goal):
    """
    This multigoal method works by completing each 'level' in the goal.
    blocks on level 0 are on the table,
    blocks on level 1 are on level 0 blocks,
    level 2 blocks are on level 1 blocks, etc.
    This method first accomplishes everything on level 0,
    then level 1, ... onto the highest level in the goal.
    """
    to_do = []
    curr_level = 0
    list_goal = gen.gen_list_representation(goal, state.max_stacks)
    ceiling = max(list(map(len, list_goal)))
    for i in range(ceiling):
        for stack in list_goal:
            if len(stack) > i:
                to_do += [('pos', stack[i],
                           stack[i - 1] if i != 0 else 'table')]
    return to_do
Beispiel #6
0
def m_multi_level_aux(state, goal, curr_level):
    """
    This multigoal method works by completing each 'level' in the goal.
    blocks on level 0 are on the table,
    blocks on level 1 are on level 0 blocks,
    level 2 blocks are on level 1 blocks, etc.
    This method first accomplishes everything on level 0,
    then level 1, ... onto the highest level in the goal.
    """
    list_goal = gen.gen_list_representation(goal, _current_domain.max_stacks)
    ceiling = max(list(map(len, list_goal)))
    if curr_level > ceiling:
        return []
    elif is_level_done(state, goal, curr_level):
        return [('multi_level_aux', goal, curr_level + 1)]
    else:
        blocks_at_curr_level = []
        for stack in list_goal:
            if len(stack) > curr_level:
                blocks_at_curr_level += [stack[curr_level]]
        return [('pos', b1, goal.pos[b1], goal) for b1 in blocks_at_curr_level
                ] + [('multi_level_aux', goal, curr_level)]