Example #1
0
        /// <summary>
        /// Extracts a minimal necessary operator substitution needed for the backward application (other parameters remain lifted).
        /// </summary>
        /// <returns>Minimal substitution.</returns>
        public ISubstitution ExtractMinimalOperatorSubstitution()
        {
            // we need to determine, which effects were actually used for the backwards application (i.e. have to be grounded).

            ISubstitution substitution = new Substitution();

            foreach (var predicate in UsedGroundedPredicates)
            {
                IAtom liftedPredicate;
                if (Effects.OriginalLiftedPredicates.TryGetValue(predicate, out liftedPredicate))
                {
                    var unification = liftedPredicate.GetUnificationWith(predicate);
                    substitution.AddLocalSubstitution(unification);
                }
            }

            foreach (var function in UsedGroundedFunctions)
            {
                IAtom liftedFunction;
                if (Effects.OriginalLiftedFunctions.TryGetValue(function, out liftedFunction))
                {
                    var unification = liftedFunction.GetUnificationWith(function);
                    substitution.AddLocalSubstitution(unification);
                }
            }

            return(substitution);
        }
        /// <summary>
        /// Visits and performs a property count on forall expression.
        /// </summary>
        /// <param name="expression">Forall expression.</param>
        /// <returns>Tuple (property satisfied count, property not satisfied count).</returns>
        public Tuple <double, double> Visit(ForallExpression expression)
        {
            double positiveValue = 0;
            double negativeValue = 0;

            IEnumerable <ISubstitution> localSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(expression.Parameters);

            foreach (var localSubstitution in localSubstitutions)
            {
                Substitution.AddLocalSubstitution(localSubstitution);
                var childPropertyCounts = expression.Child.Accept(this);
                Substitution.RemoveLocalSubstitution(localSubstitution);

                if (EvaluationStrategy == ForwardCostEvaluationStrategy.ADDITIVE_VALUE)
                {
                    positiveValue += childPropertyCounts.Item1;
                    negativeValue += childPropertyCounts.Item2;
                }
                else
                {
                    positiveValue = Math.Max(positiveValue, childPropertyCounts.Item1);
                    negativeValue = Math.Max(negativeValue, childPropertyCounts.Item2);
                }
            }

            return(Tuple.Create(positiveValue, negativeValue));
        }
        /// <summary>
        /// Visits and handles the effect.
        /// </summary>
        /// <param name="effect">Effect.</param>
        public void Visit(ForallEffect effect)
        {
            IEnumerable <ISubstitution> localSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(effect.Parameters);

            foreach (var localSubstitution in localSubstitutions)
            {
                Substitution.AddLocalSubstitution(localSubstitution);
                foreach (var localEffect in effect.Effects)
                {
                    localEffect.Accept(this);
                }
                Substitution.RemoveLocalSubstitution(localSubstitution);
            }
        }
        /// <summary>
        /// Visits and evaluates forall expression.
        /// </summary>
        /// <param name="expression">Forall expression.</param>
        /// <returns>True if the specified expression evaluates as true, false otherwise.</returns>
        public bool Visit(ForallExpression expression)
        {
            IEnumerable <ISubstitution> localSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(expression.Parameters);

            foreach (var localSubstitution in localSubstitutions)
            {
                Substitution.AddLocalSubstitution(localSubstitution);
                bool subExpressionResult = expression.Child.Accept(this);
                Substitution.RemoveLocalSubstitution(localSubstitution);

                if (!subExpressionResult)
                {
                    return(false);
                }
            }
            return(true);
        }
        /// <summary>
        /// Visits and performs a property count on exists expression.
        /// </summary>
        /// <param name="expression">Exists expression.</param>
        /// <returns>Tuple (property satisfied count, property not satisfied count).</returns>
        public Tuple <double, double> Visit(ExistsExpression expression)
        {
            double positiveValue = 0.0;
            double negativeValue = 0.0;

            IEnumerable <ISubstitution> localSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(expression.Parameters);

            foreach (var localSubstitution in localSubstitutions)
            {
                Substitution.AddLocalSubstitution(localSubstitution);
                var childPropertyCounts = expression.Child.Accept(this);
                Substitution.RemoveLocalSubstitution(localSubstitution);

                positiveValue = Math.Max(positiveValue, childPropertyCounts.Item1);
                negativeValue = Math.Max(negativeValue, childPropertyCounts.Item2);
            }

            return(Tuple.Create(positiveValue, negativeValue));
        }
Example #6
0
        /// <summary>
        /// Visits and performs a property count on forall expression.
        /// </summary>
        /// <param name="expression">Forall expression.</param>
        /// <returns>Tuple (property satisfied count, property not satisfied count).</returns>
        public Tuple <int, int> Visit(ForallExpression expression)
        {
            int fulfilled    = 0;
            int notFulfilled = 0;

            IEnumerable <ISubstitution> localSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(expression.Parameters);

            foreach (var localSubstitution in localSubstitutions)
            {
                Substitution.AddLocalSubstitution(localSubstitution);
                var childPropertyCounts = expression.Child.Accept(this);
                Substitution.RemoveLocalSubstitution(localSubstitution);

                fulfilled    += childPropertyCounts.Item1;
                notFulfilled += childPropertyCounts.Item2;
            }

            return(Tuple.Create(fulfilled, notFulfilled));
        }
Example #7
0
        /// <summary>
        /// Visits and performs a property count on exists expression.
        /// </summary>
        /// <param name="expression">Exists expression.</param>
        /// <returns>Tuple (property satisfied count, property not satisfied count).</returns>
        public Tuple <int, int> Visit(ExistsExpression expression)
        {
            int minFulfilled    = int.MaxValue;
            int minNotFulfilled = int.MaxValue;

            IEnumerable <ISubstitution> localSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(expression.Parameters);

            foreach (var localSubstitution in localSubstitutions)
            {
                Substitution.AddLocalSubstitution(localSubstitution);
                var childPropertyCounts = expression.Child.Accept(this);
                Substitution.RemoveLocalSubstitution(localSubstitution);

                minFulfilled    = Math.Min(minFulfilled, childPropertyCounts.Item1);
                minNotFulfilled = Math.Min(minNotFulfilled, childPropertyCounts.Item2);
            }

            return(Tuple.Create(minFulfilled, minNotFulfilled));
        }