コード例 #1
0
def not_equal_stream(ty1=OBJECT, ty2=OBJECT):
    name = '_not_eq_%s_%s' % (ty1.name, ty2.name)
    AreNotEqual = NamedPredicate(name, [ty1, ty2])
    X1, X2 = Parameter('x1', ty1), Parameter('x2', ty2)
    cs = EasyTestStream([X1, X2], [], [AreNotEqual(X1, X2)],
                        lambda x1, x2: x1 != x2, eager=True)
    return AreNotEqual, cs
コード例 #2
0
ファイル: utils.py プロジェクト: OolongQian/stripstream
def rename_easy(assignments):
    """
    Mutates any :class:`.EasyType`, :class:`.EasyPredicate`, or :class:`.EasyParameter` instance to assign their local scope name

    :param assignments: the result of ```locals()```
    """
    for name, value in assignments.iteritems():
        if type(value) in [EasyType, EasyPredicate]:
            value.name = name.lower()
        elif type(value) == EasyParameter:
            Parameter.__init__(value, name, value.type)
コード例 #3
0
 def p1(self):
     return Parameter('1', self)  # NOTE - could also just make an object
コード例 #4
0
hand_empty = H(0)
holding_1 = H(1)

Function = Predicate  # TODO - alternatively a constraint

Kin = Function('kin', [R, O])
Motion = Function('motion', [R, R, T])

# TODO - make a shared initial and final variable for all of these
# I could just make a long laundry list of fluents that are constraints

# NOTE - if I list a variable twice, then I have to automatically substitute its values

# Maybe list what changes instead fo what is the same in general

Q = Parameter('q', R)
QE = Parameter('qe', R)

Q1 = Parameter('q1', R)
Q2 = Parameter('q2', R)


def O1(name):
    return 'o' + name + '1'


def B(var):
    return var + 'e'


def E(var):
コード例 #5
0
ファイル: problem.py プロジェクト: OolongQian/stripstream
    def convert_axioms_to_effects(self):
        derived_predicates = self.get_derived_predicates()
        fluent_predicates = self.get_fluent_predicates()
        constants = defaultdict(set)
        for const in self.get_constants():
            constants[const.type].add(const)

        mapping = []
        for op in self.operators:
            if isinstance(op, Axiom):
                [conditions
                 ] = op.condition.dequantify(constants).get_literals()
                assert not filter(lambda a: a.predicate in derived_predicates,
                                  conditions)
                print conditions
                [fluent] = filter(lambda a: a.predicate in fluent_predicates,
                                  conditions)
                others = filter(lambda a: a != fluent, conditions)
                mapping.append((fluent, others, op.effect))

        new_operators = []
        for op in self.operators:
            if isinstance(op, Action):
                new_op = op.clone()
                new_operators.append(new_op)
                [literals] = new_op.effect.get_literals()
                for literal in literals:
                    effect = literal.formula if isinstance(literal,
                                                           Not) else literal
                    for fluent, conditions, derived in mapping:
                        if effect.predicate == fluent.predicate:
                            free_params = set(
                                flatten(
                                    map(lambda a: a.args, [derived] +
                                        conditions))) - set(fluent.args)
                            param_map = dict(zip(fluent.args, effect.args))
                            for i, param in enumerate(free_params):

                                param_map[param] = Parameter(
                                    'l%s' % i, param.type)

                            new_params = list(
                                set(param_map.values()) - set(effect.args))
                            new_derived = derived.instantiate(param_map)
                            new_conditions = [
                                cond.instantiate(param_map)
                                for cond in conditions
                            ]
                            if isinstance(literal, Not):
                                new_op.add_effects(
                                    ForAll(
                                        new_params,
                                        When(And(*new_conditions),
                                             new_derived)))
                            else:
                                new_op.add_effects(
                                    ForAll(
                                        new_params,
                                        When(And(*new_conditions),
                                             Not(new_derived))))

        return new_operators
コード例 #6
0
def convert_axioms_to_effects(
    problem
):  # NOTE - can always use the previous compilation process for some problematic axioms
    derived_predicates = problem.get_derived_predicates()
    fluent_predicates = problem.get_fluent_predicates()
    constants = defaultdict(set)
    for const in problem.get_constants():
        constants[const.type].add(const)

    mapping = []
    for op in problem.operators:  # NOTE - can always just convert one
        if isinstance(op, Axiom):
            [conditions] = op.condition.dequantify(constants).get_literals(
            )  # TODO - more complicated if multiple ways to achieve
            assert not filter(
                lambda a: a.predicate in derived_predicates,
                conditions)  # TODO - difficulty when levels of axioms
            print conditions
            [fluent] = filter(
                lambda a: a.predicate in fluent_predicates,
                conditions)  # NOTE - could easily expand to conjunctive case
            others = filter(lambda a: a != fluent, conditions)
            mapping.append((fluent, others, op.effect))

    new_operators = []
    for op in problem.operators:
        if isinstance(op, Action):
            new_op = op.clone()
            new_operators.append(new_op)
            [literals] = new_op.effect.get_literals()  # TODO
            for literal in literals:
                effect = literal.formula if isinstance(literal,
                                                       Not) else literal
                for fluent, conditions, derived in mapping:
                    if effect.predicate == fluent.predicate:
                        free_params = set(
                            flatten(
                                map(lambda a: a.args, [derived] +
                                    conditions))) - set(fluent.args)
                        param_map = dict(zip(fluent.args, effect.args))
                        for i, param in enumerate(
                                free_params):  # Prevents conflicting names
                            #param_map[param] = Parameter('_%s'%i, param.type) # NOTE - FF can't parse this
                            param_map[param] = Parameter('l%s' % i, param.type)

                        new_params = list(
                            set(param_map.values()) - set(effect.args))
                        new_derived = derived.instantiate(param_map)
                        new_conditions = [
                            cond.instantiate(param_map) for cond in conditions
                        ]  # TODO - could put in the negated version of new_derived
                        if isinstance(literal, Not):
                            new_op.add_effects(
                                ForAll(new_params,
                                       When(And(*new_conditions),
                                            new_derived)))
                        else:
                            new_op.add_effects(
                                ForAll(
                                    new_params,
                                    When(And(*new_conditions),
                                         Not(new_derived)))
                            )  # Not necessary, but it could reduce the number of instances
                            #op.add_effects(ForAll(new_params, Not(new_derived))) # One failure can break
    return new_operators