0

I'm doing a graph program in C# which uses the Dijkstra algorithm to find the shortest path between nodes but I need to export the time it takes between each node to an excel file. I really haven't been able to come up with something or find any information about it. Any ideas on how to do this?Here's the code for it.(verticesCount is a vertex count used in other parts of the program)

    public static void Dijkstra(int[,] graph, int source, int verticesCount)
            {
                int[] distance = new int[verticesCount];
                bool[] shortestPathTreeSet = new bool[verticesCount];

                for (int i = 0; i < verticesCount; ++i)
                {
                    distance[i] = int.MaxValue;
                    shortestPathTreeSet[i] = false;
                }

        distance[source] = 0;

        for (int count = 0; count < verticesCount - 1; ++count)
        {
            int u = MinimumDistance(distance, shortestPathTreeSet, verticesCount);
            shortestPathTreeSet[u] = true;

            for (int v = 0; v < verticesCount; ++v)
                if (!shortestPathTreeSet[v] && Convert.ToBoolean(graph[u, v]) && distance[u] != int.MaxValue && distance[u] + graph[u, v] < distance[v])
                    distance[v] = distance[u] + graph[u, v];
        }

        Print(distance, verticesCount);
    }

1 Answers1

0

You can use the Stopwatch class to count the elapsed time between two or more desired parts. See Stopwatch class Also, you can write to a CSV file to open it with excel. See an example: Write to a CSV file

Community
  • 1
  • 1
Josep B.
  • 587
  • 1
  • 6
  • 16