model_size += 1 filtered_known_dels = [eff for eff in action.effects if eff.literal.negated and eff.literal.predicate in dels_filter] for eff in filtered_known_dels: model_representation_fluent = "del_" + "_".join( [eff.literal.predicate] + [action.name] + ["var" + str(action_params.index(eff.literal.args[i]) + 1) for i in range(len(eff.literal.args))]) learning_task.init.append(pddl.conditions.Atom(model_representation_fluent, [])) model_size += 1 ### Write the learning task domain and problem to pddl fdomain = open("learning_domain.pddl", "w") fdomain.write(fdtask_to_pddl.format_domain(learning_task, domain_pddl)) fdomain.close() fdomain = open("learning_problem.pddl", "w") fdomain.write(fdtask_to_pddl.format_problem(learning_task, domain_pddl)) fdomain.close() ### Solvie the learning task # starting_horizon = str(2*TOTAL_STEPS + 3) validation_steps = max(states_seen-1, total_actions_seen)*2 + 1 if action_observability == 1 and state_observability == 0: validation_steps = states_seen + total_actions_seen starting_horizon = str(validation_steps + 2) if state_observability==1 or action_observability==1: ending_horizon = " -T " + starting_horizon
for j in range(0,len(plans[i])): name = "plan-"+plans[i][j].replace("(","").replace(")","").split(" ")[0] pars = ["i"+str(j+1)]+plans[i][j].replace("(","").replace(")","").split(" ")[1:] eff = eff + [pddl.effects.Effect([],pddl.conditions.Truth(),pddl.conditions.NegatedAtom(name,pars))] if i<len(plans)-1: for j in range(0,len(plans[i+1])): name = "plan-"+plans[i+1][j].replace("(","").replace(")","").split(" ")[0] pars = ["i"+str(j+1)]+plans[i+1][j].replace("(","").replace(")","").split(" ")[1:] eff = eff + [pddl.effects.Effect([],pddl.conditions.Truth(),pddl.conditions.Atom(name,pars))] fd_task.actions.append(pddl.actions.Action("test_"+str(i+1),[],0,pddl.conditions.Conjunction(pre),eff,0)) # Writing the compilation output domain and problem fdomain=open("aux_domain.pddl","w") fdomain.write(fdtask_to_pddl.format_domain(fd_task,fd_domain)) fdomain.close() fdomain=open("aux_problem.pddl","w") fdomain.write(fdtask_to_pddl.format_problem(fd_task,fd_domain)) fdomain.close() # Solving the compilation cmd = "rm " + config.OUTPUT_FILENAME + " planner_out.log;"+config.PLANNER_PATH+"/M aux_domain.pddl aux_problem.pddl -F "+str(len(plans)+sum([len(p) for p in plans]))+" "+config.PLANNER_PARAMS+" > planner_out.log" print("\n\nExecuting... " + cmd) os.system(cmd) # Reading the plan output by the compilation pres = [[] for _ in xrange(len(actions))] dels = [[] for _ in xrange(len(actions))]