Exemple #1
0
def parse_problem(problem, stream_info={}, constraints=None, unit_costs=False, unit_efforts=False):
    # TODO: just return the problem if already written programmatically
    #reset_globals() # Prevents use of satisfaction.py
    domain_pddl, constant_map, stream_pddl, stream_map, init, goal = problem
    domain = parse_domain(domain_pddl)
    #domain = domain_pddl
    if not isinstance(domain, Domain):
        #assert isinstance(domain, str) # raw PDDL is returned
        obj_from_constant = {name: Object(value, name=name)
                             for name, value in constant_map.items()}
        streams = parse_stream_pddl(stream_pddl, stream_map, stream_info=stream_info,
                                    unit_costs=unit_costs, unit_efforts=unit_efforts)
        evaluations = evaluations_from_init(init)
        goal_exp = obj_from_value_expression(goal)
        return evaluations, goal_exp, domain, streams
    if len(domain.types) != 1:
        raise NotImplementedError('Types are not currently supported')
    if unit_costs:
        set_unit_costs(domain)
    obj_from_constant = parse_constants(domain, constant_map)
    streams = parse_stream_pddl(stream_pddl, stream_map, stream_info=stream_info,
                                unit_costs=unit_costs, unit_efforts=unit_efforts)
    check_problem(domain, streams, obj_from_constant)

    evaluations = evaluations_from_init(init)
    goal_exp = obj_from_value_expression(goal)
    #normalize_domain_goal(domain, goal_expression)
    goal_exp = add_plan_constraints(constraints, domain, evaluations, goal_exp)
    parse_goal(goal_exp, domain) # Just to check that it parses

    # TODO: refactor the following?
    compile_to_exogenous(evaluations, domain, streams)
    enforce_simultaneous(domain, streams)
    compile_fluent_streams(domain, streams)
    return evaluations, goal_exp, domain, streams
Exemple #2
0
def parse_problem(problem,
                  stream_info={},
                  constraints=None,
                  unit_costs=False,
                  unit_efforts=False):
    # TODO: just return the problem if already written programmatically
    #reset_globals() # Prevents use of satisfaction.py
    domain_pddl, constant_map, stream_pddl, stream_map, init, goal = problem

    domain = parse_domain(domain_pddl)  # TODO: normalize here
    #domain = domain_pddl
    if len(domain.types) != 1:
        raise NotImplementedError('Types are not currently supported')
    if unit_costs:
        set_unit_costs(domain)
    if not has_costs(domain):
        # TODO: set effort_weight to 1 if no costs
        print(
            'Warning! All actions have no cost. Recommend setting unit_costs=True'
        )
    obj_from_constant = parse_constants(
        domain, constant_map)  # Keep before parse_stream_pddl

    streams = parse_stream_pddl(stream_pddl,
                                stream_map,
                                stream_info=stream_info,
                                unit_costs=unit_costs,
                                unit_efforts=unit_efforts)
    check_problem(domain, streams, obj_from_constant)

    evaluations = evaluations_from_init(init)
    goal_exp = obj_from_value_expression(goal)

    if isinstance(domain, SimplifiedDomain):
        #assert isinstance(domain, str) # raw PDDL is returned
        _ = {
            name: Object(value, name=name)
            for name, value in constant_map.items()
        }
        return evaluations, goal_exp, domain, streams

    goal_exp = add_plan_constraints(constraints, domain, evaluations, goal_exp)
    parse_goal(goal_exp, domain)  # Just to check that it parses
    normalize_domain_goal(domain,
                          goal_exp)  # TODO: does not normalize goal_exp

    compile_to_exogenous(evaluations, domain, streams)
    return evaluations, goal_exp, domain, streams
Exemple #3
0
def create_simplified_problem(problem,
                              use_actions=False,
                              use_streams=False,
                              new_goal=None):
    # TODO: check whether goal is a conjunction
    domain_pddl, constant_map, stream_pddl, stream_map, init, goal_parts = problem
    if not use_streams:
        stream_pddl = None
    if new_goal is None:
        new_goal = goal_parts
    domain = parse_domain(
        domain_pddl
    )  # TODO: Constant map value @base not mentioned in domain :constants
    if not use_actions:
        domain.actions[:] = []  # No actions
    return PDDLProblem(domain, constant_map, stream_pddl, stream_map, init,
                       new_goal)