public void testPerf(Graph g) { long milliseconds; Stopwatch stopDij = new Stopwatch(); stopDij.Start(); Dijkstra dj = new Dijkstra(g, g.getNodeAt(0)); stopDij.Stop(); milliseconds = stopDij.ElapsedMilliseconds; Console.WriteLine("Dijkstra : " + milliseconds + " ms"); Stopwatch stopBell = new Stopwatch(); stopBell.Start(); Bellman bm = new Bellman(g, g.getNodeAt(0)); stopBell.Stop(); milliseconds = stopBell.ElapsedMilliseconds; Console.WriteLine("Bellman : " + milliseconds + " ms"); Stopwatch stopDFS = new Stopwatch(); stopDFS.Start(); DepthFirst dfs = new DepthFirst(g , g.getNodeAt(0)); stopDFS.Stop(); milliseconds = stopDFS.ElapsedMilliseconds; Console.WriteLine("DFS : " + milliseconds + " ms"); Stopwatch stopFloyd = new Stopwatch(); stopFloyd.Start(); Floyd fl = new Floyd(g); stopFloyd.Stop(); milliseconds = stopFloyd.ElapsedMilliseconds; Console.WriteLine("Floyd : " + milliseconds + " ms"); }
static void Main(string[] args) { /* Object[,] graphComponent = new Object[,] { {"Paris", int.MaxValue, 1, int.MaxValue, int.MaxValue, 11, int.MaxValue, int.MaxValue}, {"Bordeaux", int.MaxValue, int.MaxValue, 5, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue}, {"Bayonne", int.MaxValue, int.MaxValue, int.MaxValue, 5, int.MaxValue, int.MaxValue, int.MaxValue}, {"Pau", 3, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, 3}, {"Bangkok", int.MaxValue, int.MaxValue, int.MaxValue,int.MaxValue, int.MaxValue, 8, 13}, {"Yangon", int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, 3, int.MaxValue, int.MaxValue}, {"Tarbes", int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue , int.MaxValue}, }; */ Object[,] graphComponent = new Object[,] { {"Paris", 0, 1, 10, 3, int.MaxValue, int.MaxValue, int.MaxValue}, {"Bordeaux", 4, 0, 3, 1, int.MaxValue, int.MaxValue, 5}, {"Pau", 3, 7, 0, 1, int.MaxValue, 10, int.MaxValue}, {"Bangkok", 52, 4, 1, 0, 8, int.MaxValue, int.MaxValue}, {"Yangon", int.MaxValue, int.MaxValue, int.MaxValue, 8, int.MaxValue, int.MaxValue, int.MaxValue}, {"Tarbes", int.MaxValue, 5, int.MaxValue, int.MaxValue, int.MaxValue, 0, int.MaxValue}, {"Bayonne", int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue, 0}, }; Graph g = new Graph(graphComponent); g.display(); g.displayCurrentMatrix(); SaveManager sm = new SaveManager(); sm.saveGraph(g); StronglyConnectedComponent scc = new StronglyConnectedComponent(); scc.displaySCC(g); /* Actions a = new Actions(); a.testPerf(g); */ Bellman bm = new Bellman(g, g.getNodeAt(0)); bm.display(); Dijkstra dj = new Dijkstra(g, g.getNodeAt(0)); dj.display(); /* * Floyd flo = new Floyd(g); flo.display(); * DepthFirst dfs = new DepthFirst(g, g.getNodeAt(0)); dfs.displayDFSPath(); TreeDepthFirst tdfs = new TreeDepthFirst(g, g.getNodeAt(0)); Graph zi = tdfs.getDFSGraph(); zi.display(); */ }
public void generateMatrix(Graph g) { int dim = g.getNodeList().Count(); Object[,] matrixC = new Object[dim, dim + 1]; //+1 <=> colonne ajoutée pour les noms //On ajoute les noms de noeuds à la matrice for (int i = 0; i < dim; i++) matrixC[i, 0] = g.getNodeAt(i).getName(); //On remplit les cases connues foreach (Node n in g.getNodeList()) { foreach (Arc a in n.getEgressArc()) { int x = a.getOrigin().getIndex(); int y = a.getEdge().getIndex(); setValueAt(matrixC, a.getCost(), x, y+1); } } //On remplie les cases inconnues for (int i = 0; i < dim; i++) { for (int j = 1; j < dim + 1; j++) { if(matrixC[i, j]==null) { if (i + 1 == j) matrixC[i, j] = 0; else matrixC[i, j] = int.MaxValue; } } } this.costMatrix = matrixC; refreshCalcM(); }