def fixsolutionnew_backward1(plan_list,lists,init,new_plan, actions, TYPING, goals,new_actions):
    print "actions",actions
    print "new_actions",new_actions
    print "plan_list",plan_list
    if plan_list == []:
        return []
    else:
        move = plan_list[-1]
        print "move",move
#        print "G.storage2",G.storage2
#        if checkmove(move) or checkmove(move[:-2]):
#            print "helper"
#            x=2
#        else:
        state = goals
        print "state",state
        for i in lists:
            for j in i:
                print "move1",move
                print "j",j
                print "i",i
                newmove = repairmove_complex(move,j,i,actions,new_actions)
#need to make a new repairmove (using the old move and the new move)
                print "newmove88",newmove
                print "state",state
                newstate = testmove_backward(newmove,state,actions, TYPING)            #changed to new_actions 3/11
                print "newstate2",newstate  ###gets this far...in pour_shaker_to_shot2b ....must add preconditions to testmove_backward  3/12/2014
                if newstate <> False:
                    new_plan.append(newmove)
                    temp2 = fixsolutionnew_backward1(plan_list[0:-1],lists,init,new_plan,actions, TYPING, newstate,new_actions) 
                else:
                    temp2 = False
                print "i",i
                print "j",j
                print "newstate444",newstate
                print "temp2",temp2
                print "G.recurse",G.recurse
                if G.recurse <> 0:
                    new_plan = new_plan[0:-(len(plan_list)-1)]
                    G.recurse = 0
                print "new_plan",new_plan
                print "plan_list",plan_list
                print "plan_list[0:-1]",plan_list[0:-1]
                print "temp2",temp2
                if temp2 <> False:
                    temp2.insert(0,newmove)
                    return temp2
#                else: 
#                    print "new_plan1",new_plan
#                    new_plan = new_plan[0:-1]
#                    print "new_plan2",new_plan
        new_plan = new_plan[0:-1]
        G.recurse = G.recurse + 1
        return False
    _PRINT("really??")
Exemple #2
0
def maketypehierarchy(types):
    _PRINT(len(types))
    mark = False
    store = []
    l = range(0, len(types))
    for i in l:
        if types[i] == ":types":
            fred = 3  #do nothing
        elif types[i] == "-":
            mark = True
        elif mark == True:
            G.ontology.insert(0, [store, types[i]])
            store = []
            mark = False
        else:
            store.insert(0, types[i])
    #_PRINT("ontology",G.ontology)
    return G.ontology
Exemple #3
0
def run(domain_file, problem_file, direction, local_config=None):
    '''
    This is the entry point for the PDDL Reform application
    It expects two input files in PDDL format and generates a set of files in response including:

     - reformulated input files
     - a regenerated sas plan file
    '''

    if not local_config is None:
        names = dir(local_config)
        if not 'APP_HOME' in names and not 'PLANNER_HOME' in names:
            local_config = None

    # Read in the domain and problem input files
    domain, prob = core.read_input(domain_file, problem_file)

    G.HASMETRIC = False
    G.HAVEFUNCTIONS = False
    G.HASREQUIREMENTS = False

    # Parse the domain input
    domain2, requirements, predicates, types, actions, domain_list1_real, domain_list1_temp = core.parse_domain(
        domain)

    # Form a deep copy of the actions component
    _DEBUG("requirements", requirements)
    _DEBUG("actions", actions)
    old_actions = copy.deepcopy(
        actions)  #! do not remember why I had to do this
    _DEBUG("helphelp", old_actions)

    # Parse the problem input
    prob2, objects1, goals, init, prob_list2_real, prob_list2_temp = core.parse_problem(
        prob)

    _DEBUG("objects", objects1)
    _DEBUG("goals", goals)

    # Process the typing if applicable
    ontology, typing, objects, typeof_l, SOKOBAN = core.process_typing(
        requirements, types, objects1)
    G.typeof = typeof_l
    _PRINT("typeof!", G.typeof)
    print "ontology", ontology

    # Check whether we can reformulate this input
    REFORMULATE, myset, FOUND, direction = core.test_reformulate(
        direction, objects, actions, goals, prob2, init, ontology, objects1)

    print "test3"
    # If we can't reformulate then simply output what was input and exit
    if myset == []:
        #_PRINT("reformulate",REFORMULATE,"myset",myset) #"mylist",mylist
        planner.giveup(domain,
                       prob,
                       domain_file,
                       problem_file,
                       local_config=local_config)
        sys.exit()

    _DEBUG("reformulate", REFORMULATE)
    print "test2"
    # Otherwise if we can reformulate the input do so
    if REFORMULATE:
        lists, new_actions = core.reformulate(
            myset, domain2, requirements, predicates, types, actions,
            domain_list1_real, domain_list1_temp, prob2, objects1, goals, init,
            prob_list2_real, prob_list2_temp, ontology, typing, objects,
            SOKOBAN, direction, objects1)

    #fix double list first - change gripper to make 2 lists
    #! run lmcut
    #! replace methodologyical

    # Execute the embedded planner over the reformulated input files
    timer = timeit("timing.txt", "elapsed")
    timer.start(domain_file, problem_file)
    timer.capture()
    plan = planner.execute(local_config=local_config)
    timer.capture()

    #_PRINT("plan",plan)

    # Post process the resulting sas_plan file
    print "all_lists", G.all_lists
    if G.all_lists <> []:
        solution = core.postprocess_plan(plan, G.all_lists, init, old_actions,
                                         goals, direction, new_actions)
    else:
        solution = core.postprocess_plan(plan, lists, init, old_actions, goals,
                                         direction, new_actions)

    _DEBUG("solutionwww", solution)
    #_PRINT("solution", solution)

    # Finally write out the resulting new sas_plan file
    core.writeout_solution(solution)

    _DEBUG("test")
    _DEBUG(reform.fun('D', ['ontable', 'D']))
    _DEBUG("found", FOUND)

    timer.capture()
    timer.stop()
def fixsolution1(plan_list,lists,new_plan):                              #! old code not currently used ........second fixsolution routine which includes new_plan where we build the plan so we can backtrack
    #global recurse
    _DEBUG("new_plan",new_plan)
    _DEBUG("plan_list",plan_list)
    if plan_list == []:
        suceed = planner.runvalidation(new_plan)
        _DEBUG("suceed",suceed)
        if suceed <> False:
            return new_plan
        else:
            return False
    move = plan_list[0]
    _DEBUG("move",move)
#    if len(move) == 6:
    if checkmove(move):
        _DEBUG("here1")
        for i in lists:
            _DEBUG("i",i)
            _DEBUG("lists",lists)
            for j in i:
                _DEBUG("here2")
                _DEBUG("j",j)
                _DEBUG("i",i)
                new_move = repairmove(move,j,i)
                _DEBUG("new_move",new_move)
                new_plan.append(new_move)
                temp = fixsolution1(plan_list[1:],lists,new_plan)
                if G.recurse <> 0:
                    _DEBUG("recurseb", G.recurse,len(plan_list),len(new_plan))
                    new_plan = new_plan[0:-(len(plan_list)-1)] #changed from -recurse
                    G.recurse = 0
                    _DEBUG("tempa",temp)
                if temp <> False:
                    _DEBUG("here3")
                    temp.insert(0,new_move)
                    _DEBUG("temp",temp)
                    return temp
                else:
                    _DEBUG("before",new_plan)
                    new_plan = new_plan[0:-1]
                    _DEBUG("ohnoc",new_plan)
#                    return False
        new_plan = new_plan[0:-1] #not sure this does anything
        _DEBUG("ohnoa",new_plan)
        G.recurse = G.recurse + 1
        _DEBUG("recurse", G.recurse)
        return False
    if len(move) < 6:
        _DEBUG("here4")
        new_plan.append(move)
        temp2 = fixsolution1(plan_list[1:],lists,new_plan)
        _DEBUG("temp2",temp2)
        if temp2 <> False:
            _DEBUG("here5")
            temp2.insert(0,move)
            _DEBUG("temp2",temp2)
            return temp2
        else:
            new_plan = new_plan[0:-1]
            _DEBUG("ohnob",new_plan)
            G.recurse = G.recurse + 2
            _DEBUG("recursec",G.recurse)
            return False
    _PRINT("really??")
