- Timestamp:
- 08/20/12 17:32:19 (12 years ago)
- Location:
- branches/RoutePlanning
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3/DijkstraAlgorithmV2.cs
r8481 r8509 53 53 54 54 #endregion 55 56 public long GetNodeIdWithRank(long sourceNodeId, int rank) { 57 visitedNodes = new HashSet<long>(); // visited 58 unvisitedNodes = new HashSet<long>(); // unvisited 59 distances = new Dictionary<long, float>(); 60 predecessors = new Dictionary<long, long>(); 61 int currentRank = 0; 62 63 64 long currentNode = sourceNodeId; 65 distances.Add(currentNode, 0); 66 unvisitedNodes.Add(currentNode); 67 68 while (unvisitedNodes.Count > 0) { 69 currentNode = GetMinimumDistance(unvisitedNodes); 70 visitedNodes.Add(currentNode); 71 unvisitedNodes.Remove(currentNode); 72 currentRank++; 73 if (currentRank == rank) { 74 break; 75 } 76 FindMinimalWeight(currentNode); 77 } 78 return currentNode; 79 } 55 80 56 81 private long GetMinimumDistance(HashSet<long> nodeIds) { -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning.Test/Program.cs
r8504 r8509 1 1 2 2 using System; 3 using System.Collections.Generic; 3 4 using System.Diagnostics; 4 5 using System.IO; 6 using System.Linq; 5 7 using System.Xml; 6 8 using HeuristicLab.Algorithms.GraphRouting; … … 28 30 29 31 //IDataSource ds = TestLoad(typeof(XmlDataSource), file7); 30 IDataSource ds = TestLoad(typeof(OsmDataSource), file5); 31 OsmGraph graph = new OsmGraph(ds); 32 IDataSource ds = TestLoad(typeof(OsmDataSource), file6); 33 //OsmGraph graph = new OsmGraph(ds); 34 32 35 //IGraph graphNew = TestGetRoutingGraph(ds); 36 //ExecuteBenchmark(graphNew, typeof(AStarAlgorithmV3), 2048, 1000); 33 37 34 38 //IDataSource ds = new DIMACSDataSource(fileNYCoords, fileNYArcs); 35 39 //IDataSource ds = new OsmDataSource(file5); 36 40 37 TestRouter(new DijkstraAlgorithm(graph), 529102170, 1001363194, true);41 //TestRouter(new DijkstraAlgorithm(graph), 529102170, 1001363194, true); 38 42 //TestRouter(new DijkstraAlgorithmV2(graphNew), 529102170, 1001363194, true); 39 TestRouter(new DijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb43 //TestRouter(new DijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb 40 44 //TestRouter(new DijkstraAlgorithmV2(graphNew), 529102170, 31372732, false); // inz - hgb 41 TestRouter(new BidrectionalDijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb45 //TestRouter(new BidrectionalDijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb 42 46 //TestRouter(new BidrectionalDijkstraAlgorithmV2(graphNew), 529102170, 31372732, false); // inz - hgb 43 47 //TestRouter(new AStarAlgorithm(graph), 529102170, 31372732, false); // inz - hgb 44 TestRouter(new AStarAlgorithmV2(graph), 529102170, 31372732, false); // inz - hgb48 //TestRouter(new AStarAlgorithmV2(graph), 529102170, 31372732, false); // inz - hgb 45 49 //TestRouter(new AStarAlgorithmV3(graphNew), 529102170, 31372732, false); // inz - hgb 46 50 … … 73 77 //TestLoadAndRouterNew(file7, typeof(AStarAlgorithmV3), 346151602, 33196510, false, true); // bregenz (bahnhofstr) - wien (stepansplatz) 74 78 75 TestLoadAndRouter(file8, typeof(AStarAlgorithmV2), 32044987, 261576106, false, true); //vorarblberg79 //TestLoadAndRouter(file8, typeof(AStarAlgorithmV2), 32044987, 261576106, false, true); //vorarblberg 76 80 77 81 System.Console.Read(); … … 299 303 return graph; 300 304 } 305 306 private static List<Tuple<long, long>> GenerateSourceTargetPairs(IGraph graph, int locality, int noOfPairs) { 307 List<Tuple<long, long>> benchmarkPairs = new List<Tuple<long, long>>(); 308 Random r = new Random(); 309 DijkstraAlgorithmV2 dijkstra = new DijkstraAlgorithmV2(graph); 310 int vertexCount = graph.GetVertices().Count; 311 312 for (int i = 0; i < noOfPairs; i++) { 313 long startId = r.Next(); 314 Vertex s = graph.GetVertex(startId); 315 316 while (s == null) { 317 startId = r.Next(); 318 s = graph.GetVertex(startId); 319 } 320 long targetId = dijkstra.GetNodeIdWithRank(s.Id, locality); 321 Tuple<long, long> t = new Tuple<long, long>(startId, targetId); 322 benchmarkPairs.Add(t); 323 } 324 return benchmarkPairs; 325 } 326 327 private static void ExecuteBenchmark(IGraph graph, Type routerType, int locality, int noOfQueries) { 328 Console.WriteLine("Benchmark Routing Algrithm BEGIN ------------------"); 329 Stopwatch sw; 330 IRouter router = (IRouter)Activator.CreateInstance(routerType, graph); 331 332 Console.Write("Generate queries ... "); 333 List<Tuple<long, long>> queries = GenerateSourceTargetPairs(graph, locality, noOfQueries); 334 Console.WriteLine("done."); 335 336 Console.Write("Execute benchmark ... "); 337 List<TimeSpan> times = new List<TimeSpan>(noOfQueries); 338 foreach (Tuple<long, long> pair in queries) { 339 sw = Stopwatch.StartNew(); 340 long[] result = router.Calculate(pair.Item1, pair.Item2); 341 sw.Stop(); 342 times.Add(sw.Elapsed); 343 } 344 Console.WriteLine("done.\n"); 345 346 Console.WriteLine("Results:"); 347 PrintStatistics(times); 348 349 Console.WriteLine("==================================================="); 350 } 351 352 private static void PrintStatistics(List<TimeSpan> times) { 353 long averageTicks = Convert.ToInt64(times.Average(timeSpan => timeSpan.Ticks)); 354 TimeSpan avg = new TimeSpan(averageTicks); 355 TimeSpan min = times.Min(); 356 TimeSpan max = times.Max(); 357 TimeSpan total = times.Aggregate(TimeSpan.Zero, (sum, value) => sum.Add(value)); 358 359 Console.WriteLine("Min:\t" + min); 360 Console.WriteLine("Max:\t" + max); 361 Console.WriteLine("Avg:\t" + avg); 362 Console.WriteLine("Total:\t" + total); 363 Console.WriteLine("Count:\t" + times.Count); 364 365 } 301 366 } 302 367 } -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/Graph.cs
r8479 r8509 25 25 vertices.TryGetValue(id, out vertex); 26 26 return vertex; 27 } 28 29 public List<Vertex> GetVertices() { 30 return new List<Vertex>(vertices.Values); 27 31 } 28 32 -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/IGraph.cs
r8479 r8509 5 5 void AddVertex(Vertex vertex); 6 6 Vertex GetVertex(long id); 7 List<Vertex> GetVertices(); 7 8 void AddEdge(long startId, long endId); 8 9 void AddEdge(Edge<Vertex> edge); -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm.Data/OsmDataSource.cs
r8504 r8509 141 141 NameTable nt = new NameTable(); 142 142 string osmName = nt.Add("osm"); 143 stringnodeName = nt.Add("node");143 object nodeName = nt.Add("node"); 144 144 object tagName = nt.Add("tag"); 145 145 object wayName = nt.Add("way"); … … 147 147 string lonName = nt.Add("lon"); 148 148 string idName = nt.Add("id"); 149 stringndName = nt.Add("nd");149 object ndName = nt.Add("nd"); 150 150 string refName = nt.Add("ref"); 151 151 string kName = nt.Add("k"); … … 166 166 167 167 reader.Read(); 168 if (reader.LocalName.Equals(tagName)) { 169 reader.ReadToFollowing(nodeName, ns); 170 } 171 } 172 while (reader.LocalName.Equals(wayName)) { 168 //if (reader.LocalName.Equals(tagName)) { 169 if (ReferenceEquals(tagName, reader.LocalName)) { 170 reader.ReadToFollowing((string)nodeName, ns); 171 } 172 } 173 //while (reader.LocalName.Equals(wayName)) { 174 while (ReferenceEquals(wayName, reader.LocalName)) { 173 175 List<Vertex> way = new List<Vertex>(); 174 176 bool missingNodes = false; … … 177 179 178 180 reader.Read(); 179 while ( reader.LocalName.Equals(nodeName) || reader.LocalName.Equals(tagName)) {181 while (ReferenceEquals(ndName, reader.LocalName) || ReferenceEquals(tagName, reader.LocalName)) { 180 182 if (reader.LocalName.Equals(ndName)) { 181 183 long refNodeId = XmlConvert.ToInt64(reader.GetAttribute(refName, ns));
Note: See TracChangeset
for help on using the changeset viewer.