コード例 #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);
        }