Ejemplo n.º 1
0
        /// <summary>Given the forward and backward chains formed by bidirectional searching, joins them together and returns
        /// a single forward-only solution.
        /// </summary>
        Node <StateType, ActionType> BuildBidirectionalSolution(Node <StateType, ActionType> start,
                                                                Node <StateType, ActionType> end)
        {
            // 'start' contains the solution leading back to the start node, and 'end' contains the solution leading back to
            // the end node. both have the same state. we need to reverse the solution of the end node, and adjust the
            // actions, depths, and costs
            while (end.Parent != null)
            {
                Node <StateType, ActionType> nextEnd = end.Parent;

                end.Action        = BidiProblem.GetSuccessorAction(end.Parent.State, end.State, end.Action);
                end.State         = nextEnd.State;
                end.PathCost      = start.PathCost + (end.Parent == null ? 0 : end.PathCost - end.Parent.PathCost);
                end.Depth         = start.Depth + 1;
                end.Parent        = start;
                end.HeuristicCost = nextEnd.HeuristicCost;

                start = end;
                end   = nextEnd;
            }

            return(start);
        }