Ejemplo n.º 1
0
        return state
    else:
        return False


def checkpile4(state, nothing):
    if (state.on_table['block-1'] == True and state.on['block-1'] == 'block-2'
            and state.on['block-2'] == 'block-3'
            and state.on['block-3'] == 'block-4'
            and state.clear['block-4'] == True):
        return state
    else:
        return False


new_tihtn_planner.declare_operators(pick_up, put_down, stack, checkpile1,
                                    checkpile2, checkpile3, checkpile4)
print('')
new_tihtn_planner.print_operators()


def tower5(state, block1, block2, block3, block4, block5):
    return [('tower4', block1, block2, block3, block4), ('make_clear', block5),
            ('checkpile4', ()), ('pick_up', block5),
            ('stack', block5, block4)], [[0, 1], [1, 2], [2, 3], [3, 4]]


def tower4(state, block1, block2, block3, block4):
    return [('tower3', block1, block2, block3), ('make_clear', block4),
            ('checkpile3', ()), ('pick_up', block4),
            ('stack', block4, block3)], [[0, 1], [1, 2], [2, 3], [3, 4]]
Ejemplo n.º 2
0
        return False


def take_img(state, satellite, direction, instrument, mode):
    if (state.calibrate[instrument] == True
            and state.on_board[instrument] == satellite
            and state.mode[instrument] == mode
            and state.power_on[instrument] == True
            and state.pointing[satellite] == direction):
        state.have_img[direction][mode] = True
        return state
    else:
        return False


new_tihtn_planner.declare_operators(turn_to, switch_on, switch_off, calibrate,
                                    take_img)
print('')
new_tihtn_planner.print_operators()


# define the methods
def get_img(state, direction, mode):
    instrument = state.mode[mode][0]
    return [('activate', instrument, state.on_board[instrument], direction),
            ('take_img', state.on_board[instrument], direction, instrument,
             mode)], [[0, 1]]


def activate(state, instrument, satellite, direction):
    # return [('switch_off', satellite), ('switch_on', instrument, satellite), ('auto_calibrate', instrument)], [[0, 1],[1, 2]]
    return [('switch_on', instrument, satellite)], []
Ejemplo n.º 3
0

def unload_truck(state, pkg, goal, truck):
    if state.loc.has_key(pkg) and state.loc[pkg][0] == truck and state.loc[
            pkg][1] == truck and state.load[truck] == pkg and state.loc[
                truck] == goal:
        tmp = (state.loc[truck][0], goal[1])
        state.loc[pkg] = copy.deepcopy(tmp)
        state.load[truck] = False
        return state
    else:
        return False


#可以看出,如何声明operator
new_tihtn_planner.declare_operators(load_plane, by_plane, unload_plane,
                                    load_truck, drive_truck, unload_truck)
print('')
new_tihtn_planner.print_operators()

#############################上面表示operator,下面表示method########################


#可以看出每一个method也是有条件的
def air_ship(state, pkg, goal):
    # i = random.randint(1, state.plane_nums)
    i = 1
    plane = 'plane' + str(i)
    return [('load_plane', pkg, (copy.deepcopy(state.loc[pkg][0]), 'loc1'),
             plane), ('unload_plane', pkg, goal, plane)], [[0, 1]]