| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using PathfindingPCL;
- namespace PathfindingConsole
- {
- class MainProgram : IHM
- {
- static void Main(string[] _args)
- {
- MainProgram p = new MainProgram();
- p.Run();
-
- while (true) ;
- }
- private void Run()
- {
- // 1ère carte
- String mapStr = ".. XX .\n"
- + "*. *X *.\n"
- + " . XX ...\n"
- + " .* X *.* \n"
- + " ...=... \n"
- + " .* X \n"
- + " . XXX* \n"
- + " . * = \n"
- + " .... XX \n"
- + " *. X* ";
- Map map = new Map(mapStr, 0, 0, 9, 9);
- RunAllAlgorithms(map);
- // 2ème carte
- mapStr = "...* X .* * \n"
- + " *..* *X .........\n"
- + " . = *.* *.\n"
- + " *. * XXXX . .\n"
- + "XXX=XX X *XX=XXX*.\n"
- + " *.*X = X*. X \n"
- + " . X * X X . *X* \n"
- + "* .*XX=XX *X . XXXX\n"
- + " .... .... X . X \n"
- + " . *....* . X*. = * ";
- map = new Map(mapStr, 0, 0, 9, 19);
- RunAllAlgorithms(map);
- }
- private void RunAllAlgorithms(Graph _graph)
- {
- // Résolution par une recherche en profondeur
- RunAlgorithm("Depth-First", _graph);
- // Résolution par une recherche en largeur
- RunAlgorithm("Breadth-First", _graph);
- // Résolution par Bellman-Ford
- RunAlgorithm("Bellman-Ford", _graph);
- // Résolution par Dijkstra
- RunAlgorithm("Dijkstra", _graph);
- // Résolution par A*
- RunAlgorithm("A*", _graph);
- }
- private void RunAlgorithm(string _algoName, Graph _graph)
- {
- // Variables
- DateTime beginning;
- DateTime end;
- TimeSpan duration;
- Algorithm algo = null;
- // Création de l'algorithme
- switch (_algoName)
- {
- case "Depth-First":
- algo = new DepthFirst(_graph, this);
- break;
- case "Breadth-First" :
- algo = new BreadthFirst(_graph, this);
- break;
- case "Bellman-Ford" :
- algo = new BellmanFord(_graph, this);
- break;
- case "Dijkstra":
- algo = new Dijkstra(_graph, this);
- break;
- case "A*":
- algo = new AStar(_graph, this);
- break;
- }
-
- // Résolution
- Console.Out.WriteLine("Algorithme : " + _algoName);
- beginning = DateTime.Now;
- algo.Solve();
- end = DateTime.Now;
- duration = end - beginning;
- Console.Out.WriteLine("Durée (ms) : " + duration.TotalMilliseconds.ToString() + "\n");
- }
- public void PrintResult(String _path, double _distance)
- {
- Console.Out.WriteLine("Chemin (taille : " + _distance + ") : " + _path);
- }
- }
- }
|