public void AddNeighbor(GraphNode <T> n, double cost) { this.edges.AddLast(new GraphEdge <T>(this, n, cost)); }
public GraphEdge(GraphNode <T> start, GraphNode <T> end, double cost) { this.start_node = start; this.end_node = end; this.cost = cost; }
public virtual LinkedList <GraphNode <T> > ShortestPath(GraphNode <T> start_node, GraphNode <T> end_node) { examined_nodes.Clear(); curr_start_node = start_node; curr_end_node = end_node; open_nodes.Clear(); //clear both open and closed lists since they will be repopulated in this pathfinding step closed_nodes.Clear(); this.StartNode = start_node; //start node for pathfinding step resetCosts(); //reset all the costs start_node.CostSoFar = 0; DijkstraEvaluate(); //after the evaluation is done, each node has its cost and connections set //starting at the end node and appending nodes by following the connections backwards allows us to build and return a list containing the nodes in the shortest path in order. GraphNode <T> curr = end_node; LinkedList <GraphNode <T> > node_order = new LinkedList <GraphNode <T> >(); while (curr != start_node) { node_order.AddFirst(curr); curr = curr.Connection.Start; } node_order.AddFirst(curr); return(node_order); }
//shortest path using a* public override LinkedList <GraphNode <T> > ShortestPath(GraphNode <T> start_node, GraphNode <T> end_node) { examined_nodes.Clear(); curr_start_node = start_node; curr_end_node = end_node; open_nodes.Clear(); //clear open and closed and reset all costs (costs so far) closed_nodes.Clear(); this.StartNode = start_node; resetCosts(); start_node.CostSoFar = 0; //for each node compute its heuristic cost foreach (GraphNode <T> n in nodes) { n.Heuristic = n.Value.ComputeHeuristic(end_node.Value); } //same node path construction as parent class Evaluate(end_node); GraphNode <T> curr = end_node; LinkedList <GraphNode <T> > node_order = new LinkedList <GraphNode <T> >(); while (curr != start_node) { node_order.AddFirst(curr); curr = curr.Connection.Start; } node_order.AddFirst(curr); return(node_order); }
public void Add(GraphNode <T> node) { nodes.AddLast(node); }