Skip to content

Commit

Permalink
remvoed bug in dijkstra
Browse files Browse the repository at this point in the history
  • Loading branch information
AzuxirenLeadGuy committed Apr 16, 2022
1 parent cdae15e commit 479490e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/GTT/Algorithms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public static G_Updates Dijkstra(byte nodeCount, byte[,] edges, byte source, byt
do
{
byte u = queue.Dequeue();
if(color[u]>=2) continue;
color[u] = 2;
yield return new(u, AllowedColors[2], $"Now exporing node {GameApp.GetLabel(u)}");
if (u == dest)
Expand Down Expand Up @@ -199,14 +200,14 @@ public static G_Updates Kruskal(byte nodeCount, byte[,] edges)
yield return new(from, to, AllowedColors[5], $"Adding this edge will introduce a cycle\nEdge {text} is discarded");
else
{
yield return new(from, to, AllowedColors[0], $"This edge can be included in the MST.\n Edge {text} is included");
yield return new(from, to, AllowedColors[4], $"This edge can be included in the MST.\n Edge {text} is included");
cost += weight;
i++;
sets.Merge(from, to);
}
if (i == nodeCount)
{
yield return new(255, AllowedColors[0], $"MST of cost {cost} is formed with the edges marked with white color");
yield return new(255, AllowedColors[4], $"MST of cost {cost} is formed with the edges marked with green color");
yield break;
}
}
Expand All @@ -227,18 +228,19 @@ public static F_Updates FloydWarshall(byte nodeCount, byte[,] edges)
yield return new("Initializing the matrix from the adjacency matrix");
for (i = 0; i < nodeCount; i++)
{
yield return new($"Pass {i+1}");
yield return new($"Pass {i + 1}");
for (j = 0; j < nodeCount; j++)
{
if (i == j) continue;
for (k = 0; k < nodeCount; k++)
{
if (k == i || k == j || matrix[i, k] == 0 || matrix[j, i] == 0) continue;
uint newdist = matrix[j, i] + matrix[i, k];
if (matrix[j, k] == 0 || newdist < matrix[j, k])
uint olddist = matrix[j, k];
if (olddist == 0 || newdist < olddist)
{
matrix[j, k] = newdist;
yield return new(j, k, newdist, $"Updated distance between {GameApp.GetLabel(j)} and {GameApp.GetLabel(k)} to {newdist}");
yield return new(j, k, newdist, $"Updated distance between {GameApp.GetLabel(j)} and {GameApp.GetLabel(k)} to {newdist} instead of {(olddist != 0 ? olddist.ToString() : "INF")}");
}
}
}
Expand Down

0 comments on commit 479490e

Please sign in to comment.