MainProgram.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using PathfindingPCL;
  3. namespace PathfindingConsole
  4. {
  5. class MainProgram : IHM
  6. {
  7. static void Main(string[] _args)
  8. {
  9. MainProgram p = new MainProgram();
  10. p.Run();
  11. while (true) ;
  12. }
  13. private void Run()
  14. {
  15. // 1ère carte
  16. String mapStr = ".. XX .\n"
  17. + "*. *X *.\n"
  18. + " . XX ...\n"
  19. + " .* X *.* \n"
  20. + " ...=... \n"
  21. + " .* X \n"
  22. + " . XXX* \n"
  23. + " . * = \n"
  24. + " .... XX \n"
  25. + " *. X* ";
  26. Map map = new Map(mapStr, 0, 0, 9, 9);
  27. RunAllAlgorithms(map);
  28. // 2ème carte
  29. mapStr = "...* X .* * \n"
  30. + " *..* *X .........\n"
  31. + " . = *.* *.\n"
  32. + " *. * XXXX . .\n"
  33. + "XXX=XX X *XX=XXX*.\n"
  34. + " *.*X = X*. X \n"
  35. + " . X * X X . *X* \n"
  36. + "* .*XX=XX *X . XXXX\n"
  37. + " .... .... X . X \n"
  38. + " . *....* . X*. = * ";
  39. map = new Map(mapStr, 0, 0, 9, 19);
  40. RunAllAlgorithms(map);
  41. }
  42. private void RunAllAlgorithms(Graph _graph)
  43. {
  44. // Résolution par une recherche en profondeur
  45. RunAlgorithm("Depth-First", _graph);
  46. // Résolution par une recherche en largeur
  47. RunAlgorithm("Breadth-First", _graph);
  48. // Résolution par Bellman-Ford
  49. RunAlgorithm("Bellman-Ford", _graph);
  50. // Résolution par Dijkstra
  51. RunAlgorithm("Dijkstra", _graph);
  52. // Résolution par A*
  53. RunAlgorithm("A*", _graph);
  54. }
  55. private void RunAlgorithm(string _algoName, Graph _graph)
  56. {
  57. // Variables
  58. DateTime beginning;
  59. DateTime end;
  60. TimeSpan duration;
  61. Algorithm algo = null;
  62. // Création de l'algorithme
  63. switch (_algoName)
  64. {
  65. case "Depth-First":
  66. algo = new DepthFirst(_graph, this);
  67. break;
  68. case "Breadth-First" :
  69. algo = new BreadthFirst(_graph, this);
  70. break;
  71. case "Bellman-Ford" :
  72. algo = new BellmanFord(_graph, this);
  73. break;
  74. case "Dijkstra":
  75. algo = new Dijkstra(_graph, this);
  76. break;
  77. case "A*":
  78. algo = new AStar(_graph, this);
  79. break;
  80. }
  81. // Résolution
  82. Console.Out.WriteLine("Algorithme : " + _algoName);
  83. beginning = DateTime.Now;
  84. algo.Solve();
  85. end = DateTime.Now;
  86. duration = end - beginning;
  87. Console.Out.WriteLine("Durée (ms) : " + duration.TotalMilliseconds.ToString() + "\n");
  88. }
  89. public void PrintResult(String _path, double _distance)
  90. {
  91. Console.Out.WriteLine("Chemin (taille : " + _distance + ") : " + _path);
  92. }
  93. }
  94. }