コード例 #1
0
def instantiate_condition(action, is_static, args_from_predicate):
    parameters = {p.name for p in action.parameters}
    #if not parameters:
    #    yield {}
    #    return
    static_conditions = list(
        filter(is_static, get_literals(get_precondition(action))))
    static_parameters = set(
        filter(is_parameter, flatten(atom.args for atom in static_conditions)))
    if not (parameters <= static_parameters):
        raise NotImplementedError(
            'Could not instantiate action {} due to parameters: {}'.format(
                action.name, str_from_object(parameters - static_parameters)))
    atoms_from_cond = {
        condition: args_from_predicate[condition.predicate,
                                       get_constants(condition)]
        for condition in static_conditions
    }
    conditions, atoms = zip(*atoms_from_cond.items())
    relations = [
        Relation(conditions[index].args, atoms[index])
        for index in compute_order(conditions, atoms)
    ]
    solution = solve_satisfaction(relations)
    for element in solution.body:
        yield solution.get_mapping(element)
コード例 #2
0
ファイル: instantiation.py プロジェクト: Khodeir/pddlstream
 def _add_combinations_relation(self, stream, atoms):
     if not all(atoms):
         return
     # TODO: might be a bug here?
     domain = list(map(head_from_fact, stream.domain))
     # TODO: compute this first?
     relations = [
         Relation(filter(is_parameter, domain[index].args), [
             tuple(a for a, b in safe_zip(atom.args, domain[index].args)
                   if is_parameter(b)) for atom in atoms[index]
         ]) for index in compute_order(domain, atoms)
     ]
     solution = solve_satisfaction(relations)
     for element in solution.body:
         mapping = solution.get_mapping(element)
         input_objects = safe_apply_mapping(stream.inputs, mapping)
         self.push_instance(stream.get_instance(input_objects))