def dump(task, destination=sys.stdout): (goal_relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) (groups, mutex_groups, tk) = fact_groups.compute_groups(task, atoms, reachable_action_params, partial_encoding=True) print("(:atoms", file=destination) for atom in atoms: print_atom(atom, destination=destination, indent=2) print(" )", file=destination) print("(:actions", file=destination) for act in actions: print(" " + act.name, file=destination) print(" )", file=destination) print("(:mutex-groups", file=destination) for group in mutex_groups: if len(group) > 1: print_mutex_group(group, destination=destination, indent=2) print(" )", file=destination)
def main() : task = pddl.open() relaxed_solvable, atoms, actions, axioms = instantiate.explore(task) #for action in actions : # action.dump() not_trivial_axioms = [] trivial_axioms = {} for axiom in axioms : if len(axiom.condition) > 1 : not_trivial_axioms.append( axiom ) continue if not isinstance( axiom.effect, pddl.conditions.Literal ) : not_trivial_axioms.append( axiom ) continue if isinstance( axiom.effect, pddl.conditions.NegatedAtom ) : not_trivial_axioms.append( axiom ) continue try : trivial_axioms[ axiom.effect ].append( axiom.condition[0] ) except KeyError : trivial_axioms[ axiom.effect ] = [ axiom.condition[0] ] print >> sys.stdout, "Non-trivial axioms:", len(not_trivial_axioms) print >> sys.stdout, "Trivial axioms:", len(trivial_axioms.keys()) if not relaxed_solvable : print >> sys.stdout, "Problem is unsolvable!" sys.exit(1) task_to_prop_strips_domain( task, atoms, actions, not_trivial_axioms ) task_to_prop_strips_problem( task, atoms, trivial_axioms )
def pddl_to_sas(task): with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, reachable_action_params, partial_encoding=USE_PARTIAL_ENCODING) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=USE_PARTIAL_ENCODING) with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if ADD_IMPLIED_PRECONDITIONS: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) with timers.timing("Translating task", block=True): sas_task = translate_task( strips_to_sas, ranges, translation_key, mutex_dict, mutex_ranges, mutex_key, task.init, goal_list, actions, axioms, task.use_min_cost_metric, implied_facts) print("%d implied effects removed" % removed_implied_effect_counter) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) if DETECT_UNREACHABLE: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") return sas_task
def instantiate_task(task, check_infeasible=True, use_fd=FD_INSTANTIATE, **kwargs): start_time = time() print() normalize.normalize(task) if use_fd: relaxed_reachable, atoms, actions, axioms, reachable_action_params = instantiate.explore( task) else: relaxed_reachable, atoms, actions, axioms = instantiate_domain( task, **kwargs) reachable_action_params = get_reachable_action_params(actions) #for atom in sorted(filter(lambda a: isinstance(a, pddl.Literal), set(task.init) | set(atoms)), # key=lambda a: a.predicate): # print(fact_from_fd(atom)) #print(axioms) #for i, action in enumerate(sorted(actions, key=lambda a: a.name)): # print(i, transform_action_args(pddl_from_instance(action), obj_from_pddl)) print('Infeasible:', not relaxed_reachable) print('Instantiation time:', elapsed_time(start_time)) if check_infeasible and not relaxed_reachable: return None goal_list = instantiate_goal(task.goal) return InstantiatedTask(task, atoms, actions, axioms, reachable_action_params, goal_list)
def get_task_actions(domain, problem, agent_list): IGNORE_ACTIONS = set() REPLACEABLE_ACTIONS = [] import re action_args = re.compile('\((.*)\)') #private_pred_list = list(map(str.strip,private_preds)) task = pddl_parser.open(task_filename=problem, domain_filename=domain) normalize.normalize(task) (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) for _action in actions: IGNORE_FLAG = True REPLACEABLE_ACTIONS_FLAG = True for cond, eff_pred in _action.add_effects: # if eff_pred.literal.predicate not in private_pred_list: if len(set(eff_pred.args) & set(agent_list)) == 0: IGNORE_FLAG = False for cond, eff_pred in _action.del_effects: # if eff_pred.literal.predicate not in private_pred_list: if len(set(eff_pred.args) & set(agent_list)) == 0: IGNORE_FLAG = False if IGNORE_FLAG: act_name = action_args.findall(_action.name)[0].split()[0] IGNORE_ACTIONS.add(act_name) return task, actions, list( IGNORE_ACTIONS ), relaxed_reachable, atoms, axioms, reachable_action_params
def pddl_to_sas(task): with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, reachable_action_params) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=options.use_partial_encoding) with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if options.add_implied_preconditions: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) with timers.timing("Translating task", block=True): sas_task = translate_task( strips_to_sas, ranges, translation_key, mutex_dict, mutex_ranges, mutex_key, task.init, goal_list, actions, axioms, task.use_min_cost_metric, implied_facts) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) if options.filter_unreachable_facts: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") except simplify.TriviallySolvable: return solvable_sas_task("Simplified to empty goal") return sas_task
def explore_silently(task): # Call instantiate.explore, swallowing its output. real_stdout = sys.stdout sys.stdout = io.StringIO() result = instantiate.explore(task) sys.stdout = real_stdout return result
def explore_silently(task): # Call instatiate.explore, swallowing its output. real_stdout = sys.stdout sys.stdout = StringIO.StringIO() result = instantiate.explore(task) sys.stdout = real_stdout return result
def pddl_to_sas(task): with timers.timing("Instantiating", block=True): relaxed_reachable, atoms, actions, axioms = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, partial_encoding=USE_PARTIAL_ENCODING) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=USE_PARTIAL_ENCODING) with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if ADD_IMPLIED_PRECONDITIONS: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Translating task", block=True): sas_task = translate_task( strips_to_sas, ranges, mutex_dict, mutex_ranges, task.init, goal_list, actions, axioms, task.use_min_cost_metric, implied_facts) print "%d implied effects removed" % removed_implied_effect_counter print "%d effect conditions simplified" % simplified_effect_condition_counter print "%d implied preconditions added" % added_implied_precondition_counter with timers.timing("Building mutex information"): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) if DETECT_UNREACHABLE: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions( sas_task, mutex_key, translation_key) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") with timers.timing("Writing translation key"): write_translation_key(translation_key) with timers.timing("Writing mutex key"): write_mutex_key(mutex_key) return sas_task
def instantiate_task(task): # TODO: my own action instantiation normalize.normalize(task) relaxed_reachable, atoms, actions, axioms, reachable_action_params = instantiate.explore(task) if not relaxed_reachable: return None goal_list = instantiate_goal(task.goal) return InstantiatedTask(task, atoms, actions, axioms, reachable_action_params, goal_list)
def pddl_to_sas(task): print "Instantiating..." (relaxed_reachable, atoms, num_fluents, actions, durative_actions, axioms, num_axioms, reachable_action_params) = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") num_axioms = list(num_axioms) num_axioms.sort(lambda x, y: cmp(x.name, y.name)) # HACK! Goals should be treated differently (see TODO file). # Update: This is now done during normalization. The assertions # are only left here to be on the safe side. Can be removed eventually if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, reachable_action_params, return_mutex_groups=WRITE_ALL_MUTEXES, partial_encoding=USE_PARTIAL_ENCODING, safe=USE_SAFE_INVARIANT_SYNTHESIS) num_axioms_by_layer, max_num_layer, num_axiom_map, const_num_axioms = \ numeric_axiom_rules.handle_axioms(num_axioms) print "Building STRIPS to SAS dictionary..." ranges, strips_to_sas = strips_to_sas_dictionary(groups, num_axioms, num_axiom_map, num_fluents) print "Translating task..." assert not actions, "There shouldn't be any actions - just temporal actions" sas_task = translate_task(strips_to_sas, ranges, task.init, goal_list, actions, durative_actions, axioms, num_axioms, num_axioms_by_layer, max_num_layer, num_axiom_map, const_num_axioms) simplify.constrain_end_effect_conditions(sas_task) mutex_key = build_mutex_key(strips_to_sas, mutex_groups) # try: # simplify.filter_unreachable_propositions( # sas_task, mutex_key, translation_key) # except simplify.Impossible: # return unsolvable_sas_task("Simplified to trivially false goal") write_translation_key(strips_to_sas) if WRITE_ALL_MUTEXES: write_mutex_key(mutex_key) return sas_task
def build_relaxed_task(task): relaxed_reachable, fluent_atoms, actions, axioms, _ = instantiate.explore(task) if not relaxed_reachable: raise SystemExit("goal is not relaxed reachable") if axioms: raise SystemExit("axioms not supported") symtable = dict((atom, RelaxedAtom(str(atom))) for atom in fluent_atoms) relaxed_atoms = sorted(symtable.values()) relaxed_actions = [build_relaxed_action(action, symtable) for action in actions] relaxed_init = collect_init_facts(task.init, symtable) relaxed_goal = collect_goal_facts(task.goal, symtable) return RelaxedTask(relaxed_atoms, relaxed_init, relaxed_goal, relaxed_actions)
def pddl_to_sas(task): print "Instantiating..." (relaxed_reachable, atoms, num_fluents, actions, durative_actions, axioms, num_axioms) = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") num_axioms = list(num_axioms) num_axioms.sort(lambda x,y: cmp(x.name,y.name)) # HACK! Goals should be treated differently (see TODO file). # Update: This is now done during normalization. The assertions # are only left here to be on the safe side. Can be removed eventually if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, return_mutex_groups=WRITE_ALL_MUTEXES, partial_encoding=USE_PARTIAL_ENCODING) num_axioms_by_layer, max_num_layer, num_axiom_map, const_num_axioms = \ numeric_axiom_rules.handle_axioms(num_axioms) print "Building STRIPS to SAS dictionary..." ranges, strips_to_sas = strips_to_sas_dictionary(groups, num_axioms, num_axiom_map, num_fluents) print "Translating task..." sas_task = translate_task(strips_to_sas, ranges, task.init, goal_list, actions, durative_actions, axioms, num_axioms, num_axioms_by_layer, max_num_layer, num_axiom_map, const_num_axioms) simplify.constrain_end_effect_conditions(sas_task) mutex_key = build_mutex_key(strips_to_sas, mutex_groups) # try: # simplify.filter_unreachable_propositions( # sas_task, mutex_key, translation_key) # except simplify.Impossible: # return unsolvable_sas_task("Simplified to trivially false goal") write_translation_key(strips_to_sas) if WRITE_ALL_MUTEXES: write_mutex_key(mutex_key) return sas_task
def instantiate_task(task): normalize.normalize(task) relaxed_reachable, atoms, actions, axioms, reachable_action_params = instantiate.explore(task) if not relaxed_reachable: return None # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) return InstantiatedTask(task, atoms, actions, axioms, reachable_action_params, goal_list)
def instantiate_task(task, check_infeasible=True, **kwargs): start_time = time() print() normalize.normalize(task) if FD_INSTANTIATE: relaxed_reachable, atoms, actions, axioms, reachable_action_params = instantiate.explore(task) else: relaxed_reachable, atoms, actions, axioms = instantiate_domain(task, **kwargs) reachable_action_params = get_reachable_action_params(actions) print('Infeasible:', not relaxed_reachable) print('Instantiation time:', elapsed_time(start_time)) if check_infeasible and not relaxed_reachable: return None goal_list = instantiate_goal(task.goal) return InstantiatedTask(task, atoms, actions, axioms, reachable_action_params, goal_list)
def build_relaxed_task(task): relaxed_reachable, fluent_atoms, actions, axioms = instantiate.explore( task) if not relaxed_reachable: raise SystemExit("goal is not relaxed reachable") if axioms: raise SystemExit("axioms not supported") symtable = dict((atom, RelaxedAtom(str(atom))) for atom in fluent_atoms) relaxed_atoms = sorted(symtable.values()) relaxed_actions = [ build_relaxed_action(action, symtable) for action in actions ] relaxed_init = collect_init_facts(task.init, symtable) relaxed_goal = collect_goal_facts(task.goal, symtable) return RelaxedTask(relaxed_atoms, relaxed_init, relaxed_goal, relaxed_actions)
def instantiate_dump(task): with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) print("goal relaxed reachable: %s" % relaxed_reachable) print("%d atoms:" % len(atoms)) for atom in atoms: print(" ", atom) print() print("%d actions:" % len(actions)) for action in actions: action.dump() print() print("%d axioms:" % len(axioms)) for axiom in axioms: axiom.dump() print() print(reachable_action_params)
def compile(task): with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) # Transform logical terms of all cost functions into arithmetic terms. for a in actions: if isinstance(a.cost, pddl_parser.CostNode): a.cost.transform_logic() # writing value tuples to atoms predicate_dict = dict((p.name, p ) for p in task.predicates) for a in atoms: p = predicate_dict.get(a.predicate) if p and len(p.value_mapping) > 0: a.value = p.value_mapping.get(a.args) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key, atom_groups = fact_groups.compute_groups( task, atoms, reachable_action_params) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=options.use_partial_encoding) with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) compiler = EVMDDActionCompiler() actions = compiler.evmdd_action_compilation(actions) pddl_writer = SdacPDDLWriter(compiler._fact_name_dict) pddl_writer.write_pddl_files(options.domain, options.task, actions) print("done!")
def pddl_to_sas(task): print "Instantiating..." relaxed_reachable, atoms, actions, axioms = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently (see TODO file). if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, return_mutex_groups=WRITE_ALL_MUTEXES, partial_encoding=USE_PARTIAL_ENCODING) print "Building STRIPS to SAS dictionary..." ranges, strips_to_sas = strips_to_sas_dictionary(groups) print "Translating task..." sas_task = translate_task(strips_to_sas, ranges, task.init, goal_list, actions, axioms, task.use_min_cost_metric) mutex_key = build_mutex_key(strips_to_sas, mutex_groups) try: simplify.filter_unreachable_propositions(sas_task, mutex_key, translation_key) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") write_translation_key(translation_key) if WRITE_ALL_MUTEXES: write_mutex_key(mutex_key) return sas_task
def pddl_to_sas(task): print("Instantiating...") relaxed_reachable, atoms, actions, axioms, _ = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently (see TODO file). if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) # switched off invariant syntheses -> one group for each fluent fact groups = [[fact] for fact in atoms] mutex_groups = [] translation_key = [[str(fact),str(fact.negate())] for group in groups for fact in group] print("Building STRIPS to SAS dictionary...") ranges, strips_to_sas = strips_to_sas_dictionary(groups) print("Building mutex information...") mutex_key = build_mutex_key(strips_to_sas, mutex_groups) print("Translating task...") sas_task = translate_task(strips_to_sas, ranges, translation_key, mutex_key, task.init, goal_list, actions, axioms, task.use_min_cost_metric) try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") return sas_task
def pddl_to_sas(task): print "Instantiating..." relaxed_reachable, atoms, actions, axioms = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently (see TODO file). if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) # groups, mutex_groups, translation_key = fact_groups.compute_groups( # task, atoms, return_mutex_groups=WRITE_ALL_MUTEXES, # partial_encoding=USE_PARTIAL_ENCODING) # switched off invariant syntheses -> one group for each fluent fact groups = [[fact] for fact in atoms] translation_key = [[str(fact), str(fact.negate())] for group in groups for fact in group] print "Building STRIPS to SAS dictionary..." ranges, strips_to_sas = strips_to_sas_dictionary(groups) print "Translating task..." sas_task = translate_task(strips_to_sas, ranges, task.init, goal_list, actions, axioms) try: simplify.filter_unreachable_propositions(sas_task, [], translation_key) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") write_translation_key(translation_key) return sas_task
def pddl_to_sas(task): print "Instantiating..." relaxed_reachable, atoms, actions, axioms = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently (see TODO file). if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) # groups, mutex_groups, translation_key = fact_groups.compute_groups( # task, atoms, return_mutex_groups=WRITE_ALL_MUTEXES, # partial_encoding=USE_PARTIAL_ENCODING) # switched off invariant syntheses -> one group for each fluent fact groups = [[fact] for fact in atoms] translation_key = [[str(fact),str(fact.negate())] for group in groups for fact in group] print "Building STRIPS to SAS dictionary..." ranges, strips_to_sas = strips_to_sas_dictionary(groups) print "Translating task..." sas_task = translate_task(strips_to_sas, ranges, task.init, goal_list, actions, axioms) try: simplify.filter_unreachable_propositions( sas_task, [], translation_key) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") write_translation_key(translation_key) return sas_task
def pddl_to_sas(task): print("Instantiating...") relaxed_reachable, atoms, actions, axioms, _ = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently (see TODO file). if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) # switched off invariant syntheses -> one group for each fluent fact groups = [[fact] for fact in atoms] mutex_groups = [] translation_key = [[str(fact), str(fact.negate())] for group in groups for fact in group] print("Building STRIPS to SAS dictionary...") ranges, strips_to_sas = strips_to_sas_dictionary(groups) print("Building mutex information...") mutex_key = build_mutex_key(strips_to_sas, mutex_groups) print("Translating task...") sas_task = translate_task(strips_to_sas, ranges, translation_key, mutex_key, task.init, goal_list, actions, axioms, task.use_min_cost_metric) try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") return sas_task
def pddl_to_sas(task): print "Instantiating..." relaxed_reachable, atoms, actions, axioms = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently (see TODO file). if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, return_mutex_groups=WRITE_ALL_MUTEXES, partial_encoding=USE_PARTIAL_ENCODING) print "Building STRIPS to SAS dictionary..." ranges, strips_to_sas = strips_to_sas_dictionary(groups) print "Translating task..." sas_task = translate_task(strips_to_sas, ranges, task.init, goal_list, actions, axioms, task.use_min_cost_metric) mutex_key = build_mutex_key(strips_to_sas, mutex_groups) try: simplify.filter_unreachable_propositions( sas_task, mutex_key, translation_key) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") write_translation_key(translation_key) if WRITE_ALL_MUTEXES: write_mutex_key(mutex_key) return sas_task
def pddl_to_sas(task): with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, num_fluents, actions, axioms, num_axioms, init_constant_predicates, init_constant_numerics, reachable_action_params) = instantiate.explore(task) if DEBUG: print("Task converted to SAS.") # task.function_administrator.dump() if DEBUG: print("Relaxed_reachable: %s" % relaxed_reachable) if DEBUG: print("List of %d Atoms:" % len(atoms)) # for atom in atoms: # atom.dump() if DEBUG: print("List of %d numeric Fluents:" % len(num_fluents)) # for fluent in num_fluents: # fluent.dump() if len(num_fluents) == 0: assert False if DEBUG: print("List of %d Actions:" % len(actions)) # for action in actions: # print(action.name) if DEBUG: print("List of %d propositional Axioms:" % len(axioms)) # if len(axioms) > 0: # axioms[0].dump() # print("layer=%s"%axioms[0].__class__ ) # for axiom in axioms: # axiom.dump() if DEBUG: print("List of %d numeric Axioms:" % len(num_axioms)) # for numax in num_axioms: # numax.dump() if DEBUG: print("List of %d constant predicates from initial state" % len(init_constant_predicates)) # for icp in init_constant_predicates: # icp.dump() if DEBUG: print("List of %d constant numeric predicates from initial state" % len(init_constant_numerics)) # for icn in init_constant_numerics: # icn.dump() if DEBUG: print("List of %d reachable Action Parameters:" % len(reachable_action_params)) # for rap in reachable_action_params: # rap.dump() if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) assert isinstance(task.global_constraint, pddl.Literal) # if DEBUG: print("Global constraint Literal is ", task.global_constraint) with timers.timing("Computing fact groups", block=True): # groups: the ground facts are grouped in order to create multi valued variables # mutex_groups: includes all mutex groups, so a fact can appear in multiple groups # translation key: the names of the grounded facts of the MVV determined in groups, including "NegatedAtom" for binary and "none of those" for multi valued variables groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, reachable_action_params) # print ("Fact groups (%d) computed %s" % (len(groups),[len(group) for group in groups])) # print ("Full mutex groups (%d) containing %s:" % (len(mutex_groups),[len(group) for group in mutex_groups])) with timers.timing("Handling numeric axioms"): num_axioms_by_layer, max_num_layer, num_axiom_map, const_num_axioms = \ numeric_axiom_rules.handle_axioms(num_axioms) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas, num_count, numeric_strips_to_sas = strips_to_sas_dictionary( groups, num_axioms, num_axiom_map, num_fluents, assert_partial=options.use_partial_encoding) # if DEBUG: # print("Strips to sas dictionary (%s entries)" % len(strips_to_sas)) # for entry in sorted(strips_to_sas.items(), key=lambda x:x[1]): # sort by value # print("%s -> %s" % entry) # print(ranges) # print("Numeric Strips to sas dictionary (%s entries)" % len(numeric_strips_to_sas)) # for entry in numeric_strips_to_sas: # print("%s -> %s" % (entry, numeric_strips_to_sas[entry])) # print ("pddl2sas Zwischendebug: metric = ", task.metric) # assert task.metric[1] in numeric_strips_to_sas with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict, _, _ = strips_to_sas_dictionary( mutex_groups, num_axioms, num_axiom_map, num_fluents, assert_partial=False, include_numeric=False) if options.add_implied_preconditions: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) with timers.timing("Translating task", block=True): sas_task = translate_task( strips_to_sas, ranges, translation_key, numeric_strips_to_sas, num_count, mutex_dict, mutex_ranges, mutex_key, task.init, task.num_init, goal_list, task.global_constraint, actions, axioms, num_axioms, num_axioms_by_layer, num_axiom_map, const_num_axioms, task.metric, implied_facts, init_constant_predicates, init_constant_numerics) # print("len(variables.valuenames) = %s" % len(sas_task.variables.value_names)) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) # print("created sas_task") # sas_task.dump() if options.filter_unreachable_facts: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task( "Simplified to trivially false goal") except simplify.TriviallySolvable: return solvable_sas_task("Simplified to empty goal") # print("translate pddl to sas returns task") return sas_task
def pddl_to_sas(task): with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) # Transform logical terms of all cost functions into arithmetic terms. for a in actions: if isinstance(a.cost, pddl_parser.CostNode): a.cost.transform_logic() # writing value tuples to atoms predicate_dict = dict((p.name, p ) for p in task.predicates) for a in atoms: p = predicate_dict.get(a.predicate) if p and len(p.value_mapping) > 0: a.value = p.value_mapping.get(a.args) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key, atom_groups = fact_groups.compute_groups( task, atoms, reachable_action_params) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=options.use_partial_encoding) with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if options.add_implied_preconditions: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) if options.exp: actions = pddl_parser.transform_exp_actions(actions, mutex_groups) compiler = EVMDDActionCompiler() actions = compiler.evmdd_action_compilation(actions) pddl_writer = SdacPDDLWriter(compiler._fact_name_dict) pddl_writer.write_pddl_files(options.domain, options.task, actions) print("done!") exit(0) task.inst_actions = actions with timers.timing("Translating task", block=True): sas_task = translate_task( strips_to_sas, ranges, translation_key, mutex_dict, mutex_ranges, mutex_key, task.init, goal_list, actions, axioms, task.use_min_cost_metric, implied_facts, atom_groups) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) if options.filter_unreachable_facts: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") except simplify.TriviallySolvable: return solvable_sas_task("Simplified to empty goal") atom_dict = dict((str(a), a) for a in atoms) new_atom_groups = [] for i in range(0, len(sas_task.variables.atom_groups)): group_str = [str(fact) for fact in sas_task.variables.atom_groups[i]] for j in range(0, len(sas_task.variables.value_names)): if group_str == sas_task.variables.value_names[j]: new_atom_groups.append(sas_task.variables.atom_groups[i]) break sas_task.variables.atom_groups = new_atom_groups for i in range(0, len(sas_task.variables.atom_groups)): group_str = [str(fact) for fact in sas_task.variables.atom_groups[i]] assert(group_str == sas_task.variables.value_names[i]) # Transform atoms of all cost functions into sas notation. # Simplify cost function for op in sas_task.operators: if isinstance(op.cost, pddl_parser.CostNode): op.cost.to_sas(sas_task.variables.atom_groups, atom_dict, sas_task.variables.deleted_true_variables) op.cost = op.cost.get_simplified_function() return sas_task
def pddl_to_sas(task): with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, reachable_action_params) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=options.use_partial_encoding) with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if options.add_implied_preconditions: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): if options.use_partial_encoding: mutex_key = build_mutex_key(strips_to_sas, mutex_groups) else: # With our current representation, emitting complete mutex # information for the full encoding can incur an # unacceptable (quadratic) blowup in the task representation # size. See issue771 for details. print( "using full encoding: between-variable mutex information skipped." ) mutex_key = [] with timers.timing("Translating task", block=True): sas_task = translate_task(strips_to_sas, ranges, translation_key, mutex_dict, mutex_ranges, mutex_key, task.init, goal_list, actions, axioms, task.use_min_cost_metric, implied_facts) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) if options.filter_unreachable_facts: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task( "Simplified to trivially false goal") except simplify.TriviallySolvable: return solvable_sas_task("Simplified to empty goal") if options.reorder_variables or options.filter_unimportant_vars: with timers.timing("Reordering and filtering variables", block=True): variable_order.find_and_apply_variable_order( sas_task, options.reorder_variables, options.filter_unimportant_vars) return sas_task
output_dir = 'FOND/SS_BW/A1/' #output_dir = 'FOND/Perestroika/A1/' #output_dir = 'FOND/AUV/A1/' if __name__ == '__main__': task = pddl_parser.open(sys.argv[1], sys.argv[2]) actions = task.actions events = task.events os.makedirs(output_dir, exist_ok=True) action_names = list(map(lambda a: a.name, task.actions)) event_names = list(map(lambda e: e.name, task.events)) task.actions = actions + events inst = instantiate.explore(task) inst_actions = [ a for a in inst[2] if a.name.split(' ')[0][1:] in action_names ] inst_events = [ a for a in inst[2] if a.name.split(' ')[0][1:] in event_names ] task.actions = actions inst_atoms = inst[1] ground_actions = list(map(transform_action, inst_actions)) ground_events = list(map(transform_action, inst_events)) ground_atoms = list(map(atom_to_name, inst_atoms))
def pddl_to_sas(task): with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") goal_list = translate_to_list(task.goal) online_goals_list = [translate_to_list(subgoal) for subgoal in task.online_goals] online_goals_availability = task.online_goals_availability with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, reachable_action_params) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=options.use_partial_encoding) with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if options.add_implied_preconditions: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) with timers.timing("Translating task", block=True): sas_task = translate_task( strips_to_sas, ranges, translation_key, mutex_dict, mutex_ranges, mutex_key, task.init, goal_list, online_goals_list, online_goals_availability, actions, axioms, task.use_min_cost_metric, task.execution_time, implied_facts) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) if options.filter_unreachable_facts: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") except simplify.TriviallySolvable: return solvable_sas_task("Simplified to empty goal") if options.reorder_variables or options.filter_unimportant_vars: with timers.timing("Reordering and filtering variables", block=True): variable_order.find_and_apply_variable_order( sas_task, options.reorder_variables, options.filter_unimportant_vars) return sas_task
def transform_action(action): add_effects = set(map(lambda x: atom_to_name(x[1]), action.add_effects)) del_effects = set(map(lambda x: atom_to_name(x[1]), action.del_effects)) pre = set(map(atom_to_name, action.precondition)) return Action(action.name.replace(" ", "_"), pre, add_effects, del_effects, []) if __name__ == '__main__': task = pddl_parser.open(sys.argv[1], sys.argv[2]) actions = task.actions events = task.events inst = instantiate.explore(task) task.actions = events inst_ev = instantiate.explore(task) task.actions = actions inst_atoms = inst[1] inst_actions = inst[2] inst_events = inst_ev[2] ground_actions = list(map(transform_action, inst_actions)) ground_events = list(map(transform_action, inst_events)) ground_atoms = list(map(atom_to_name, inst_atoms)) for a in ground_actions: a.pre.add('(act-turn)')
def pddl_to_sas(task, agent_id, agent_url): comm = None if agent_id >= 0 and len(agent_url) > 1: comm = AgentComm(agent_id, agent_url) with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task, comm) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, reachable_action_params, partial_encoding=USE_PARTIAL_ENCODING, comm = comm) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=USE_PARTIAL_ENCODING) if comm is not None: # Each group contains either all public or all private values private_vars = [x[0].is_private for x in groups] else: private_vars = [None for _ in groups] with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if ADD_IMPLIED_PRECONDITIONS: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) with timers.timing("Translating task", block=True): sas_task = translate_task( strips_to_sas, ranges, translation_key, private_vars, mutex_dict, mutex_ranges, mutex_key, task.init, goal_list, actions, axioms, task.use_min_cost_metric, implied_facts, task.agents, comm) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) if comm is not None: comm.close() if DETECT_UNREACHABLE and comm is None: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") return sas_task
def pddl_to_sas(task, agent_id, agent_url): comm = None if agent_id >= 0 and len(agent_url) > 1: comm = AgentComm(agent_id, agent_url) with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task, comm) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, reachable_action_params, partial_encoding=USE_PARTIAL_ENCODING, comm=comm) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=USE_PARTIAL_ENCODING) if comm is not None: # Each group contains either all public or all private values private_vars = [x[0].is_private for x in groups] else: private_vars = [None for _ in groups] with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if ADD_IMPLIED_PRECONDITIONS: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) with timers.timing("Translating task", block=True): sas_task = translate_task(strips_to_sas, ranges, translation_key, private_vars, mutex_dict, mutex_ranges, mutex_key, task.init, goal_list, actions, axioms, task.use_min_cost_metric, implied_facts, task.agents, comm) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) if comm is not None: comm.close() if DETECT_UNREACHABLE and comm is None: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task( "Simplified to trivially false goal") return sas_task
def pddl_to_sas(task): # for partial observability assume that unknown facts # are true initially (to use it in the reachability analysis) mod_task = deepcopy(task) mod_task.init = mod_task.init + mod_task.init_unknown with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, observation_actions, axioms, reachable_action_params) = instantiate.explore(mod_task) if not relaxed_reachable: # POND we return no unsolvable task return # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key = fact_groups.compute_groups( mod_task, atoms, reachable_action_params, partial_encoding=USE_PARTIAL_ENCODING) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=USE_PARTIAL_ENCODING) with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if ADD_IMPLIED_PRECONDITIONS: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) with timers.timing("Translating task", block=True): sas_task = translate_task( strips_to_sas, ranges, translation_key, mutex_dict, mutex_ranges, mutex_key, task.init, task.init_unknown, task.init_oneof, task.init_formula, goal_list, actions, observation_actions, axioms, task.use_min_cost_metric, implied_facts) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) if DETECT_UNREACHABLE: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task("Simplified to trivially false goal") return sas_task
def pddl_to_sas(task): with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key, inessentials = fact_groups.compute_groups( task, atoms, reachable_action_params, actions, axioms) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=options.use_partial_encoding) with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if options.add_implied_preconditions: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) with timers.timing("Translating task", block=True): sas_task = translate_task(strips_to_sas, ranges, translation_key, mutex_dict, mutex_ranges, mutex_key, task.init, goal_list, actions, axioms, task.use_min_cost_metric, implied_facts) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) if options.filter_unreachable_facts: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task( "Simplified to trivially false goal") except simplify.TriviallySolvable: return solvable_sas_task("Simplified to empty goal") reachable_inessentials = [] for i, values in enumerate(sas_task.variables.value_names): if len(values) > 2: continue pos, neg = values for mutex in inessentials: if (pos == str(mutex)): reachable_inessentials.append(mutex) if options.mark_inessential: sas_task.variables.axiom_layers[i] = -2 print("Translator essentials: {}".format( len(sas_task.variables.ranges) - len(reachable_inessentials))) print("Translator inessentials: {}".format(len(reachable_inessentials))) return sas_task
def pddl_to_sas(task): with timers.timing("Instantiating", block=True): (relaxed_reachable, atoms, actions, axioms, reachable_action_params) = instantiate.explore(task) #if not relaxed_reachable: #return unsolvable_sas_task("No relaxed solution") # ALBERTO POZANCO # Here we write the static predicates outfile = open('static-predicates.txt', 'w+') for a in task.init: if type(a) is pddl.Atom and str(a.predicate) != '=': if a not in atoms: data = '(' + a.key[0] for x in a.key[1]: data += ' ' + str(x) data += ')' outfile.write(data + '\n') outfile.close() # HACK! Goals should be treated differently. if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) with timers.timing("Computing fact groups", block=True): groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, reachable_action_params) with timers.timing("Building STRIPS to SAS dictionary"): ranges, strips_to_sas = strips_to_sas_dictionary( groups, assert_partial=options.use_partial_encoding) with timers.timing("Building dictionary for full mutex groups"): mutex_ranges, mutex_dict = strips_to_sas_dictionary( mutex_groups, assert_partial=False) if options.add_implied_preconditions: with timers.timing("Building implied facts dictionary..."): implied_facts = build_implied_facts(strips_to_sas, groups, mutex_groups) else: implied_facts = {} with timers.timing("Building mutex information", block=True): mutex_key = build_mutex_key(strips_to_sas, mutex_groups) with timers.timing("Translating task", block=True): sas_task = translate_task(strips_to_sas, ranges, translation_key, mutex_dict, mutex_ranges, mutex_key, task.init, goal_list, actions, axioms, task.use_min_cost_metric, implied_facts) print("%d effect conditions simplified" % simplified_effect_condition_counter) print("%d implied preconditions added" % added_implied_precondition_counter) if options.filter_unreachable_facts: with timers.timing("Detecting unreachable propositions", block=True): try: simplify.filter_unreachable_propositions(sas_task) except simplify.Impossible: return unsolvable_sas_task( "Simplified to trivially false goal") except simplify.TriviallySolvable: return solvable_sas_task("Simplified to empty goal") if options.reorder_variables or options.filter_unimportant_vars: with timers.timing("Reordering and filtering variables", block=True): variable_order.find_and_apply_variable_order( sas_task, options.reorder_variables, options.filter_unimportant_vars) return sas_task
def pddl_to_sas(task): print "Instantiating..." (relaxed_reachable, atoms, num_fluents, actions, durative_actions, axioms, num_axioms, modules, init_constant_predicates, init_constant_numerics, reachable_action_params) = instantiate.explore(task) # make order deterministic init_constant_predicates = list(init_constant_predicates) init_constant_predicates.sort(lambda x,y: cmp(str(x), str(y))) init_constant_numerics = list(init_constant_numerics) init_constant_numerics.sort(lambda x,y: cmp(str(x), str(y))) if not relaxed_reachable: return unsolvable_sas_task("No relaxed solution") axioms = list(axioms) axioms.sort(lambda x,y: cmp(str(x), str(y))) num_axioms = list(num_axioms) num_axioms.sort(lambda x,y: cmp(x.name,y.name)) # HACK! Goals should be treated differently. # Update: This is now done during normalization. The assertions # are only left here to be on the safe side. Can be removed eventually if isinstance(task.goal, pddl.Conjunction): goal_list = task.goal.parts else: goal_list = [task.goal] for item in goal_list: assert isinstance(item, pddl.Literal) groups, mutex_groups, translation_key = fact_groups.compute_groups( task, atoms, reachable_action_params, return_mutex_groups=WRITE_ALL_MUTEXES, partial_encoding=USE_PARTIAL_ENCODING, safe=USE_SAFE_INVARIANT_SYNTHESIS) num_axioms_by_layer, max_num_layer, num_axiom_map, const_num_axioms = \ numeric_axiom_rules.handle_axioms(num_axioms) print "Building STRIPS to SAS dictionary..." ranges, strips_to_sas, module_effects_to_sas, module_groundings_to_sas = strips_to_sas_dictionary(groups, num_axioms, num_axiom_map, num_fluents, modules) print "Translating task..." assert not actions, "There shouldn't be any actions - just temporal actions" sas_task = translate_task(strips_to_sas, module_effects_to_sas, module_groundings_to_sas, ranges, task.init, goal_list, actions, durative_actions, axioms, num_axioms, num_axioms_by_layer, max_num_layer, num_axiom_map, const_num_axioms, task.oplinit, task.objects, modules, task.module_inits, task.module_exits, task.subplan_generators, init_constant_predicates, init_constant_numerics) simplify.constrain_end_effect_conditions(sas_task) mutex_key = build_mutex_key(strips_to_sas, mutex_groups) # try: # simplify.filter_unreachable_propositions( # sas_task, mutex_key, translation_key) # except simplify.Impossible: # return unsolvable_sas_task("Simplified to trivially false goal") write_translation_key(strips_to_sas) if WRITE_ALL_MUTEXES: write_mutex_key(mutex_key) return sas_task