/// <summary> /// Initializes a new instance of the <see cref="BellmanFord"/> class. /// </summary> /// <param name="graph">The graph.</param> /// <param name="startNode">The start node.</param> public BellmanFordSearch([NotNull] IWeightedGraph graph, uint startNode, uint goal) { if ((graph.Properties & GraphProperties.Dnyamic) != 0) { throw InvalidGraphPropertiesException.MustNotHave(GraphProperties.Dnyamic); } if (startNode >= graph.Count) { throw new ArgumentException("The starting node not in range."); } int count = (int)graph.Count; this.distance = new float[count]; this.bestPrevious = new uint[count]; this.graph = graph; this.initialNode = startNode; this.goal = goal; for (int i = 0; i < count; i++) { this.distance[i] = float.PositiveInfinity; this.bestPrevious[i] = uint.MaxValue; // And extract edges. List <Edge> edges = graph.NextWeightedNodes((uint)i); for (int j = 0; j < edges.Count; j++) { allEdges.Add(new BFEdge((uint)i, edges[j].Node, edges[j].Weight)); } } distance[startNode] = 0.0f; }
/// <summary> /// Initializes a new instance of the <see cref="FloydWarshallSearch"/> class. /// </summary> /// <param name="graph">The graph.</param> public FloydWarshallSearch([NotNull] IWeightedGraph graph) { if ((graph.Properties & GraphProperties.Dnyamic) != 0) { throw InvalidGraphPropertiesException.MustNotHave(GraphProperties.Dnyamic); } // Extract count. int count = (int)graph.Count; this.graph = graph; this.path = new float[count, count]; for (int i = 0; i < count; i++) { // Initialize all to infinite. for (int j = 0; j < count; j++) { path[i, j] = float.PositiveInfinity; } // Correct for those that are not infinite. List <Edge> edges = graph.NextWeightedNodes((uint)i); for (int k = 0; k < edges.Count; k++) { path[i, edges[k].Node] = edges[k].Weight; } } }
/// <summary> /// Initializes a new instance of the <see cref="Dijkstra"/> class. /// </summary> /// <param name="graph">The graph.</param> /// <param name="start">The start.</param> /// <param name="goal">The goal.</param> public Dijkstra([NotNull] IWeightedGraph graph, uint start, uint goal) { if ((graph.Properties & GraphProperties.Dnyamic) != 0) { throw InvalidGraphPropertiesException.MustNotHave(GraphProperties.Dnyamic); } int count = (int)graph.Count; if (start >= (uint)count || goal >= (uint)count) { throw new ArgumentException("Goal or start out of graph nodes."); } this.graph = graph; this.goal = goal; // We initialize distance and best previous. bestPrevious = new uint[count]; wasProcessed = new bool[count]; distance = new float[count]; for (int i = 0; i < count; i++) { distance[i] = float.PositiveInfinity; bestPrevious[i] = uint.MaxValue; wasProcessed[i] = false; } distance[start] = 0.0f; minHeap.Push(new DijkstraNode(0.0f, start)); }