/// <summary> /// Applies backwards the relevant operator effects and operator preconditions to the given target conditions. /// </summary> /// <param name="expression">Target conditions in CNF.</param> /// <param name="expressionSubstitution">Variables substitution of the expression.</param> /// <returns>Preceding conditions.</returns> private ConditionsCNF ApplyBackwardsImpl(ConditionsCNF expression, ISubstitution expressionSubstitution) { UsedGroundedPredicates.Clear(); UsedGroundedFunctions.Clear(); ExpressionSubstitution = expressionSubstitution; // remove positively contributing effects from the target conditions ConditionsCNF resultExpression = ProcessPrimitiveEffects(expression); resultExpression = ProcessForallEffects(resultExpression); resultExpression = ProcessWhenEffects(resultExpression); // unite processed conditions with partially grounded preconditions of the operator if (OperatorPreconditions != null) { var preconditions = ClearRigidRelations(OperatorPreconditions); resultExpression.Merge((ConditionsCNF)GroundConditions(preconditions).GetCNF()); } return(resultExpression); }
/// <summary> /// Visits the expression. /// </summary> /// <param name="expression">Expression.</param> public IElementCNF Visit(PredicateLiteralCNF expression) { var positivePredicateEffects = Effects.GroundedPositivePredicateEffects; var negativePredicateEffects = Effects.GroundedNegativePredicateEffects; if ((!expression.IsNegated && positivePredicateEffects.Count == 0) || (expression.IsNegated && negativePredicateEffects.Count == 0)) { return(expression.Clone()); } IAtom atom = GroundAtom(expression.PredicateAtom); bool positivelyContributing = (expression.IsNegated) ? negativePredicateEffects.Contains(atom) : positivePredicateEffects.Contains(atom); if (positivelyContributing) { UsedGroundedPredicates.Add(atom); return(null); } return(expression.Clone()); }