Exemplo n.º 1
0
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
Exemplo n.º 2
0
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 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