Ejemplo n.º 1
0
        if is_a(x, 'location') and x != y:
            state.loc[taxi] = y
            state.owe[p] = taxi_rate(distance(x, y))
            return state


def pay_driver(state, p, y):
    if is_a(p, 'person'):
        if state.cash[p] >= state.owe[p]:
            state.cash[p] = state.cash[p] - state.owe[p]
            state.owe[p] = 0
            state.loc[p] = y
            return state


pyhop2.declare_actions(walk, call_taxi, ride_taxi, pay_driver)

###############################################################################
# Commands:


# this does the same thing as the action model
def c_walk(state, p, x, y):
    if is_a(p, 'person') and is_a(x, 'location') and is_a(y, 'location'):
        if state.loc[p] == x:
            state.loc[p] = y
            return state


# c_call_taxi
# like the action model, but chooses the taxi randomly
Ejemplo n.º 2
0
        return state

def pick_item(state, r, y):
	if is_a(r,'person') and is_a(y,'location') and state.loc[r] == state.loc[y]:
		state.loc[y] = state.loc[r]
		print(y, ' picked !!')
		return state

def pay_robot(state, r, y):
	if is_a(r,'person') and is_a(y,'location') and state.loc[r] == state.loc[y]:
		state.cost[r] = 0
		print(r, ' paid !!')
		return state


pyhop2.declare_actions(move_robot, pick_item, pay_robot)


# Commands:

def c_move_robot(state,r,y):
    if is_a(r,'person') and is_a(y,'location') and state.loc[r] != state.loc[y]:
        
        resp_location = robot_location('mobile_base', 'world')
        coord = (resp_location.pose.position.x, resp_location.pose.position.y)
        
        #######################################
        ### PLANNING WITHOUT FINITE HORIZON ###
        #######################################
        # wayp = astar(coord, state.loc[y], 0.4)
        # path = wayp
Ejemplo n.º 3
0
    """
    return variable in rigid.types[type]


###############################################################################
# Actions:


def append(state, x, y):
    if is_a(x, 'character') and is_a(y, 'character'):
        if state.last_char == x and permissible(x, y):
            state.last_char = y
            return state


pyhop2.declare_actions(append)

###############################################################################
# Methods:


def do_nothing(state, y):
    if is_a(y, 'character') and state.last_char == y:
        return []


def ms(x):
    def make_string(state, y):
        if is_a(y, 'character') and permissible(x, y):
            return [('make_string', x), ('append', x, y)]
Ejemplo n.º 4
0
###############################################################################
# Actions:


def putv(state, flag_val):
    state.flag = flag_val
    return state


def getv(state, flag_val):
    if state.flag == flag_val:
        return state


pyhop2.declare_actions(putv, getv)

###############################################################################
# Problem:

###############################################################################
# Running the examples

print(
    '-----------------------------------------------------------------------')
print(f"Created the domain '{domain_name}'. To run the examples, type this:")
print(f"{domain_name}.main()")


def main():
    # Code for use in paging and debugging
Ejemplo n.º 5
0
    return []


def insert_dummy(state, stack):
    bottom = None
    if state.stacks[stack]:
        bottom = state.stacks[stack][0]
    state.stacks[stack].insert(0, dummy_block)
    if bottom:
        state.pos[bottom] = dummy_block
        state.clear[dummy_block] = False
    state.pos[dummy_block] = 'table'
    return state


pyhop2.declare_actions(insert_dummy, remove_dummy)


def m_dissolve_stack(state, stack):
    """
    This is used to clear a specified stack from the table.
    Note that it can use any of the clearing methods for blocks.
    """
    return [('insert_dummy', stack), ('make_clear', dummy_block, dummy_block),
            ('remove_dummy', )]


pyhop2.declare_task_methods('dissolve_stack', m_dissolve_stack)


def m_move_one(state, b1, dest):
Ejemplo n.º 6
0
def unstack(state,b1,b2):
    if state.pos[b1] == b2 and b2 != 'table' and state.clear[b1] == True and state.holding['hand'] == False:
        state.pos[b1] = 'hand'
        state.clear[b1] = False
        state.holding['hand'] = b1
        state.clear[b2] = True
        return state
    
def putdown(state,b1):
    if state.pos[b1] == 'hand':
        state.pos[b1] = 'table'
        state.clear[b1] = True
        state.holding['hand'] = False
        return state

def stack(state,b1,b2):
    if state.pos[b1] == 'hand' and state.clear[b2] == True:
        state.pos[b1] = b2
        state.clear[b1] = True
        state.holding['hand'] = False
        state.clear[b2] = False
        return state


"""
Below, 'declare_actions(pickup, unstack, putdown, stack)' tells pyhop2
what the actions are. Note that the action names are *not* quoted.
"""

pyhop2.declare_actions(pickup, unstack, putdown, stack)
Ejemplo n.º 7
0
            state.loc['briefcase'] = l2
            return state

def take_out(state,x,l):
    if is_a(x,'object') and is_a(l,'location'):
        if state.loc[x] == 'briefcase' and state.loc['briefcase'] == l:
            state.loc[x] = l
            return state

def put_in(state,x,l):
    if is_a(x,'object') and is_a(l,'location'):
        if state.loc[x] == l and state.loc['briefcase'] == l:
            state.loc[x] = 'briefcase'
            return state

pyhop2.declare_actions(move, take_out, put_in)

###############################################################################
# Methods:

def organize(state, g):
    x = state.loc['briefcase']
    todo = []
    for obj in objects():
        if state.loc[obj] == 'briefcase' and g.loc[obj] == x:
            todo.append(('take_out', obj, x))
        elif state.loc[obj] == x and g.loc[obj] != x:
            todo.append(('put_in', obj, x))
    return todo

pyhop2.declare_task_methods('organize',organize)
Ejemplo n.º 8
0
def restack(state, block, position, dest):
    if state.pos[block] == position and position != 'table' and state.clear[
            block] and state.clear[dest]:
        remove_from_stack(state, block)
        state.pos[block] = dest
        state.stacks[get_stack_of_block(state, dest)] += [block]
        state.clear[position] = True
        state.clear[dest] = False
        return state


"""moves any clear block to the top of a stack specified by stack index"""


def move_to_stack(state, block, stack_index):
    position = state.pos[block]
    if state.clear[block]:
        remove_from_stack(state, block)
        if position != 'table': state.clear[position] = True
        dest = 'table'
        if not is_empty(state, stack_index):
            dest = state.stacks[stack_index][-1]
            state.clear[dest] = False
        state.pos[block] = dest
        state.stacks[stack_index] += [block]
        return state


"""incorporating these actions into the planner"""
pyhop2.declare_actions(move_to_stack, stack, unstack, restack)
Ejemplo n.º 9
0
#         x = state.loc[taxi]
#         if is_a(x,'location') and x != y:
#             state.loc[taxi] = y
#             state.owe[p] = taxi_rate(distance(x,y))
#             return state

# def pay_driver(state,p,y):
#     if is_a(p,'person'):
#         if state.cash[p] >= state.owe[p]:
#             state.cash[p] = state.cash[p] - state.owe[p]
#             state.owe[p] = 0
#             state.loc[p] = y
#             return state


pyhop2.declare_actions(move_robot)


###############################################################################
# Commands:


# this does the same thing as the action model
# def c_move_robot(state,p,x,y):
#     if is_a(p,'person') and is_a(x,'location') and is_a(y,'location'):
#         if state.loc[p] == x:
#             state.loc[p] = y
#             return state

def c_move_robot(state,r,y):
    if is_a(r,'person') and is_a(y,'location') and state.loc[r] != state.loc[y]: