def replaceinmove2(new_move,params,replace_lists): _DEBUG("new_move",new_move,"replace_lists",replace_lists) types = return_type_list(params) print "types",types l = range(1,len(new_move)) print "new_move",new_move print "l",l t = range(0,len(G.locations_in_list)) for j in t: #make G.which a pair which says which entry in newmove[1, [shot4..]] for i in l: print "here111",j,i,new_move[i],G.which[j][1][-1] type_newmove = core.find_type_of(new_move[i],G.pats_favorite) print "type_newmove",type_newmove # for p in replace_lists: # print "p1",p[0] type_which = core.find_type_of(G.which[j][1][-1],G.pats_favorite) print "type_p1",type_which print "i",i,G.which[j] print "new_move[i]",new_move[i] if i == G.which[j][0] and (new_move[i] == G.which[j][1][-1] or type_which == type_newmove or new_move[i] in G.which[j][1]): # temp_list - G.which[t] print "here222" print "new_move[i]",new_move[i] print "G.locations_in_list[j]",G.locations_in_list[j] print "G.which[j]",G.which[j] new_move[i] = G.which[j][1][G.locations_in_list[j]-1] print "new_move",new_move print "GG.locations_in_list",G.locations_in_list increment1() print "GGGG.locations_in_list",G.locations_in_list return new_move
def fixsolution(plan_list,lists): #! old code that is not currently used (see new version above) ... this tried all options and ran the validator....too solve #global recurse _DEBUG("plan_list",plan_list) _DEBUG("lists",lists) G.recurse = 0 plan = fixsolution1(plan_list,lists,[]) return plan
def replaceinmove(new_move,replace,lists): _DEBUG("new_move",new_move,"replace",replace,"lists",lists) l = range(0,len(new_move)) for i in l: if new_move[i] == lists[len(lists)-1]: new_move[i] = replace return new_move
def addzero_typing(objects, locations, theobject, new_init, original_objects, typing): print "00objects", objects, "locations", locations, "theobject", theobject, "new_init", new_init, "original_objects", original_objects, "typing", typing # if debug == True: _DEBUG("addzerotyping", objects, "locations", locations, "theobjects", theobject) #,"new_init",new_init if locations == []: # newzero = ["count1a1a",theobject, original_objects[i] , "0"] print "newzero" # new_init.append(newzero) else: thelocation = locations[0] l = range(0, len(original_objects)) for i in l: if thelocation == original_objects[i]: theindex = i thetype = typing[theindex] for i in l: if typing[i] == thetype: if not original_objects[i] in locations: newzero = [ "count1a1a", theobject, original_objects[i], "0" ] _DEBUG("newzero", newzero) print "newzero", newzero new_init.append(newzero) print "new_init", new_init return new_init
def runvalidation(new_plan, local_config=None): #! code that ran the validator with the final solution....also not run anymore config = default_config if not local_config is None: config = local_config _DEBUG("new_plan_yea",new_plan) solutionstring = tostring(new_plan) _DEBUG("solutionstring",solutionstring) _DEBUG("test",solutionstring[1:-1]) solution_file = open("sas_plan_new", "w") solution_file.write(solutionstring[1:-1]) solution_file.close() test_file = open("tester","w") subprocess.call(["%s/src/validate newdomain.pddl newprob.pddl sas_plan" % config.PLANNER_HOME], shell=True, stdout=test_file) _DEBUG("subprocess",subprocess) #! omp_cmd = '/Users/prid013/Documents/Fast-Downward-8ea549f76262/src/validate /Users/prid013/Documents/IPCdomains/benchmarks3/gripper/domain.pddl /Users/prid013/Documents/IPCdomains/benchmarks3/gripper/prob01.pddl /Users/prid013/Documents/IPCdomains/sas_plan_new' #!with open(test_file) as stdout: #! xmlResult = Popen(shlex.split(omp_cmd), stdin=stdin, stdout=PIPE, stderr=STDOUT) test_file.close() test_file = open("tester","r") output = test_file.read() _DEBUG("output",output) if "Successful" in output: return new_plan else: return False
def checkmove(move): _DEBUG("G.storage2",G.storage2,"move",move) print "movename",move print "G.storage2",G.storage2 l = range(0,len(G.storage2)) for i in l: if move[0].lower() == G.storage2[i].lower() or move[0][0:-2].lower() == G.storage2[i].lower(): _DEBUG("yeaa",move[0],G.storage2[i]) return True return False
def dotyping2(objects, typing, leftover, count): _DEBUG("objects2", objects, "typing", typing, "leftover", leftover, "count", count) # if count[0] == 1: # typing.insert(len(typing),objects[0]) # else: l = range(0, (count[0])) for i in l: typing.insert(len(typing), objects[0]) leftover += objects[1:]
def dotyping1(objects, typing, leftover, count): _DEBUG("objects1", objects, "typing", typing, "leftover", leftover, "count", count) if objects[0] == "-": leftover += objects[1:] return [] else: nextobj = dotyping1(objects[1:], typing, leftover, count) nextobj.insert(0, objects[0]) count[0] = count[0] + 1 return nextobj
def fixsolutionnew(plan_list,lists,init,actions, TYPING): #!attempts to find solution to old representation # print "init",init _DEBUG("fix",plan_list) #global recurse _DEBUG("plan_list",plan_list) _DEBUG("lists",lists) G.recurse = 0 plan = fixsolutionnew1(plan_list,lists,init,[],actions, TYPING) _DEBUG("plan",plan) _DEBUG("planzzz",plan) return plan
def dotyping(objects, typing): _DEBUG("objects", objects, "typing", typing) if objects == []: return [] leftover = [] count = [0] new_objects = dotyping1(objects, typing, leftover, count) leftover2 = [] _DEBUG("count", count) new_type = dotyping2(leftover, typing, leftover2, count) # typing.insert(len(typing),new_type) newer_objects = dotyping(leftover2, typing) new_objects.extend(newer_objects) return new_objects
def fixparam(param, TYPING): newparam = [] _DEBUG("debugparam",param) if TYPING == True: newparam.insert(0,param[0]) l = range(1,len(param)) for i in l: # if i % 3 == 0: # newparam.insert(len(param),param[i]) temp = param[i] if temp[0] == "?": newparam.insert(len(newparam),param[i]) else: newparam=param _DEBUG("debugnewparam",newparam) return newparam
def tostring(old): _DEBUG("old1",old) #! if debug == True: len, len(old) if old == []: return '' #! if debug == True: "old2", old[0] if type(old) is str: return old if type(old) is int: return str(old) if type(old) is list: l = range(0,len(old)) string = "(" + " " for i in l: string += tostring(old[i]) + " " return string + ")"
def completeset_typing1(lists, objects, typing): _DEBUG("lists", lists, "lists[len(lists)]", lists[len(lists) - 1], "objects", objects, "typing", typing) extra = [] l = range(0, len(objects)) for i in l: if lists[len(lists) - 1] == objects[i]: mytype = typing[i] for i in l: if typing[i] == mytype: MISSING = True k = range(0, len(lists)) for m in k: if objects[i] == lists[m]: MISSING = False if MISSING == True: extra.insert(0, [objects[i]]) return extra
def findparam(new_move,move): l = range(0,len(G.storage3)) for i in l: _DEBUG("new_move[0]",new_move[0],"G.storage3[i]",G.storage3[i],len(move),len(G.storage3[i+1]),G.storage3) if isinstance(G.storage3[i],str) and new_move[0].lower() == G.storage3[i].lower(): start = len(move)-len(G.storage3[i+1]) end = start + len(G.storage3[i+1]) _DEBUG("start",start) _DEBUG("end",end) new_move.extend(move[start:end]) _DEBUG("new+movedebug",new_move) return new_move
def addinit_typing(mylist, counter_type, new_init, more_list, original_objects, typing, max_num, init, predicates, objects): print "josie", mylist, len(mylist) print "counter_type", counter_type #_PRINT("mylist1",mylist) _DEBUG("typinglists", mylist, "counter_type", counter_type) if mylist == []: return [] elif len(mylist) == 1: _DEBUG("mylist", mylist) return addinit_typing1(mylist[0], counter_type[0], new_init, more_list, original_objects, typing, max_num, init, predicates, objects) else: newer_init = addinit_typing1(mylist[0], counter_type[0], new_init, more_list, original_objects, typing, max_num, init, predicates, objects) return addinit_typing(mylist[1:], counter_type[1:], newer_init, more_list, original_objects, typing, max_num, init, predicates, objects)
def giveup(domain,prob, domain_file, problem_file, local_config=None): _DEBUG("OH NO") new_file_name = "newdomain.pddl" text_file = open(new_file_name, "w") #!write prob string into a file text_file.write(domain) text_file.close() new_file_name = "newprob.pddl" text_file = open(new_file_name, "w") #!write prob string into a file text_file.write(prob) text_file.close() timer = timeit("timing.txt", "elapsed") timer.start(domain_file, problem_file) timer.capture() plan = execute(local_config=local_config) timer.capture() solution_file = open("sas_plan_new", "w") solution_file.write(plan) solution_file.close() timer.capture() timer.stop() return []
def completeset_typing(lists, objects, typing): _DEBUG("listslistslists", lists) _DEBUG("objects", objects) _DEBUG("typing", typing) if lists == []: return [] extra = completeset_typing1(lists[0], objects, typing) #_PRINT("extrareal",extra) extra2 = completeset_typing(lists[1:], objects, typing) #_PRINT("extrareal",extra) #_PRINT("extrareal2",extra2) extra.extend(extra2) return extra
def fix_counter_type1( counter_type, temp ): #! this is the second routine called from ebfore that has the "temp" variable we are building up _DEBUG("c", counter_type, "t", temp) if counter_type == []: return [temp] if counter_type[0] == "merge" and counter_type[1:] == []: return temp if counter_type[0] == "merge": temp2 = [] reallist = fix_counter_type1(counter_type[1:], temp2) _DEBUG("temp2", temp2, "temp", temp) temp = [temp] temp.extend(reallist) _DEBUG("realtemp", temp) return temp temp.append(counter_type[0]) return fix_counter_type1(counter_type[1:], temp)
def checkprecond_typing(precond, action, typeof): # if not checkprecond_typing_part1(precond,action,typeof): print "thetypes", G.thetypes checkset = returntypes(typeof, G.thetypes) # return checkprecond_typing_part2(precond,action,checkset) # #def checkprecond_typing_part2(precond,action,thetypes) # #def checkprecond_typing_part1(precond,action,typeof): print "typeof", typeof print "action", action print "checkset", checkset found = False _DEBUG("action", action, "precond", precond) l = range(0, len(action)) for i in l: #! break domain list into important pieces if action[i] == ":parameters": myobject = action[i + 1] _DEBUG("objects1", myobject) j = 0 # while j+2 < len(myobject): # _DEBUG("myobject",myobject[j+2],"typeof",typeof) # print "checkseta",checkset,"myobject[j+2]",myobject[j+2],"typeof",typeof # if myobject[j+2] == typeof or myobject[j+2] in checkset: # print "checksetb",checkset,"myobject[j+2]",myobject[j+2],"typeof",typeof # realtype = myobject[j] # found = True # j = j+3 # return found while j < len(myobject): _DEBUG("myobject", myobject[j], "typeof", typeof) print "checkseta", checkset, "myobject[j+2]", myobject[ j], "typeof", typeof if myobject[j] == typeof or myobject[j] in checkset: print "checksetb", checkset, "myobject[j+2]", myobject[ j], "typeof", typeof realtype = myobject[j] found = True j = j + 1 return found
def checkprecond_typing2(precond, action, typeof): found = False _DEBUG("action", action, "precond", precond) l = range(0, len(action)) for i in l: #! break domain list into important pieces if action[i] == ":parameters": myobject = action[i + 1] _DEBUG("objects1", myobject) j = 0 while j + 2 < len(myobject): _DEBUG("myobject", myobject[j + 2], "typeof", typeof) if myobject[j + 2] == typeof: realtype = myobject[j] found = True j = j + 3 l = range(0, len(precond)) _DEBUG("realtype1", realtype, "precond", precond) for i in l: if isinstance(precond[i], list): k = range(0, len(precond[i])) temp = precond[i] for j in k: _DEBUG("realtype3", realtype, "temp", temp[j]) if realtype == temp[j]: return True else: _DEBUG("realtype2", realtype, "precond", precond[i]) if realtype == precond[i]: return True return False
def testmove(newmove,state,actions, TYPING): #!checks to see if move can be applied, returns new state # if debug == True: print "statestate",state print "newmove",newmove _DEBUG("newmove",newmove,"state",state,"actions",actions) _DEBUG("newmove",newmove) _DEBUG("state", state) realstate = state[1:] _DEBUG("actions",actions) matches = [] for i in actions: _DEBUG("debugging") _DEBUG("action",i) _DEBUG("i",i) param = i[3] if TYPING == True: param = ancillary.fixparam(param, TYPING) # if debug == True: _DEBUG("param",i[3]) _DEBUG("newmove[0]",newmove[0],"i[1]",i[1]) if newmove[0].lower() == i[1].lower(): print "i[5]",i[5] precond1 = i[5] if precond1[0] == "and": #3/20/2014 precond2 = precond1[1:] else: precond2 = [precond1] print "precond2",precond2 _DEBUG("debugi",i,"precond1",precond1,"precond2",precond2) _DEBUG("precond2",precond2) #! for k in precond2: #!make matches list #! match1 = False #! for j in realstate: #! print "matches",matches #! print "i",i #! print "j",j #! print "k",k #! if k == "and": #! match1=True #! if k[0] == j[0] or k == "and": #! if len(k) == 2: #! matches.insert(0,[j[1],k[1]]) #! if len(k) == 3: #! matches.insert(0,[j[1],k[1]]) #! matches.insert(0,[j[2],k[2]]) #! match1=True #! print "precon",k #! print "match1",match1 #! if match1 <> True: #! return False #! newmatches = remove_duplicates(matches) #!remove duplicates in matches list for k in precond2: #!check instantiated preconditions print "kkk",k _DEBUG("debugk",k,"precond2",precond2) match1 = False if k == "and": match1=True else: # if debug == True: _DEBUG("instantiate",k,"newmove",newmove,"param",param) newk = instantiate(k,newmove,param) # if debug == True: _DEBUG("newk",newk) _DEBUG("realstate",realstate) print "k",k for j in realstate: print "j",j,"newk",newk _DEBUG("realstate",realstate) _DEBUG("matches",matches) _DEBUG("i",i) _DEBUG("j",j) _DEBUG("k",k) _DEBUG("newked",newk) _DEBUG("j",j) if newk == j or k == "and": match1=True _DEBUG("preconkkk",k) _DEBUG("match1",match1) print "match1",match1 if match1 <> True: return False _DEBUG("here?") #,newmatches _DEBUG("newmove",newmove) _DEBUG("state",state) effect1 = i[7] _DEBUG("effect1",effect1) # effect1 = effect1[1] # print "effect2",effect2 effect = effect1[1:] _DEBUG("effect3",effect) for temp in effect: print "temp",temp _DEBUG("debugtemp",temp,"effect",effect) _DEBUG("effect",temp) # temp = m[0] _DEBUG("temp[0]",temp[0]) if temp[0] <> "not": _DEBUG("again") _DEBUG("temp",temp) newtemp = instantiate(temp,newmove,param) _DEBUG("newtemp",newtemp) state.insert(1,newtemp) _DEBUG("newstate1",state) else: _DEBUG("hoowa",temp[1]) _DEBUG("newmove",newmove) #! print "newmatches",newmatches newtemp = instantiate(temp[1],newmove,param) for n in state: _DEBUG("temp1",temp[1]) _DEBUG("newtemp2",newtemp) _DEBUG("state",state) _DEBUG("newtemp",newtemp) _DEBUG("n",n) if newtemp == n: _DEBUG("wahoo",newtemp) state.remove(n) _DEBUG("newstate2",state) _DEBUG("newstate",state) return state
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??")
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 addinit_typing1(mylist, counter_type, new_init, more_list, original_objects, typing, max_num, init, predicates, objects): print "mylsit", mylist print "counter_type", counter_type print "new_init", new_init print "more_list", more_list print "original_objects", original_objects print "typing", typing print "max_num", max_num countlist1 = [] #_PRINT("mylist",mylist) _DEBUG("testing") # new_count = len(counter_type) #! + 1 # print "new_vampire", new_count # new_list = ["count1a1a", mylist[-1], counter_type[0], new_count] # print "chocula",new_list print "G.predicate", G.predicate print "G.savepredicate", G.savepredicate print "G.save_objects", G.save_objects print "G.save_unary_predicates", G.save_unary_predicates ###add makecount for unary**1** ####must add in predicates from predicates list (holding ?h - hand ?c - container) (contains ?c - container ?b - beverage) (used ?c - container ?b - beverage) #(must have stored all predicates from initial state not just left and shot1) - so can get counts #why handempty seperate handempty ontable shot => holding shot => handempty ontable shot #(count hand enmpy shot) if counter_type == [] and G.save_unary_predicates <> []: countlist1, removallist = makeunarycounts(mylist[-1], G.save_unary_predicates, new_init, max_num, init, predicates, objects) countlist = makecounts(counter_type, mylist, []) #this is where count predicates are made # print "removallist",removallist if countlist == []: countlist = countlist1 elif countlist1 <> []: countlist.append(countlist1) print "countlist", countlist print "counter_type", counter_type, "G.save_unary_predicates", G.save_unary_predicates, "G.multiple_reforms", G.multiple_reforms, # if debug == True: #_PRINT("countlist",countlist) # if counter_type == [] and G.multiple_reforms <> []: #for barman but not nomystery 2/26/2014 if counter_type == [] and G.save_unary_predicates <> []: new_init = remove_unary(new_init, removallist) #****fix removal here**** if G.max_num < max_num: G.max_num = max_num print "remove", new_init new_init.extend(countlist) print "aaded", new_init l = range(0, max_num) _DEBUG("set max") # max_num = len(counter_type)+2 #why + 2 ???? myvar = mylist[-1] # myletter = myvar[0] myletter = myvar[:2] print "myvar??", myvar print "myletter", myletter print "zzmore_list", more_list mymore = "more" + myletter #changed back I hope 1/12/14 for i in l: if not i in more_list: print "KKKKK", mylist[-1] if G.multiple_reforms: new_temp = [mymore, i, i + 1] #1/8/2014 change more_list.insert(0, i) new_init.append(new_temp) else: new_temp = ["more", i, i + 1] more_list.insert(0, i) new_init.append(new_temp) # print "new_init",new_init # myextralist = return_places(counts[0],counter_type[0],original_list,typing) #%%%%put this back to handle ""ins"" (must fix changeaction too) #mytype = find_type(counts[0],new_init) #%%%problem with typing # if debug == True: # print "mytype", mytype # mylist = makelist(mytype,counts[0],new_init) # if debug == True: # print "mylist", mylist # if debug == True: # print "NEW_INIT",new_init print "new_initkoo", new_init _DEBUG("chocchocmylist", mylist, "counter_type", counter_type) print "temper2mylist", mylist, counter_type, mylist[ -1], new_init, original_objects, typing temper = addzero_typing(mylist, counter_type, mylist[-1], new_init, original_objects, typing) #need to fix more to moreh*** print "temper", temper _DEBUG("DDDDONE", temper) return temper #else: _DEBUG("MUST EXTEND")
def repairmove(move,i,lists): #! repairs the move call to the correct form for the original representation _DEBUG("debugmove1",move,"i",i) _DEBUG("move",move) _DEBUG("i",i) print "move",move print "i",i print "lists",lists new_move = [move[0]] # new_move.insert(1,i) _DEBUG("new_move",new_move) _DEBUG("G.storage3",G.storage3) new_move = findparam(new_move,move) print "new_move1",new_move _DEBUG("new_move",new_move) _DEBUG("i",i,"lists",lists) print "i",i,"lists",lists new_move = replaceinmove(new_move,i,lists) print "new_move2",new_move # new_move.extend(move[4:6]) _DEBUG("new_move2",new_move) return new_move
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 find_type(counter, new_init): _DEBUG("ft_counter", counter) _DEBUG("new_init", new_init) if new_init == []: _DEBUG("AAA") return "NONE" elif len(new_init[0]) == 1: _DEBUG("BBB") return find_type(counter, new_init[1:]) elif len(new_init[0]) == 2: _DEBUG("CCC") temp = new_init[0] _DEBUG("temp", temp) _DEBUG("temp1", temp[1]) if temp[1] == counter: return temp[0] else: _DEBUG("DDD") return find_type(counter, new_init[1:]) else: _DEBUG("EEE") _DEBUG("len", len(new_init[0])) _DEBUG("new", new_init[0]) return find_type(counter, new_init[1:])
def instantiate(term,move,param): #! two problems (road ?l ?l) returns (road city..) and needs to backtrack...need to move test inside of instantiate!!!!! #! not sure this only uses elements in the same list "[ball1 balls]" should check this ...will make it faster # if debug == True: print "ttterm1",term print "move",move print "param",param _DEBUG("seven") _DEBUG("term",term) _DEBUG("move",move) _DEBUG("param",param) # print "matches", matches newterm=[] for i in term: print "iii",i # if debug == True: _DEBUG("i",i) if len(str(i)) > 1 and i[0] == "?": #! for j in matches: #!change this part to use param #! print "j",j #! print "j1",j[1] #! print "i0",i[0] #! if j[1] == i: #! print "almost", j #! print "move",move #! if j[0] in move: #! print "gothere",j #! newterm.insert(len(newterm),j[0]) l = range(0,(len(param))) #-1 or not??? # if debug == True: _DEBUG("l", l) for j in l: print "jjj",j,param[j] # if debug == True: _DEBUG("i",i,"param[j]",param[j]) if i == param[j]: newterm.insert(len(newterm),move[j+1]) _DEBUG("pazazz",newterm) # return newterm else: newterm.insert(len(newterm),i) _DEBUG("newterm",newterm) print "ttterm2",newterm return newterm