Пример #1
0
def augment_evaluations(evaluations, future_map):
    for evaluation in list(filter(is_atom, evaluations)):
        name = evaluation.head.function
        if name in future_map:
            new_head = Head(future_map[name], evaluation.head.args)
            new_evaluation = Evaluation(new_head, evaluation.value)
            evaluations[new_evaluation] = None
Пример #2
0
def augment_evaluations(evaluations, future_map):
    for evaluation in list(filter(is_atom, evaluations)):
        name = evaluation.head.function
        if name in future_map:
            new_head = Head(future_map[name], evaluation.head.args)
            new_evaluation = Evaluation(new_head, evaluation.value)
            add_fact(evaluations, fact_from_evaluation(new_evaluation),
                     result=INTERNAL_EVALUATION, complexity=0)
Пример #3
0
def evaluation_from_fd(fd):
    if isinstance(fd, pddl.Literal):
        head = Head(fd.predicate, tuple(map(obj_from_pddl, fd.args)))
        return Evaluation(head, not fd.negated)
    if isinstance(fd, pddl.f_expression.Assign):
        raise NotImplementedError(fd)
        #head = Head(fd.fluent.symbol, tuple(map(obj_from_pddl, fd.fluent.args)))
        #return Evaluation(head, float(fd.expression.value) / get_cost_scale())  # Need to be careful due to rounding
    raise ValueError(fd)
Пример #4
0
def get_action_cost(domain, results_from_head, name, args):
    import pddl
    action = find_unique(lambda a: a.name == name, domain.actions)
    if action.cost is None:
        return 0.
    if isinstance(action.cost.expression, pddl.NumericConstant):
        return action.cost.expression.value / get_cost_scale()
    var_mapping = {p.name: a for p, a in zip(action.parameters, args)}
    args = tuple(var_mapping[p] for p in action.cost.expression.args)
    head = Head(action.cost.expression.symbol, args)
    [(value, _)] = results_from_head[head]
    return value
Пример #5
0
def extract_function_results(results_from_head, action, pddl_args):
    import pddl
    if (action.cost is None) or not isinstance(
            action.cost.expression, pddl.PrimitiveNumericExpression):
        return None
    var_mapping = {p.name: a for p, a in zip(action.parameters, pddl_args)}
    pddl_args = tuple(
        obj_from_pddl(var_mapping[p]) for p in action.cost.expression.args)
    head = Head(action.cost.expression.symbol, pddl_args)
    [(_, result)] = results_from_head[head]
    if result is None:
        return None
    return result
def extract_function_result(results_from_head, action, pddl_args):
    import pddl
    if action.cost is None:
        return None
    # TODO: retrieve constant action costs
    # TODO: associate costs with the steps they are applied
    expression = action.cost.expression
    if not isinstance(expression, pddl.PrimitiveNumericExpression):
        return None
    var_mapping = {p.name: a for p, a in zip(action.parameters, pddl_args)}
    obj_args = tuple(
        obj_from_pddl(var_mapping[p] if is_parameter(p) else p)
        for p in expression.args)
    head = Head(expression.symbol, obj_args)
    [result] = results_from_head[head]
    if result is None:
        return None
    return result
Пример #7
0
def head_from_fact(fact):
    return Head(get_prefix(fact), get_args(fact))