Esempio n. 1
0
        /// <summary>
        /// Computes the forward cost heuristics for the given state in the relaxed planning graph.
        /// </summary>
        /// <param name="state">Starting state.</param>
        /// <param name="goalConditions">Goal conditions.</param>
        /// <param name="evaluationStrategy">Evaluation strategy.</param>
        /// <returns>Forward cost heuristic value from the specified state.</returns>
        private double ComputeForwardCost(IState state, IConditions goalConditions, ForwardCostEvaluationStrategy evaluationStrategy)
        {
            IStateLayer previousStateLayer = null;
            IStateLayer stateLayer         = CreateLabeledStateLayer(state.GetRelaxedState());
            ActionLayer actionLayer        = new ActionLayer();

            while (!stateLayer.Equals(previousStateLayer))
            {
                // check goal conditions

                if (goalConditions.Evaluate(stateLayer.GetState()))
                {
                    return(goalConditions.EvaluateOperatorPlanningGraphLabel(stateLayer.GetStateLabels(), evaluationStrategy));
                }

                // build new action layer

                actionLayer.Clear();
                foreach (var successor in RelaxedProblem.GetSuccessors(stateLayer.GetState()))
                {
                    IOperator appliedOperator = successor.GetAppliedOperator();
                    double    label           = appliedOperator.ComputePlanningGraphLabel(stateLayer.GetStateLabels(), evaluationStrategy);
                    actionLayer.Add(new ActionNode(appliedOperator, label + appliedOperator.GetCost()));
                }

                // build new state layer

                previousStateLayer = stateLayer;
                stateLayer         = CreateLabeledStateLayer(stateLayer, actionLayer);
            }

            // failure, solution cannot be found from the specified state
            return(int.MaxValue);
        }
        /// <summary>
        /// Evaluates the label of the operator with the specified preconditions and substitution.
        /// </summary>
        /// <param name="conditions">Operator conditions.</param>
        /// <param name="substitution">Variable substitution.</param>
        /// <param name="stateLabels">Atom labels in the predecessor layer.</param>
        /// <param name="evaluationStrategy">Evaluation strategy.</param>
        /// <returns>Operator label value in the relaxed planning graph.</returns>
        public double Evaluate(ConditionsCNF conditions, ISubstitution substitution, StateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy)
        {
            Substitution       = substitution;
            StateLabels        = stateLabels;
            EvaluationStrategy = evaluationStrategy;

            return(conditions.Accept(this).Item1);
        }
Esempio n. 3
0
        /// <summary>
        /// Computes the operator label in the relaxed planning graph.
        /// </summary>
        /// <param name="stateLabels">State labels from the predecessor layer in the graph.</param>
        /// <param name="evaluationStrategy">Evaluation strategy of the planning graph.</param>
        /// <returns>Computed operator label in the relaxed planning graph.</returns>
        public double EvaluateOperatorPlanningGraphLabel(IStateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy)
        {
            double result = 0;

            foreach (var conditions in this)
            {
                result = Math.Max(result, conditions.EvaluateOperatorPlanningGraphLabel(stateLabels, evaluationStrategy));
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Computes the operator label in the relaxed planning graph.
        /// </summary>
        /// <param name="stateLabels">State labels from the predecessor layer in the graph.</param>
        /// <param name="evaluationStrategy">Evaluation strategy of the planning graph.</param>
        /// <returns>Computed operator label in the relaxed planning graph.</returns>
        public double EvaluateOperatorPlanningGraphLabel(IStateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy)
        {
            StateLabels labels = (StateLabels)stateLabels;

            double result = 0;

            foreach (var assignment in this)
            {
                double variableLabel = labels[assignment];
                if (evaluationStrategy == ForwardCostEvaluationStrategy.ADDITIVE_VALUE)
                {
                    result += variableLabel;
                }
                else
                {
                    result = Math.Max(result, variableLabel);
                }
            }

            return(result);
        }
Esempio n. 5
0
 /// <summary>
 /// Computes the operator label in the relaxed planning graph.
 /// </summary>
 /// <param name="substitution">Variable substitution.</param>
 /// <param name="stateLabels">Atom labels from the predecessor layer in the graph.</param>
 /// <param name="evaluationStrategy">Evaluation strategy of the planning graph.</param>
 /// <returns>Computed operator label in the relaxed planning graph.</returns>
 public double EvaluateOperatorPlanningGraphLabel(ISubstitution substitution, IStateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy)
 {
     return(EvaluationManager.EvaluateOperatorPlanningGraphLabel(this, substitution, (StateLabels)stateLabels, evaluationStrategy));
 }
Esempio n. 6
0
 /// <summary>
 /// Computes the operator label in the relaxed planning graph.
 /// </summary>
 /// <param name="stateLabels">State labels from the predecessor layer in the graph.</param>
 /// <param name="evaluationStrategy">Evaluation strategy of the planning graph.</param>
 /// <returns>Computed operator label in the relaxed planning graph.</returns>
 public double EvaluateOperatorPlanningGraphLabel(IStateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy)
 {
     return(EvaluateOperatorPlanningGraphLabel(null, stateLabels, evaluationStrategy));
 }
Esempio n. 7
0
 /// <summary>
 /// Computes the operator label in the relaxed planning graph.
 /// </summary>
 /// <param name="stateLabels">State labels from the predecessor layer in the graph.</param>
 /// <param name="evaluationStrategy">Evaluation strategy of the planning graph.</param>
 /// <returns>Computed operator label in the relaxed planning graph.</returns>
 public double EvaluateOperatorPlanningGraphLabel(IStateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy)
 {
     return(int.MaxValue);
 }
Esempio n. 8
0
 /// <summary>
 /// Computes the operator label in the relaxed planning graph.
 /// </summary>
 /// <param name="substitution">Variable substitution.</param>
 /// <param name="stateLabels">Atom labels from the predecessor layer in the graph.</param>
 /// <param name="evaluationStrategy">Evaluation strategy of the planning graph.</param>
 /// <returns>Computed operator label in the relaxed planning graph.</returns>
 public double ComputePlanningGraphLabel(ISubstitution substitution, StateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy)
 {
     return(Preconditions.EvaluateOperatorPlanningGraphLabel(substitution, stateLabels, evaluationStrategy));
 }
Esempio n. 9
0
 /// <summary>
 /// Computes the operator label in the relaxed planning graph.
 /// </summary>
 /// <param name="conditions">Operator preconditions.</param>
 /// <param name="substitution">Variable substitution.</param>
 /// <param name="stateLabels">Atom labels from the predecessor layer in the graph.</param>
 /// <param name="evaluationStrategy">Evaluation strategy of the planning graph.</param>
 /// <returns>Computed operator label in the relaxed planning graph.</returns>
 public double EvaluateOperatorPlanningGraphLabel(ConditionsCNF conditions, ISubstitution substitution, StateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy)
 {
     return(PlanningGraphOperatorLabelEvaluatorCNF.Value.Evaluate(conditions, substitution, stateLabels, evaluationStrategy));
 }
Esempio n. 10
0
 /// <summary>
 /// Computes the operator label in the relaxed planning graph.
 /// </summary>
 /// <param name="stateLabels">Atom labels from the predecessor layer in the graph.</param>
 /// <param name="evaluationStrategy">Evaluation strategy of the planning graph.</param>
 /// <returns>Computed operator label in the relaxed planning graph.</returns>
 public double ComputePlanningGraphLabel(IStateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy)
 {
     return(LiftedOperator.ComputePlanningGraphLabel(Substitution, (StateLabels)stateLabels, evaluationStrategy));
 }