LISTING PROGRAM
public void init(List<List<double>> inputTable, double N) {
public void path(int u, int v)
public List<List<double>> FloydAlgo(List<List<double>> M) {
Console.Write("-");
public List<List<edge_>> graph = new List<List<edge_>>(); List<double> shortestDistances = new List<double>(); List<double> predecessorVertex = new List<double>();
public double totalJarak; public List<int> path;
Stopwatch watch = new Stopwatch(); public double elapsedTimeMs = 0;
while (queue.Count != 0) {
int u = queue.Dequeue();
foreach (var pair in graph[u]) {
int v = pair.toIndex; if (shortestDistances[v] > shortestDistances[u] + pair.cost)
{
shortestDistances[v] = shortestDistances[u] + pair.cost;
predecessorVertex[v] = u; if (!queue.Contains(v)) queue.Enqueue(v); }
} }
getPath(startIndex, toIndex);
totalJarak = shortestDistances[toIndex]; elapsedTimeMs = watch.stop();
}
public void getPath(int u, int v) {
double k;
k = predecessorVertex[v];
if (k == -1 || u == v) {
return; }
path.Add((int)k); getPath(u, (int)k);