def init_state(self):
        # set state variables to be used by operators and methods
        self.state = hop.State('start_state')
        self.state.path = []
        self.state.path_found = 0
        self.state.path_idx = -1
        self.state.equipment = None
        self.state.inventory = {
            'wood' : 1,
            'iron' : 0,
            'steel' : 1,}
        self.state.targets = {
            'gold': {
                'location': (0,0,0),
                'reached': 0,
                'broken': 0,
                'acquired': 0,},
            'wall': {
                'location': (-66,14,-46),
                'reached': 0,
                'broken': 0,
                'acquired': 0,},}

        self.failed_method = None
        self.preconditions = {
            'break_wall' : {
                'precondition'  : None,
                'inventory'     : ['iron'],
            },
        }
        self.methods = {
            'break_wall' : self.break_wall
        }
 def init_state(self):
     # set state variables to be used by operators and methods
     self.state = hop.State('start_state')
     self.state.gold = 1  # 1: unbroken, 0: broken
     self.state.path = []
     self.state.gold_reached = 0
     self.state.path_found = 0
     self.state.path_idx = -1
     self.state.gold_broken = 0
     self.state.gold_acquired = 0
Пример #3
0
 def __init__(self):
     self.state = hop.State("Initial State")
     self.objList = {}
     self.taskList = []
     self.methodList = {}
def task1(state, r, o, x, y):
    tasklist = [('look_cupboard', r), ('goto', r, '', x), ('open', r, x),
                ('look_table', r), ('goto', r, x, y)]
    X1 = [('pick', r, o, y), ('goto', r, y, x), ('place', r, o, x),
          ('goto', r, x, y)]
    for k in range(5):
        for j in range(len(X1)):
            tasklist.append(X1[j])
    return tasklist


hop.declare_methods('task1', task1)
print('')
hop.print_methods(hop.get_methods())

state1 = hop.State('state1')
state1.loc = {'objects': 'table', 'robot': ''}
state1.objects = {'table': 5, 'cupboard': 0}
state1.gripperfree = True  #gripper true referes to gripper free state
state1.cupboardisopen = False  #cupboard is closed
state1.isTable = False
state1.isCupboard = False

print("""
********************************************************************************
Call hop.plan(state1,[('task1','robot','coke','cupboard','table')])
********************************************************************************
""")

print('- If verbose=3, Pyhop also prints the intermediate states:')
hop.plan(state1, [('task1', 'robot', 'objects', 'cupboard', 'table')],
Пример #5
0
 def init_state(self):
     # set state variables to be used by operators and methods
     self.state = hop.State('start_state')
     # TODO: convert everything into one directory which has 'resource', 'inventory' key all in one
     # variables in this minecraft world
     self.PLAN_STATUS = None
     # 0: Rendered obsolete by assertions, 1: All okay, 2: Error, need replanning or introspection
     self.ASSERT_ID = None
     # id of the assertion held true right now
     self.state.target = 'gold'
     self.plan_idx = 0
     self.state.turn_num = 0
     self.state.objects = {
         'gold',
         'stone_block',
     }
     self.state.object_id = {'gold': 41, 'stone_block': 100}
     self.state.tools = {}
     # information structure for keeping track of world state
     self.state.resources = {}
     for obj in self.state.objects:
         self.state.resources[obj] = {
             'state': None,
             'hemisphere': None,
             'location': None,
         }
     # information structure to keep track of self state
     # State = None: not located yet, 0: seen but not near, 1: near, -1: broken
     # Hemisphere = None: Haven't seen so far, -1: was to the left of the cone,
     # 0: was in the center, +1: was to the right of the cone
     self.state.agent = {
         'cur_xyz': None,
         'cur_theta': None,
         'start_xyz': None,
         'start_theta': None,
     }
     self.state.inventory = {}
     for obj in self.state.objects:
         self.state.inventory[obj] = 0
     # self.state.need_percept = 0
     #goal state
     self.goal_state = hop.State('goal_state')
     self.goal_state.resources = {}
     self.goal_state.resources['gold'] = {
         'state': -1,
         'hemisphere': [-1, 0, 1],
     }
     self.goal_state.inventory = {}
     self.goal_state.inventory['gold'] = 1
     self.assertions = {}
     self.assertions = {
         1: {
             'resources': {
                 'gold': {
                     'state': 0,
                 },
             },
         },
         # gold must be in sight to plan how to navigate
         2: {
             'resources': {
                 'gold': {
                     'state': 1,
                 },
             },
             'inventory': {
                 'gold': 0
             },
         },
         3: {
             'inventory': {
                 'gold': 1,
             },
         },
         # agent must be next to gold block to plan how to break it
     }
Пример #6
0
#############     beginning of tests     ################

print("""
****************************************
First, test pyhop on some of the operators and smaller tasks
****************************************
""")

print("- Define state1: a on b, b on tale, c on table")
"""
A state is a collection of all of the state variables and their values. Every
state variable in the domain should have a value.
"""

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

hop.print_state(state1)
print('')

print('- these should fail:')
hop.plan(state1, [('pickup', 'a')],
         hop.get_operators(),
         hop.get_methods(),
         verbose=1)
hop.plan(state1, [('pickup', 'b')],
         hop.get_operators(),
         hop.get_methods(),