Program.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Eppstein
  5. {
  6. /// <summary>
  7. /// Main application class
  8. /// </summary>
  9. class Program
  10. {
  11. /// <summary>
  12. /// Entry point
  13. /// </summary>
  14. /// <param name="args">arguments list, not used</param>
  15. static void Main(string[] args)
  16. {
  17. Graph g = new Graph();
  18. g.CreateVertices("S,A,B,C,D,E,F,G,H,I,J,K,T");
  19. // Edges in Original Eppstein example (1997)
  20. g.CreateEdges("S", "A", 2, "alpha");
  21. g.CreateEdges("A,E", "B,I", 20, "alpha");
  22. g.CreateEdges("B,B", "C,F", 14, "alpha");
  23. g.CreateEdges("D", "E", 9, "alpha");
  24. g.CreateEdges("E", "F", 10, "alpha");
  25. g.CreateEdges("F", "G", 25, "alpha");
  26. g.CreateEdges("H", "I", 18, "alpha");
  27. g.CreateEdges("I", "J", 8, "alpha");
  28. g.CreateEdges("J", "T", 11, "alpha");
  29. g.CreateEdges("S", "D", 13, "alpha");
  30. g.CreateEdges("A", "E", 27, "alpha");
  31. g.CreateEdges("C,D", "G,H", 15, "alpha");
  32. g.CreateEdges("F", "J", 12, "alpha");
  33. g.CreateEdges("G", "T", 7, "alpha");
  34. // Additional edges for special cases testing
  35. g.CreateEdges("E", "J", 30, "beta"); // Diagonal edge
  36. g.CreateEdges("F", "T", 35, "beta"); // Diagonal edge
  37. g.CreateEdges("J", "K", 5, "beta"); // Edge not pointing to shortest path
  38. g.CreateEdges("C", "C", 16, "beta"); // Cycling edge
  39. // g.EdgeGroupWeights("beta", -1);
  40. Console.WriteLine("EPPSTEIN ALGORITHM TEST");
  41. System.Diagnostics.Stopwatch stp = new System.Diagnostics.Stopwatch();
  42. stp.Start();
  43. Path p = g.FindShortestPath("S", "T");
  44. stp.Stop();
  45. Console.ForegroundColor = ConsoleColor.Green;
  46. Console.WriteLine("Calculation time: " + stp.ElapsedMilliseconds + " ms");
  47. Console.ResetColor();
  48. while (p.IsValid) // This can be replaced by something like: while (p!=null)
  49. {
  50. Console.WriteLine(p.VertexNames + " (" + p.Weight + ")");
  51. p = g.FindNextShortestPath();
  52. }
  53. Console.WriteLine("End.");
  54. Console.ReadKey();
  55. }
  56. }
  57. }