示例#1
0
def simple_substitution(set, phi):
    if phi == ds.TRUE():
        return ds.TRUE()
    if phi == ds.FALSE():
        return ds.FALSE()
    if isinstance(phi, ds.Literal):
        if phi in set:
            return ds.TRUE()
        phi_neg = phi.negate()
        if phi_neg in set:
            return ds.FALSE()
        else:
            # phi is not in the initial state
            if phi.negated:
                return ds.TRUE()
            else:
                return ds.FALSE()
    elif isinstance(phi, ds.Or):
        return ds.Or([
            simple_substitution(set, component) for component in phi.components
        ])
    else:
        # Conjunction
        return ds.And([
            simple_substitution(set, component) for component in phi.components
        ])
示例#2
0
def effect_conversion(action):
    new_effects = []
    for cond, eff in action.add_effects:
        if not cond:
            new_effects.append(ds.Effect(ds.TRUE(), convert_formula(eff)))
        else:
            new_cond = [convert_formula(lit) for lit in cond]
            new_effects.append(
                ds.Effect(ds.And(new_cond).simplified(), convert_formula(eff)))
    for cond, eff in action.del_effects:
        eff_neg = eff.negate()
        if not cond:
            new_effects.append(ds.Effect(ds.TRUE(), convert_formula(eff_neg)))
        else:
            new_cond = [convert_formula(lit) for lit in cond]
            new_effects.append(
                ds.Effect(
                    ds.And(new_cond).simplified(), convert_formula(eff_neg)))
    return new_effects
示例#3
0
def manage_sa_compilation(phi, psi, m_atom, a, E):
    if OPTIMIZED:
        R1 = regression_aux(phi, a)
        R2 = regression_aux(psi, a)
        monitoring_atom = ds.Literal(m_atom, False)
        if can_make_true(a, phi) or can_falsify(a, psi):
            cond = ds.And([R1, R2.negate()]).simplified()
            cond_eff = create_cond_eff(cond, monitoring_atom.negate())
            add_cond_eff(E, cond_eff)
        if can_make_true(a, psi):
            add_cond_eff(E, create_cond_eff(R2, monitoring_atom))
    else:
        R1 = regression_aux(phi, a)
        R2 = regression_aux(psi, a)
        monitoring_atom = ds.Literal(m_atom, False)
        if phi != R1 or psi != R2:
            cond = ds.And([R1, R2.negate()]).simplified()
            cond_eff = create_cond_eff(cond, monitoring_atom.negate())
            add_cond_eff(E, cond_eff)
        if psi != R2:
            add_cond_eff(E, create_cond_eff(R2, monitoring_atom))
示例#4
0
def convert_formula(formula):
    if isinstance(formula, pddl.Atom):
        return ds.Literal(atom_str(formula), False)
    elif isinstance(formula, pddl.NegatedAtom):
        return ds.Literal(atom_str(formula), True)
    elif isinstance(formula, pddl.Disjunction):
        return ds.Or([convert_formula(part) for part in formula.parts])
    elif isinstance(formula, pddl.Conjunction):
        return ds.And([convert_formula(part) for part in formula.parts])
    elif isinstance(formula, pddl.Truth):
        return ds.TRUE()
    elif isinstance(formula, pddl.Falsity):
        return ds.FALSE()
示例#5
0
    def __str__(self):
        action_str = '(:action {name}\n' \
                     ':parameters ()\n' \
                     ':precondition {preconditions}\n' \
                     ':effect (and {effects}))'
        eff_str = ''
        for eff in self.effects:
            eff_str += str(eff)

        pre_str = str(ds.And(self.precondition).simplified())
        return action_str.format(name=self.name,
                                 preconditions=pre_str,
                                 effects=eff_str)
示例#6
0
def tcore(F, A, I, G, C):
    relevancy_dict = build_relevancy_dict(C)
    A_prime = []
    G_prime = []
    I_prime, F_prime = get_monitoring_atoms(C, I)
    compiled_action = 0
    for c in LTC(C):
        monitoring_atom = ds.Literal(c.monitoring_atom, False)
        G_prime.append(monitoring_atom)
    G_prime = ds.And(G_prime)
    for a in A:
        E = []
        relevant_constraints = get_relevant_constraints(a, relevancy_dict)
        if len(relevant_constraints) > 0:
            compiled_action += 1
        for c in relevant_constraints:
            if c.kind == ds.ALWAYS:
                precondition, to_add = manage_always_compilation(c.gd1, a)
            elif c.kind == ds.ATMOSTONCE:
                precondition, to_add = manage_amo_compilation(
                    c.gd1, c.monitoring_atom, a, E)
            elif c.kind == ds.SOMETIMEBEFORE:
                precondition, to_add = manage_sb_compilation(
                    c.gd1, c.gd2, c.monitoring_atom, a, E)
            if c.kind == ds.ALWAYS or c.kind == ds.ATMOSTONCE or c.kind == ds.SOMETIMEBEFORE:
                if to_add:
                    a.precondition.append(precondition)
            if c.kind == ds.SOMETIME:
                manage_sometime_compilation(c.gd1, c.monitoring_atom, a, E)
            elif c.kind == ds.SOMETIMEAFTER:
                manage_sa_compilation(c.gd1, c.gd2, c.monitoring_atom, a, E)
        for eff in E:
            a.effects.append(eff)
        if ds.FALSE() not in a.precondition:
            A_prime.append(a)
    G_new = ds.And([G, G_prime]).simplified()

    #print("Compiled actions: {}".format(compiled_action))
    return F + F_prime, A_prime, I + I_prime, G_new
示例#7
0
def regression(phi, action):
    if isinstance(phi, ds.TRUE):
        return phi
    elif isinstance(phi, ds.FALSE):
        return phi
    elif isinstance(phi, ds.Literal):
        return gamma_substitution(phi, action)
    elif isinstance(phi, ds.Or):
        return ds.Or(
            [regression(component, action) for component in phi.components])
    else:
        # And
        return ds.And(
            [regression(component, action) for component in phi.components])
示例#8
0
def gamma_substitution(literal, action):
    negated_literal = literal.negate()
    gamma1 = gamma(literal, action)
    gamma2 = gamma(negated_literal, action).negate()
    conjunction = ds.And([literal, gamma2])
    return ds.Or([gamma1, conjunction])