AIMA.Core.Search.Framework.Node.getPathFromRoot C# (CSharp) Method

getPathFromRoot() public method

public getPathFromRoot ( ) : List
return List
        public List<Node> getPathFromRoot()
        {
            List<Node> path = new List<Node>();
            Node current = this;
            while (!current.isRootNode())
            {
                path.Insert(0, current);
                current = current.getParent();
            }
            // ensure the root node is added
            path.Insert(0, current);
            return path;
        }

Usage Example

	// function HILL-CLIMBING(problem) returns a state that is a local maximum
	public List<Action> search(Problem p) {
		clearInstrumentation();
		outcome = SearchOutcome.FAILURE;
		lastState = null;
		// current <- MAKE-NODE(problem.INITIAL-STATE)
		Node current = new Node(p.getInitialState());
		Node neighbor = null;
		// loop do
		while (!CancelableThread.currIsCanceled()) {
			List<Node> children = expandNode(current, p);
			// neighbor <- a highest-valued successor of current
			neighbor = getHighestValuedNodeFrom(children, p);

			// if neighbor.VALUE <= current.VALUE then return current.STATE
			if ((neighbor == null) || (getValue(neighbor) <= getValue(current))) {
				if (SearchUtils.isGoalState(p, current)) {
					outcome = SearchOutcome.SOLUTION_FOUND;
				}
				lastState = current.getState();
				return SearchUtils.actionsFromNodes(current.getPathFromRoot());
			}
			// current <- neighbor
			current = neighbor;
		}
		return new List<Action>();
	}
All Usage Examples Of AIMA.Core.Search.Framework.Node::getPathFromRoot