We were encountering this Graph problem and we needed to implement Floyd Warshall, So we did. Although we kinda disliked the algorithm because it is very slow.
We would like to know if it's possible to apply parallel linq on the second loop, so we can speed up the algorithm a little
Question: Speed up the For loop with var
i
private int[,] FloydWarshall(int[,] matrix)
{
var loopCount = matrix.GetLength(0);
var next = CreatePredecessorMatrix(matrix);
for (var k = 0; k < loopCount; k++)
{
for (var i = 0; i < loopCount; i++)
{
for (var j = 0; j < loopCount; j++)
{
if (matrix[i, j] > matrix[i, k] + matrix[k, j])
{
matrix[i, j] = matrix[i, k] + matrix[k, j];
next[i, j] = next[k, j];
}
}
}
}
return next;
}