/// <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);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Generates all possible PDDL states meeting conditions specified by the relative state. Lazy generated via yield return.
        /// </summary>
        /// <param name="relativeState">Reference relative state.</param>
        /// <param name="problem">Planning problem.</param>
        /// <returns>All possible PDDL states meeting the conditions.</returns>
        public static IEnumerable <IState> EnumerateStates(IRelativeState relativeState, Problem problem)
        {
            // note: numeric function assignments are not enumerated (as it is generally infinite), but only fixed by the values of the source state

            Func <IAtom, bool?> predicateChecker = (predicate) =>
            {
                if (relativeState.HasPredicate(predicate))
                {
                    return(true);
                }
                else if (relativeState.HasNegatedPredicate(predicate))
                {
                    return(false);
                }
                return(null);
            };

            Func <IAtom, int> objectFunctionChecker = relativeState.GetObjectFunctionValue;

            IState initState = new State(problem.IdManager);

            foreach (var numericFunction in relativeState.GetNumericFunctions())
            {
                initState.AssignNumericFunction(numericFunction.Key, numericFunction.Value);
            }

            var predicates      = problem.EvaluationManager.GroundingManager.GetAllGroundedPredicates();
            var objectFunctions = problem.EvaluationManager.GroundingManager.GetAllGroundedObjectFunctions();

            foreach (var state in EnumerateStatesByPredicates(0, predicates, initState, predicateChecker))
            {
                foreach (var resultState in EnumerateStatesByObjectFunctions(0, objectFunctions, state, objectFunctionChecker))
                {
                    yield return(resultState);
                }
            }
        }