Exemplo n.º 1
0
Arquivo: util.py Projeto: COLAB2/midca
def jshop_tasks_from_goals(goals, pyhopState, STATE_FILE):
    #     thisDir =  os.path.dirname(os.path.realpath(__file__))
    #     MIDCA_ROOT = thisDir + "/../"
    #     STATE_FILE = MIDCA_ROOT + "jshop_domains/blocks_world/bw_ran_problems_500.shp"
    try:
        f = open(STATE_FILE, 'a')
    except Exception:
        print("could not read the state file. Check the path...")
    alltasks = []
    blkgoals = pyhop.Goal("goals")
    blkgoals.pos = {}
    f.write(" ((achieve-goals ( list\n")
    for goal in goals:
        #extract predicate
        if 'predicate' in goal.kwargs:
            predicate = str(goal.kwargs['predicate'])
        elif 'Predicate' in goal.kwargs:
            predicate = str(goal.kwargs['Predicate'])
        elif goal.args:
            predicate = str(goal.args[0])
        else:
            raise ValueError("Goal " + str(goal) +
                             " does not translate to a valid pyhop task")
        args = [str(arg) for arg in goal.args]
        if args[0] == predicate:
            args.pop(0)
        if predicate == "on":
            f.write("(on " + args[0] + " " + args[1] + ")\n")
        elif predicate == 'on-table':
            f.write("(on-table" + blkgoals.pos[args[0]] + ")\n")

        else:
            raise Exception("No task corresponds to predicate " + predicate)
    f.write(" ))))")
    f.close()
Exemplo n.º 2
0
Arquivo: util.py Projeto: COLAB2/midca
def pyhop_tasks_from_goals(goals, pyhopState):
    alltasks = []
    blkgoals = pyhop.Goal("goals")
    blkgoals.pos = {}
    for goal in goals:
        #extract predicate
        if 'predicate' in goal.kwargs:
            predicate = str(goal.kwargs['predicate'])
        elif 'Predicate' in goal.kwargs:
            predicate = str(goal.kwargs['Predicate'])
        elif goal.args:
            predicate = str(goal.args[0])
        else:
            raise ValueError("Goal " + str(goal) +
                             " does not translate to a valid pyhop task")

        args = [str(arg) for arg in goal.args]
        if args[0] == predicate:
            args.pop(0)
        if predicate == "on":
            blkgoals.pos[args[0]] = args[1]
        elif predicate == 'on-table':
            blkgoals.pos[args[0]] = 'table'
        elif predicate == "onfire" and 'negate' in goal and goal[
                'negate'] == True:
            alltasks.append(("put_out", args[0]))
        elif predicate == "free" and 'negate' in goal and goal[
                'negate'] == True:
            alltasks.append(("catch_arsonist", args[0]))
        else:
            raise Exception("No task corresponds to predicate " + predicate)
    if blkgoals.pos:
        alltasks.append(("move_blocks", blkgoals))
    return alltasks
Exemplo n.º 3
0
def pyhop_tasks_from_goals(goals,pyhopState):
    alltasks = []
    beacongoals = pyhop.Goal("goals")
    beacongoals.activated = {}
    perimeter_goal_locs = []
    agent_at_goal_locs = []
    
    for goal in goals:
        #extract predicate
        if 'predicate' in goal.kwargs:
            predicate = str(goal.kwargs['predicate'])
        elif 'Predicate' in goal.kwargs:
            predicate = str(goal.kwargs['Predicate'])
        elif goal.args:
            predicate = str(goal.args[0])
        else:
            raise ValueError("Goal " + str(goal) + " does not translate to a valid pyhop task")
        args = [str(arg) for arg in goal.args]
        if args[0] == predicate:
            args.pop(0)
        if predicate == "activated":
            loc = pyhopState.beaconlocs[str(args[0])]
            perimeter_goal_locs.append(loc)
        if predicate == "agent-at":
            agent_dest = convert(args[1])
            agent_at_goal_locs.append(agent_dest)

    # important, only one goal for all activated beacons
    if perimeter_goal_locs:
        alltasks.append(("make_perimeter",pyhopState.agents.keys()[0],perimeter_goal_locs))
        
    if agent_at_goal_locs:
        alltasks.append(("navigate",pyhopState.agents.keys()[0],agent_at_goal_locs))
    
    return alltasks
Exemplo n.º 4
0
def jshop_tasks_from_goals(goals, pyhopState):
    thisDir = os.path.dirname(os.path.realpath(__file__))
    MIDCA_ROOT = thisDir + "/../"
    STATE_FILE = MIDCA_ROOT + "jshop_domains/logistics/problems.shp"
    f = open(STATE_FILE, 'a')

    alltasks = []
    blkgoals = pyhop.Goal("goals")
    blkgoals.pos = {}
    f.write(" ((achieve-goals (list\n")
    for goal in goals:
        #extract predicate
        if 'predicate' in goal.kwargs:
            predicate = str(goal.kwargs['predicate'])
        elif 'Predicate' in goal.kwargs:
            predicate = str(goal.kwargs['Predicate'])
        elif goal.args:
            predicate = str(goal.args[0])
        else:
            raise ValueError("Goal " + str(goal) +
                             " does not translate to a valid pyhop task")
        args = [str(arg) for arg in goal.args]
        if args[0] == predicate:
            args.pop(0)
        if predicate == "obj-at":
            f.write("(obj-at " + args[0] + " " + args[1] + ")\n")

        else:
            raise Exception("No task corresponds to predicate " + predicate)
    f.write(" ))))")
    f.close()
Exemplo n.º 5
0
def pyhop_tasks_from_goals_restaurant(goals):
    alltasks = []
    ordergoals = pyhop.Goal("goals")
    ordergoals = copy.deepcopy(goals)
    if ordergoals:
        alltasks.append(("achieve_goals", ordergoals))
    return alltasks