- Timestamp:
- 08/22/12 11:46:08 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning.Test/Program.cs
r8514 r8516 7 7 using System.Xml; 8 8 using HeuristicLab.Algorithms.GraphRouting; 9 using HeuristicLab.Problems.RoutePlanning.Graph; 10 using HeuristicLab.Problems.RoutePlanning.Osm; 11 using HeuristicLab.Problems.RoutePlanning.Osm.Data; 9 using HeuristicLab.Algorithms.GraphRouting.Interfaces; 10 using HeuristicLab.Problems.RoutePlanning.Data.DIMACS; 11 using HeuristicLab.Problems.RoutePlanning.Data.Osm; 12 using HeuristicLab.Problems.RoutePlanning.Interfaces; 13 using HeuristicLab.Problems.RoutePlanning.RoutingGraph; 14 15 // For testing openstreetmap data is used 16 // http://www.openstreetmap.org 17 // Map data © OpenStreetMap contributors, CC BY-SA 18 12 19 namespace HeuristicLab.Problems.RoutePlanning.Test { 13 20 class Program { 14 21 static void Main(string[] args) { 15 // For testing openstreetmap data is used16 // http://www.openstreetmap.org17 // Map data © OpenStreetMap contributors, CC BY-SA18 19 22 string file1 = @"..\..\OsmTestFiles\test.osm"; 20 23 string file2 = @"..\..\OsmTestFiles\testNode1.osm"; 21 24 string file3 = @"..\..\OsmTestFiles\testWay1.osm"; 22 25 string file4 = @"..\..\OsmTestFiles\testRelation1.osm"; 23 string file5 = @" ..\..\OsmTestFiles\test_mid.osm";26 string file5 = @"C:\dev\osmfiles\test_mid.osm"; 24 27 string file6 = @"C:\dev\osmfiles\oberosterreich.highway.osm"; 25 28 string file7 = @"C:\dev\osmfiles\austria.highway.osm"; … … 29 32 string fileNYCoords = @"C:\dev\DIMACSfiles\USA-road-d.NY.co.gz"; 30 33 31 //IDataSource ds = TestLoad(typeof(XmlDataSource), file7); 32 //IDataSource ds = TestLoad(typeof(OsmDataSource), file6); 33 //OsmGraph graph = new OsmGraph(ds); 34 35 //IGraph graphNew = TestGetRoutingGraph(ds); 36 //ExecuteBenchmark(graphNew, typeof(AStarAlgorithmV3), 262144, 20); 37 38 //IRouter router = new AStarAlgorithmV3(graphNew); 34 IDataSource ds1 = TestLoad(typeof(OsmDataSource), file6); 35 IDataSource ds2 = TestLoad(typeof(DIMACSDataSource), fileNYCoords, fileNYArcs); 36 37 //IGraph graph = TestGetRoutingGraph(ds1); 38 //ExecuteBenchmark(graph, typeof(AStarAlgorithmV3), 262144, 20); 39 40 //IRouter router = new AStarAlgorithmV3(graph); 39 41 //long[] r = router.Calculate(266733493, 986825165); 40 ////long[] r = router.Calculate(998717680, 986825165); 41 42 //IDataSource ds = new DIMACSDataSource(fileNYCoords, fileNYArcs); 43 //IDataSource ds = new OsmDataSource(file5); 44 45 //TestRouter(new DijkstraAlgorithm(graph), 529102170, 1001363194, true); 46 //TestRouter(new DijkstraAlgorithmV2(graphNew), 529102170, 1001363194, true); 47 //TestRouter(new DijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb 48 //TestRouter(new DijkstraAlgorithmV2(graphNew), 529102170, 31372732, false); // inz - hgb 49 //TestRouter(new BidrectionalDijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb 50 //TestRouter(new BidrectionalDijkstraAlgorithmV2(graphNew), 529102170, 31372732, false); // inz - hgb 51 //TestRouter(new AStarAlgorithm(graph), 529102170, 31372732, false); // inz - hgb 52 //TestRouter(new AStarAlgorithmV2(graph), 529102170, 31372732, false); // inz - hgb 53 //TestRouter(new AStarAlgorithmV3(graphNew), 529102170, 31372732, false); // inz - hgb 54 55 //TestRouter(new AStarAlgorithmV2(graph), 763113382, 1078628481, false); // bregenz (bahnhofstr) - podersdorf (??) 56 //TestRouter(new AStarAlgorithmV3(graphNew), 346151602, 33196510, false); // bregenz (bahnhofstr) - wien (stepansplatz) 57 //TestRouter(new AStarAlgorithmV2(graph), 346151602, 33196510, false); // bregenz (bahnhofstr) - wien (stepansplatz) 58 59 //TestRouter(new AStarAlgorithmV2(graph), 32044987, 261576106, false); //vorarblberg 60 //TestRouter(new AStarAlgorithmV3(graphNew), 32044987, 261576106, false); //vorarblberg 61 62 //TestLoadAndRouter(file6, typeof(DijkstraAlgorithm), 529102170, 31372732, false, false); // inz - hgb 63 //TestLoadAndRouter(file6, typeof(AStarAlgorithm), 529102170, 31372732, false, false); // inz - hgb 64 //TestLoadAndRouter(file6, typeof(AStarAlgorithmV2), 529102170, 31372732, false, true); // inz - hgb 65 66 //TestLoadAndRouter(file6, typeof(DijkstraAlgorithm), 529102170, 1001363194, true, false); 67 //TestLoadAndRouter(file6, typeof(DijkstraAlgorithm), 529102170, 1001363194, true, false); 68 //TestLoadAndRouter(file6, typeof(AStarAlgorithm), 529102170, 1001363194, true, false); 69 //TestLoadAndRouter(file6, typeof(AStarAlgorithmV2), 529102170, 1001363194, true, false); 70 //TestLoadAndRouter(file6, typeof(BidrectionalDijkstraAlgorithm), 529102170, 1001363194, true, false); 71 72 //TestLoadAndRouter(file5, typeof(DijkstraAlgorithm), 529102170, 1001363194, true, false); 73 //TestLoadAndRouter(file5, typeof(BidrectionalDijkstraAlgorithm), 529102170, 1001363194, true, true); 74 //TestLoadAndRouter(file6, typeof(BidrectionalDijkstraAlgorithm), 529102170, 31372732, false, true); // inz - hgb 75 76 TestLoadAndRouterNew(file6, typeof(AStarAlgorithmV3), 529102170, 31372732, false, true); // inz - hgb 77 //TestLoadAndRouterNew(file6, typeof(DijkstraAlgorithmV2), 529102170, 31372732, false, true); 78 //TestLoadAndRouterNew(file6, typeof(BidrectionalDijkstraAlgorithmV2), 529102170, 31372732, false, true); 79 //TestLoadAndRouterNew(file6, typeof(AStarAlgorithmV3), 529102170, 31372732, false, true); 80 81 //TestLoadAndRouter(file7, typeof(AStarAlgorithmV2), 346151602, 33196510, false, true); // bregenz (bahnhofstr) - wien (stepansplatz) 82 //TestLoadAndRouterNew(file7, typeof(AStarAlgorithmV3), 346151602, 33196510, false, true); // bregenz (bahnhofstr) - wien (stepansplatz) 83 84 //TestLoadAndRouter(file8, typeof(AStarAlgorithmV2), 32044987, 261576106, false, true); //vorarblberg 42 //long[] r = router.Calculate(998717680, 986825165); 43 44 //TestRouter(new DijkstraAlgorithmV2(graph), 529102170, 1001363194, true); // inz 45 46 //TestRouter(new DijkstraAlgorithmV2(graph), 529102170, 31372732, false); // inz - hgb 47 //TestRouter(new BidrectionalDijkstraAlgorithmV2(graph), 529102170, 31372732, false); // inz - hgb 48 //TestRouter(new AStarAlgorithmV3(graph), 529102170, 31372732, false); // inz - hgb 49 50 //TestRouter(new AStarAlgorithmV3(graph), 346151602, 33196510, false); // bregenz (bahnhofstr) - wien (stepansplatz) 51 52 //TestRouter(new AStarAlgorithmV3(graph), 32044987, 261576106, false); //vorarblberg 53 54 //TestLoadAndRouter(typeof(OsmDataSource), file6, typeof(AStarAlgorithmV3), 529102170, 31372732, false, true); // inz - hgb 55 //TestLoadAndRouter(typeof(OsmDataSource), file6, typeof(DijkstraAlgorithmV2), 529102170, 31372732, false, true); // inz - hgb 56 //TestLoadAndRouter(typeof(OsmDataSource), file6, typeof(BidrectionalDijkstraAlgorithmV2), 529102170, 31372732, false, true); // inz - hgb 57 //TestLoadAndRouter(typeof(OsmDataSource), file6, typeof(AStarAlgorithmV3), 529102170, 31372732, false, true); // inz - hgb 58 //TestLoadAndRouter(typeof(OsmDataSource), file7, typeof(AStarAlgorithmV3), 346151602, 33196510, false, true); // bregenz (bahnhofstr) - wien (stepansplatz) 85 59 86 60 System.Console.Read(); … … 126 100 } 127 101 128 private static void TestLoadAndRouter( string filepath, Type routerType, long sourceNodeId, long targetNodeId, bool showResult, bool writeResultFile) {102 private static void TestLoadAndRouter(Type dsType, string filepath, Type routerType, long sourceNodeId, long targetNodeId, bool showResult, bool writeResultFile) { 129 103 FileInfo file = new FileInfo(filepath); 130 104 Console.WriteLine("Test Load and Route BEGIN -------------------------"); … … 133 107 Console.Write("Loading data ... "); 134 108 var sw = Stopwatch.StartNew(); 135 XmlDataSource xmlDs = new XmlDataSource(filepath);109 IDataSource ds = (IDataSource)Activator.CreateInstance(dsType, filepath); 136 110 sw.Stop(); 137 111 Console.WriteLine("done."); 138 112 Console.WriteLine("Loading Time: {0}", sw.Elapsed); 139 113 Console.WriteLine(); 140 OsmGraph graph = new OsmGraph(xmlDs);114 IGraph graph = ds.GetRoutingGraph(); 141 115 IRouter router = (IRouter)Activator.CreateInstance(routerType, graph); 142 116 Console.Write("Calculate route ... "); … … 164 138 } 165 139 166 private static void TestLoadAndRouterNew(string filepath, Type routerType, long sourceNodeId, long targetNodeId, bool showResult, bool writeResultFile) { 167 FileInfo file = new FileInfo(filepath); 168 Console.WriteLine("Test Load and Route BEGIN -------------------------"); 169 Console.WriteLine("File name: {0}", file.Name); 170 Console.WriteLine(); 171 Console.Write("Loading data ... "); 172 var sw = Stopwatch.StartNew(); 173 //XmlDataSource xmlDs = new XmlDataSource(filepath); 174 IDataSource xmlDs = new OsmDataSource(filepath); 175 sw.Stop(); 176 Console.WriteLine("done."); 177 Console.WriteLine("Loading Time: {0}", sw.Elapsed); 178 Console.WriteLine(); 179 IGraph graph = xmlDs.GetRoutingGraph(); 180 IRouter router = (IRouter)Activator.CreateInstance(routerType, graph); 181 Console.Write("Calculate route ... "); 182 sw = Stopwatch.StartNew(); 183 long[] result = router.Calculate(sourceNodeId, targetNodeId); 184 sw.Stop(); 185 Console.WriteLine("done."); 186 Console.WriteLine("Execution Time: {0}", sw.Elapsed); 187 Console.WriteLine(); 188 if (showResult) { 189 Console.WriteLine("Result: "); 190 foreach (long i in result) System.Console.Write(i + "; "); 191 Console.WriteLine(); 192 Console.WriteLine(); 193 } 194 if (writeResultFile) { 195 string dt = DateTime.Now.ToString("yyyyMMddhhmmss_"); 196 string fn = Path.GetFileNameWithoutExtension(file.Name); 197 string resultFile = dt + fn + "_" + sourceNodeId + "-" + targetNodeId + ".gpx"; 198 Console.WriteLine("Result file: {0}", resultFile); 199 WriteGPXFileNew(graph, result, resultFile); 200 } 201 Console.WriteLine("==================================================="); 202 Console.WriteLine(); 203 } 204 205 private static void WriteGPXFile(OsmGraph graph, long[] route, string file) { 206 XmlWriterSettings settings = new XmlWriterSettings(); 207 settings.Indent = true; 208 settings.IndentChars = (" "); 209 210 using (XmlWriter writer = XmlWriter.Create(file, settings)) { 211 writer.WriteStartElement("gpx", "http://www.topografix.com/GPX/1/0"); 212 writer.WriteAttributeString("version", "1.1"); 213 writer.WriteAttributeString("creator", "cloudia"); 214 215 foreach (long nodeId in route) { 216 OsmVertex<Node> node = graph.GetVertex(nodeId); 217 writer.WriteStartElement("wpt"); 218 writer.WriteAttributeString("lat", XmlConvert.ToString(node.Node.Latitude)); 219 writer.WriteAttributeString("lon", XmlConvert.ToString(node.Node.Longitude)); 220 writer.WriteEndElement(); // wpt 221 } 222 223 //writer.WriteStartElement("rte"); 224 //foreach (long nodeId in route) { 225 // Vertex<Node> node = graph.GetVertex(nodeId); 226 // writer.WriteStartElement("rtept"); 227 // writer.WriteAttributeString("lat", XmlConvert.ToString(node.Node.Latitude)); 228 // writer.WriteAttributeString("lon", XmlConvert.ToString(node.Node.Longitude)); 229 // writer.WriteEndElement(); // rtept 230 //} 231 //writer.WriteEndElement(); // rte 232 233 //writer.WriteStartElement("trk"); 234 //writer.WriteElementString("name", "RoutePath"); 235 ////writer.WriteEndElement(); // name 236 //writer.WriteStartElement("trkseq"); 237 //foreach (long nodeId in route) { 238 // Vertex<Node> node = graph.GetVertex(nodeId); 239 // writer.WriteStartElement("trkpt"); 240 // writer.WriteAttributeString("lat", XmlConvert.ToString(node.Node.Latitude)); 241 // writer.WriteAttributeString("lon", XmlConvert.ToString(node.Node.Longitude)); 242 // writer.WriteEndElement(); // trkpt 243 //} 244 //writer.WriteEndElement(); // trkseq 245 //writer.WriteEndElement(); // trk 246 247 writer.WriteEndElement(); // gpx 248 } 249 } 250 251 private static void WriteGPXFileNew(IGraph graph, long[] route, string file) { 140 private static void WriteGPXFile(IGraph graph, long[] route, string file) { 252 141 XmlWriterSettings settings = new XmlWriterSettings(); 253 142 settings.Indent = true; … … 267 156 } 268 157 269 //writer.WriteStartElement("rte");270 //foreach (long nodeId in route) {271 // Vertex<Node> node = graph.GetVertex(nodeId);272 // writer.WriteStartElement("rtept");273 // writer.WriteAttributeString("lat", XmlConvert.ToString(node.Node.Latitude));274 // writer.WriteAttributeString("lon", XmlConvert.ToString(node.Node.Longitude));275 // writer.WriteEndElement(); // rtept276 //}277 //writer.WriteEndElement(); // rte278 279 //writer.WriteStartElement("trk");280 //writer.WriteElementString("name", "RoutePath");281 ////writer.WriteEndElement(); // name282 //writer.WriteStartElement("trkseq");283 //foreach (long nodeId in route) {284 // Vertex<Node> node = graph.GetVertex(nodeId);285 // writer.WriteStartElement("trkpt");286 // writer.WriteAttributeString("lat", XmlConvert.ToString(node.Node.Latitude));287 // writer.WriteAttributeString("lon", XmlConvert.ToString(node.Node.Longitude));288 // writer.WriteEndElement(); // trkpt289 //}290 //writer.WriteEndElement(); // trkseq291 //writer.WriteEndElement(); // trk292 293 158 writer.WriteEndElement(); // gpx 294 159 }
Note: See TracChangeset
for help on using the changeset viewer.