Example #1
0
        public static void DisplayShortestPathes(string outputDirectory, ulong startId, IEnumerable <ulong> goals,
                                                 IReadOnlyDictionary <ulong, ulong> ancestors)
        {
            var lines = File.ReadAllLines(Path.Combine(outputDirectory, "map.svg")).SkipLast(1).ToList();

            File.WriteAllLines(Path.Combine(outputDirectory, "pathes.svg"), lines);
            using (var output = new StreamWriter(Path.Combine(outputDirectory, "pathes.svg"), true))
            {
                string[] coordinates;
                foreach (var goalId in goals.Skip(1))
                {
                    output.WriteLine($"<polyline points=\"{string.Join(", ", DistanceHelper.RestorePath(startId, goalId, ancestors).Select(x => GeoHelper.ConvertToGeo(Dictionary[x])))}\" " +
                                     "stroke=\"darkcyan\" fill=\"transparent\" stroke-width=\"2\"/>");
                    coordinates = GeoHelper.ConvertToGeo(Dictionary[goalId]).Split();
                    output.WriteLine($"<circle cx=\"{coordinates.First()}\" cy=\"{coordinates.Last()}\" r=\"3\" fill=\"navy(16)\" />");
                }
                output.WriteLine($"<polyline points=\"{string.Join(", ", DistanceHelper.RestorePath(startId, goals.First(), ancestors).Select(x => GeoHelper.ConvertToGeo(Dictionary[x])))}\" " +
                                 "stroke=\"cornflowerblue\" fill=\"transparent\" stroke-width=\"2.5\"/>");
                coordinates = GeoHelper.ConvertToGeo(Dictionary[goals.First()]).Split();
                output.WriteLine($"<circle cx=\"{coordinates.First()}\" cy=\"{coordinates.Last()}\" r=\"3.5\" fill=\"mediumblue\" />");
                coordinates = GeoHelper.ConvertToGeo(Dictionary[startId]).Split();
                output.WriteLine($"<circle cx=\"{coordinates.First()}\" cy=\"{coordinates.Last()}\" r=\"4\" fill=\"limegreen\" />");
                output.WriteLine("</svg>");
            }
        }
Example #2
0
 public static void WriteShortestPathes(string outputDirectory, ulong startId, IEnumerable <ulong> goals, IReadOnlyDictionary <ulong, double> distances, IReadOnlyDictionary <ulong, ulong> ancestors)
 {
     using (var pathWriter = new StreamWriter(Path.Combine(outputDirectory, "shrotest_pathes.csv")))
     {
         pathWriter.WriteLine("Start id, Goal id, Distance, Estimated time by car, Nodes id in shortest path");
         foreach (var goalId in goals)
         {
             double time    = distances[goalId] / 40;
             int    hours   = (int)time;
             double m       = (time - hours) * 60;
             int    minutes = (int)m;
             int    seconds = (int)Math.Round((m - minutes) * 60);
             pathWriter.WriteLine($"{startId}, {goalId}, {distances[goalId]}, {new TimeSpan(hours, minutes, seconds).ToString()}, [{string.Join("->", DistanceHelper.RestorePath(startId, goalId, ancestors))}]");
         }
     }
 }