def fixsolutionnew1(plan_list,lists,state,new_plan,actions, TYPING):               #!attempts to find solution to old representation - using new_plan for backtracking
    print "fix1",lists
    _PRINT("debugstate",state)
    _DEBUG("fix1",plan_list)
    #global recurse
    _DEBUG("new_plan",new_plan)
    _DEBUG("plan_list",plan_list)
    if plan_list == []:
#!        suceed = planner.runvalidation(new_plan)
#!        if debug == True:
#!            print "suceed",suceed
#!        if suceed <> False:
        _DEBUG("new_plan1111",new_plan)
#        return new_plan                 this was the bug
        return []
#!        else:
#!            return False
    move = plan_list[0]
    _DEBUG("move",move)
#    if len(move) == 6:
    _DEBUG("checkmove",move,checkmove(move))
    if checkmove(move):
        _DEBUG("checkmove",move)
        _DEBUG("here1")
        if notsametype(lists):
            return double_loop(plan_list,lists,state,new_plan,actions, TYPING)
        for i in lists: ### this this works if two sets of balls not a set of balls and a set of trucks
            _DEBUG("i",i)
            _DEBUG("lists",lists)
            for j in i:
                _DEBUG("debug",j,"i",i)
                _DEBUG("here2")
                _DEBUG("j",j)
                _DEBUG("i",i)
                _DEBUG("debugmove",move)
                if G.unary_big == []:
                    new_move = repairmove(move,j,i)
                else:
                    new_actions = G.new_actions
                    new_move = repairmove_complex(move,j,i,actions,new_actions) 
                _DEBUG("debugnewmove",new_move)
#                if debug == True:
                _DEBUG("newmovezzz",new_move)
                newstate = testmove(new_move,state,actions, TYPING) #must write this
#                if debug == True:
                _DEBUG("newstate",newstate)
                _DEBUG("newstatezzz",newstate)
                _DEBUG("new_move",new_move)
                _DEBUG("newmove",new_move)
                if newstate <> False:
                    new_plan.append(new_move)
                    _DEBUG("newplan1",new_plan)
                    temp = fixsolutionnew1(plan_list[1:],lists,newstate,new_plan,actions, TYPING)
                    _DEBUG("newplan9",new_plan)
                else:
                    _DEBUG("scary")
                    temp = False
                if G.recurse <> 0:
#                    if debug == True:
                    _DEBUG("recurseb")
                    new_plan = new_plan[0:-(len(plan_list)-1)] #changed from -recurse
                    _DEBUG("newplan2",new_plan) # never happens
                    G.recurse = 0
                    _DEBUG("tempa",temp)
                if temp <> False:
                    _DEBUG("here3")
                    temp.insert(0,new_move)
                    _DEBUG("temp",temp)
                    return temp
                else:
                    _DEBUG("before",new_plan)
                    new_plan = new_plan[0:-1]
                    _DEBUG("newplan3",new_plan)
                    _DEBUG("ohnoc",new_plan)
#                    return False
        new_plan = new_plan[0:-1] #not sure this does anything
        _DEBUG("newplan4",new_plan) #never happens
        _DEBUG("ohnoa",new_plan)
        G.recurse = G.recurse + 1
        _DEBUG("recurse", G.recurse)
        return False
#    if len(move) < 6:
    else:
        _DEBUG("here4")
        _DEBUG("here4")
        _DEBUG("move",move)
        _DEBUG("state",state)
        print "state88",state
        newstate = testmove(move,state,actions, TYPING)
#        if debug == True:
        _DEBUG("newstatevvv",newstate)
        if newstate == False:
            _PRINT("recurse2")
            new_plan = new_plan[0:-1]
            _PRINT("newplan5",new_plan) #never happens
            G.recurse = G.recurse + 1
        new_plan.append(move)
        _DEBUG("newplan6",new_plan)
        temp2 = fixsolutionnew1(plan_list[1:],lists,newstate,new_plan,actions, TYPING)
        _DEBUG("new_plan8",new_plan)
        _DEBUG("temp2",temp2)
        if temp2 <> False:
            _DEBUG("here5")
            temp2.insert(0,move)
            _DEBUG("temp2",temp2)
            return temp2
        else:
            new_plan = new_plan[0:-1]
            _DEBUG("newplan7",new_plan) #never happens
            _DEBUG("ohnob",new_plan)
            G.recurse = G.recurse + 2
            _DEBUG("recursec",G.recurse)
            return False
    _PRINT("really??")