/// <summary> /// Creates a new graph class instance based on a list of nodes. /// </summary> /// <param name="nodes">The list of nodes to populate the newly created Graph class with.</param> public Graph(NodeList nodes) { this.nodes = nodes; }
/// <summary> /// Retrieves the Node from the passed-in NodeList that has the <i>smallest</i> value in the distance table. /// </summary> /// <remarks>This method of grabbing the smallest Node gives Dijkstra's Algorithm a running time of /// O(<i>n</i><sup>2</sup>), where <i>n</i> is the number of nodes in the pathFinding.Graph. A better approach is to /// use a <i>priority queue</i> data structure to store the nodes, rather than an array. Using a priority queue /// will improve Dijkstra's running time to O(E lg <i>n</i>), where E is the number of edges. This approach is /// preferred for sparse pathFinding.Graphs. For more information on this, consult the README included in the download.</remarks> private static Node GetMin(NodeList nodes) { // find the node in nodes with the smallest distance value int minDist = Int32.MaxValue; Node minNode = null; foreach (Node n in nodes) { if (((int)dist[n.Key]) <= minDist) { minDist = (int)dist[n.Key]; minNode = n; } } return minNode; }
/// <summary> /// Default constructor. Creates a new Graph class instance. /// </summary> public Graph() { this.nodes = new NodeList(); }