// Relax(u, v, w): // if(d[v] > d[u] + w(u, v)) // d[v] = d[u] + w(u, v) private void dijkstra(EdgeWeightedDigraph graph, int vertex) { pq.Insert(vertex, 0.0); while (!pq.IsEmpty()) { int v = pq.DelMin(); foreach (DirectedWeightedEdge edge in graph.Adj(v)) { Relax(edge); } } }
private void SPBellmanFord(EdgeWeightedDigraph graph) { for (int pass = 0; pass < graph.V(); pass++) { for (int v = 0; v < graph.V(); v++) { foreach (var edge in graph.Adj(v)) { Relax(edge); } } } }
public static void DisplayEWDGraph(EdgeWeightedDigraph g) { Console.WriteLine("{0} verticies, {1} edges", g.V(), g.E()); for (int i = 0; i < g.V(); ++i) { Console.Write("{0}: ", i); foreach (var u in g.Adj(i)) { Console.Write("[{0}-{1},{2}] ", u.From(), u.To(), u.Weight()); } Console.WriteLine(); } }
private void AstarSP(EdgeWeightedDigraph graph, int vertex, int target) { pq.Insert(vertex, 0.0); while (!pq.IsEmpty()) { int v = pq.DelMin(); if (v == target) { break; } foreach (DirectedWeightedEdge edge in graph.Adj(v)) { Relax(edge, target); } } }