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 fn(evaluations, results, constraints):
     if constraints is None:
         return plan_streams(evaluations,
                             goal_exp,
                             domain,
                             results,
                             negative,
                             max_cost=max_cost,
                             **kwargs)
     #print(*relaxed_stream_plan(evaluations, goal_exp, domain, results, negative,
     #                               max_cost=max_cost, **kwargs))
     #constraints.dump()
     domain2 = deepcopy(domain)
     evaluations2 = copy(evaluations)
     goal_exp2 = add_plan_constraints(constraints,
                                      domain2,
                                      evaluations2,
                                      goal_exp,
                                      internal=True)
     max_cost2 = max_cost if constraints is None else min(
         max_cost, constraints.max_cost)
     return plan_streams(evaluations2,
                         goal_exp2,
                         domain2,
                         results,
                         negative,
                         max_cost=max_cost2,
                         **kwargs)
Exemple #3
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
def parse_problem(problem, stream_info={}, constraints=None, unit_costs=False, unit_efforts=False):
    # TODO: just return the problem if already written programmatically
    domain_pddl, constant_map, stream_pddl, stream_map, init, goal = problem
    domain = parse_domain(domain_pddl)
    if len(domain.types) != 1:
        raise NotImplementedError('Types are not currently supported')
    set_unit_costs(domain, unit_costs)
    obj_from_constant = parse_constants(domain, constant_map)
    streams = parse_stream_pddl(stream_pddl, stream_map, stream_info=stream_info, 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)
    compile_fluent_streams(domain, streams)
    enforce_simultaneous(domain, streams)
    return evaluations, goal_exp, domain, streams