Changeset 8316
- Timestamp:
- 07/21/12 23:49:56 (12 years ago)
- Location:
- branches/RoutePlanning
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning.Test/Program.cs
r8315 r8316 1 1 2 2 using System; 3 using System.Diagnostics; 4 using System.IO; 3 5 using System.Xml; 4 6 using HeuristicLab.Algorithms.GraphRouting; … … 9 11 class Program { 10 12 static void Main(string[] args) { 11 Test1(); 12 } 13 string file1 = @"..\..\OsmTestFiles\test.osm"; 14 string file2 = @"..\..\OsmTestFiles\testNode1.osm"; 15 string file3 = @"..\..\OsmTestFiles\testWay1.osm"; 16 string file4 = @"..\..\OsmTestFiles\testRelation1.osm"; 17 string file5 = @"..\..\OsmTestFiles\test_mid.osm"; 18 string file6 = @"C:\dev\osmfiles\oberosterreich.highway.osm"; 13 19 14 private static void Test1() { 15 string filepath = @"..\..\OsmTestFiles\test_mid.osm"; 16 17 Console.Write("Loading data ... "); 18 XmlDataSource xmlDs = new XmlDataSource(filepath); 19 Console.WriteLine("done."); 20 21 Graph.Graph graph = new Graph.Graph(xmlDs); 22 IRouter router = new DijkstraAlgorithm(graph); 23 24 Console.Write("Calculate route ... "); 25 long[] result = router.Calculate(529102170, 1001363194); 26 System.Console.WriteLine("done."); 27 28 Console.Write("Result: "); 29 foreach (long i in result) System.Console.Write(i + "; "); 30 Console.WriteLine(); 31 32 WriteGPXFile(graph, result); 33 20 Test(file5, 529102170, 1001363194, true, false); 21 //Test(file6, 529102170, 1001363194, true, false); 22 //Test(file6, 529102170, 31372732, false, true); // inz - hgb 34 23 System.Console.Read(); 35 24 } 36 25 37 private static void Test2() { 38 //string filepath = @"..\..\OsmTestFiles\test.osm"; 39 //string filepath = @"..\..\OsmTestFiles\testNode1.osm"; 40 //string filepath = @"..\..\OsmTestFiles\testWay1.osm"; 41 //string filepath = @"..\..\OsmTestFiles\testRelation1.osm"; 42 string filepath = @"..\..\OsmTestFiles\test_mid.osm"; 43 26 private static void Test(string filepath, long sourceNodeId, long targetNodeId, bool showResult, bool writeResultFile) { 27 FileInfo file = new FileInfo(filepath); 28 Console.WriteLine("Test BEGIN ------------------------------"); 29 Console.WriteLine("File name: {0}", file.Name); 30 Console.WriteLine(); 44 31 Console.Write("Loading data ... "); 32 var sw = Stopwatch.StartNew(); 45 33 XmlDataSource xmlDs = new XmlDataSource(filepath); 34 sw.Stop(); 46 35 Console.WriteLine("done."); 47 36 Console.WriteLine("Loading Time: {0}", sw.Elapsed); 37 Console.WriteLine(); 48 38 Graph.Graph graph = new Graph.Graph(xmlDs); 49 39 IRouter router = new DijkstraAlgorithm(graph); 50 51 40 Console.Write("Calculate route ... "); 52 long[] result = router.Calculate(529102170, 1001363194);53 System.Console.WriteLine("done.");54 55 Console.Write ("Result:");56 foreach (long i in result) System.Console.Write(i + "; ");41 sw = Stopwatch.StartNew(); 42 long[] result = router.Calculate(sourceNodeId, targetNodeId); 43 sw.Stop(); 44 Console.WriteLine("done."); 45 Console.WriteLine("Execution Time: {0}", sw.Elapsed); 57 46 Console.WriteLine(); 58 System.Console.Read(); 47 if (showResult) { 48 Console.WriteLine("Result: "); 49 foreach (long i in result) System.Console.Write(i + "; "); 50 Console.WriteLine(); 51 Console.WriteLine(); 52 } 53 if (writeResultFile) { 54 string dt = DateTime.Now.ToString("yyyyMMddhhmmss_"); 55 string fn = Path.GetFileNameWithoutExtension(file.Name); 56 string resultFile = dt + fn + "_" + sourceNodeId + "-" + targetNodeId + ".gpx"; 57 Console.WriteLine("Result file: {0}", resultFile); 58 WriteGPXFile(graph, result, resultFile); 59 } 60 Console.WriteLine("========================================="); 61 Console.WriteLine(); 59 62 } 60 63 61 private static void WriteGPXFile(Graph.Graph graph, long[] route ) {64 private static void WriteGPXFile(Graph.Graph graph, long[] route, string file) { 62 65 XmlWriterSettings settings = new XmlWriterSettings(); 63 66 settings.Indent = true; 64 67 settings.IndentChars = (" "); 65 68 66 using (XmlWriter writer = XmlWriter.Create( "RoutePath.gpx", settings)) {69 using (XmlWriter writer = XmlWriter.Create(file, settings)) { 67 70 writer.WriteStartElement("gpx", "http://www.topografix.com/GPX/1/0"); 68 71 writer.WriteAttributeString("version", "1.1"); -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm.Data/XmlDataSource.cs
r8300 r8316 91 91 using (XmlReader reader = XmlReader.Create(file.FullName, settings)) { 92 92 reader.ReadStartElement("osm"); 93 reader.ReadStartElement("bounds"); 93 //reader.ReadStartElement("bounds"); 94 reader.Read(); 94 95 while (reader.LocalName.Equals("node")) { 95 96 Node node = new Node(); … … 119 120 GetBaseAttributes(reader, way); 120 121 reader.Read(); 122 bool missingNodes = false; 121 123 while (reader.LocalName.Equals("nd") || reader.LocalName.Equals("tag")) { 122 124 if (reader.LocalName.Equals("nd")) { 123 125 long refNodeId = XmlConvert.ToInt64(reader.GetAttribute("ref")); 124 way.Nodes.Add(GetNode(refNodeId)); 126 Node refNode = GetNode(refNodeId); 127 if (refNode != null) { 128 way.Nodes.Add(refNode); 129 } else { 130 missingNodes = true; 131 } 125 132 126 133 } else if (reader.LocalName.Equals("tag")) { … … 131 138 reader.Read(); 132 139 } 133 140 if (missingNodes) { 141 // TODO: Error/Trace output 142 // if Way xxx has incomplete nodes. At least one node was missing in the data. 143 } 134 144 ways.Add(way.Id, way); 135 145 InsertNodeWayRelation(way); … … 181 191 obj.UserId = XmlConvert.ToInt32(reader.GetAttribute("uid")); 182 192 } 183 obj.Visible = XmlConvert.ToBoolean(reader.GetAttribute("visible")); 184 obj.Version = XmlConvert.ToInt32(reader.GetAttribute("version")); 185 obj.Changeset = XmlConvert.ToInt64(reader.GetAttribute("changeset")); 186 obj.Timestamp = XmlConvert.ToDateTime(reader.GetAttribute("timestamp"), XmlDateTimeSerializationMode.Utc); 193 if (reader.GetAttribute("visible") != null) { 194 obj.Visible = XmlConvert.ToBoolean(reader.GetAttribute("visible")); 195 } 196 if (reader.GetAttribute("version") != null) { 197 obj.Version = XmlConvert.ToInt32(reader.GetAttribute("version")); 198 } 199 if (reader.GetAttribute("changeset") != null) { 200 obj.Changeset = XmlConvert.ToInt64(reader.GetAttribute("changeset")); 201 } 202 if (reader.GetAttribute("timestamp") != null) { 203 obj.Timestamp = XmlConvert.ToDateTime(reader.GetAttribute("timestamp"), XmlDateTimeSerializationMode.Utc); 204 } 187 205 188 206 }
Note: See TracChangeset
for help on using the changeset viewer.