Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
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_lite(task, actions, relaxed_reachable, atoms, axioms,
                     reachable_action_params):
    # HACK! Goals should be treated differently.
    if isinstance(task.goal, pddl.Conjunction):
        goal_list = task.goal.parts
    else:
        goal_list = [task.goal]
    #print ("Goals "+str(goal_list))
    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)
    #print ("Goals init "+str(sas_task.init.values))
    #print ("Goals pair "+str(sas_task.goal.pairs))
    if options.filter_unreachable_facts:
        with timers.timing("Detecting unreachable propositions", block=True):
            try:
                simplify.filter_unreachable_propositions(sas_task)
            except simplify.Impossible:
                #print ("Goals IMPOSSIBLE")
                return unsolvable_sas_task(
                    "Simplified to trivially false goal")

    #print ("Goals pair "+str(sas_task.goal.pairs))
    return sas_task
Example #6
0
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
Example #7
0
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)

    # 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)

    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
Example #12
0
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
Example #13
0
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
Example #14
0
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
Example #15
0
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
Example #16
0
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
Example #17
0
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
Example #18
0
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)

    # 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
Example #20
0
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