def sas_from_instantiated(instantiated_task): import timers import fact_groups import options import simplify import variable_order from translate import translate_task, unsolvable_sas_task, strips_to_sas_dictionary, \ build_implied_facts, build_mutex_key, solvable_sas_task if not instantiated_task: return unsolvable_sas_task("No relaxed solution") task, atoms, actions, axioms, reachable_action_params, goal_list = instantiated_task 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) 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) translate.dump_statistics(sas_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) 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") 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): 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
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): 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