public AcyclicSP(EdgeWeightedDiagraph ewg, int source) { edgeTo = new DirectedEdge[ewg.V()]; distTo = new double[ewg.V()]; for (int i = 0; i < ewg.V(); i++) { distTo[i] = double.PositiveInfinity; } distTo[source] = 0; TopologicalOrder tlOrder = new TopologicalOrder(ewg); foreach (int v in tlOrder.Order()) { Relax(ewg, v); } }
//Bellman Ford has the complexity of O(VE) public BellmanFordSP(EdgeWeightedDiagraph ewg, int source) { vertexNum = ewg.V(); distTo = new double[vertexNum]; edgeTo = new DirectedEdge[vertexNum]; for (int i = 0; i < vertexNum; i++) { distTo[i] = double.PositiveInfinity; } distTo[source] = 0.0; }
public DijkstraSP(EdgeWeightedDiagraph g, int source) { vertexNumber = g.V(); distTo = new double[vertexNumber]; for (int i = 0; i < vertexNumber; i++) { distTo[i] = double.PositiveInfinity; } distTo[source] = 0.0; edgeTo = new DirectedEdge[vertexNumber]; pq = new IndexMinPQ <double>(vertexNumber); pq.Insert(source, 0.0); while (!pq.IsEmpty()) { int current = pq.DelMin(); Relax(g, current); } }