/// <summary> /// Processes primitive effects. /// </summary> /// <param name="relativeState">Relative state to be modified.</param> private void ProcessPrimitiveEffects(IRelativeState relativeState) { foreach (var positivePredicate in Effects.GroundedPositivePredicateEffects) { if (relativeState.HasPredicate(positivePredicate)) { relativeState.RemovePredicate(positivePredicate); } } foreach (var negatedPredicate in Effects.GroundedNegativePredicateEffects) { if (relativeState.HasNegatedPredicate(negatedPredicate)) { relativeState.RemoveNegatedPredicate(negatedPredicate); } } foreach (var objectFunction in Effects.GroundedObjectFunctionAssignmentEffects) { var groundedValue = GroundingManager.GroundTermDeep(objectFunction.Value, OperatorSubstitution, relativeState); ConstantTerm constantValue = groundedValue as ConstantTerm; if (constantValue != null) { if (relativeState.GetObjectFunctionValue(objectFunction.Key) == constantValue.NameId) { relativeState.AssignObjectFunction(objectFunction.Key, ObjectFunctionTerm.UndefinedValue); } } } foreach (var numericFunction in Effects.GroundedNumericFunctionAssignmentEffects) { NumericAssignmentsBackwardsReplacer replacer = new NumericAssignmentsBackwardsReplacer(Effects.GroundedNumericFunctionAssignmentEffects, GroundingManager, OperatorSubstitution, new Substitution()); INumericExpression reducedAssignExpression = replacer.Replace(numericFunction.Value); Number assignNumber = reducedAssignExpression as Number; if (assignNumber != null) { if (relativeState.GetNumericFunctionValue(numericFunction.Key).Equals(assignNumber.Value)) { relativeState.AssignNumericFunction(numericFunction.Key, NumericFunction.UndefinedValue); } } } }
/// <summary> /// Processes a single CNF literal of operator preconditions. /// </summary> /// <param name="literal">CNF literal.</param> /// <param name="state">Relative state to be applied to.</param> private static void ProcessPreconditionLiteral(LiteralCNF literal, IRelativeState state) { PredicateLiteralCNF predicateLiteral = literal as PredicateLiteralCNF; if (predicateLiteral != null) { if (predicateLiteral.IsNegated) { state.AddNegatedPredicate(predicateLiteral.PredicateAtom); } else { state.AddPredicate(predicateLiteral.PredicateAtom); } return; } EqualsLiteralCNF equalsLiteral = literal as EqualsLiteralCNF; if (equalsLiteral != null) { ObjectFunctionTerm objFunc = equalsLiteral.LeftArgument as ObjectFunctionTerm; ConstantTerm constTerm = equalsLiteral.RightArgument as ConstantTerm; if (objFunc == null || constTerm == null) { objFunc = equalsLiteral.RightArgument as ObjectFunctionTerm; constTerm = equalsLiteral.LeftArgument as ConstantTerm; } if (objFunc != null && constTerm != null) { if (equalsLiteral.IsNegated) { if (state.GetObjectFunctionValue(objFunc.FunctionAtom) == constTerm.NameId) { state.AssignObjectFunction(objFunc.FunctionAtom, IdManager.InvalidId); } } else { state.AssignObjectFunction(objFunc.FunctionAtom, constTerm.NameId); } } return; } NumericCompareLiteralCNF compareLiteral = literal as NumericCompareLiteralCNF; if (compareLiteral != null) { if (compareLiteral.Operator != NumericCompareExpression.RelationalOperator.EQ) { return; } NumericFunction numFunc = compareLiteral.LeftArgument as NumericFunction; Number number = compareLiteral.RightArgument as Number; if (numFunc == null || number == null) { numFunc = compareLiteral.RightArgument as NumericFunction; number = compareLiteral.LeftArgument as Number; } if (numFunc != null && number != null) { if (compareLiteral.IsNegated) { if (state.GetNumericFunctionValue(numFunc.FunctionAtom).Equals(number.Value)) { state.AssignNumericFunction(numFunc.FunctionAtom, NumericFunction.DefaultValue); } } else { state.AssignNumericFunction(numFunc.FunctionAtom, number.Value); } } } }