- Timestamp:
- 08/20/12 11:39:25 (12 years ago)
- Location:
- branches/RoutePlanning
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning.Test/Program.cs
r8481 r8504 5 5 using System.Xml; 6 6 using HeuristicLab.Algorithms.GraphRouting; 7 using HeuristicLab.Problems.RoutePlanning.DIMACS;8 7 using HeuristicLab.Problems.RoutePlanning.Graph; 9 8 using HeuristicLab.Problems.RoutePlanning.Osm; … … 23 22 string file6 = @"C:\dev\osmfiles\oberosterreich.highway.osm"; 24 23 string file7 = @"C:\dev\osmfiles\austria.highway.osm"; 24 string file8 = @"C:\dev\osmfiles\vorarlberg.highway.osm"; 25 25 26 26 string fileNYArcs = @"C:\dev\DIMACSfiles\USA-road-t.NY.gr.gz"; 27 27 string fileNYCoords = @"C:\dev\DIMACSfiles\USA-road-d.NY.co.gz"; 28 28 29 //IDataSource ds = TestLoad(file5); 30 //OsmGraph graph = new OsmGraph(ds); 29 //IDataSource ds = TestLoad(typeof(XmlDataSource), file7); 30 IDataSource ds = TestLoad(typeof(OsmDataSource), file5); 31 OsmGraph graph = new OsmGraph(ds); 31 32 //IGraph graphNew = TestGetRoutingGraph(ds); 32 33 33 IDataSource ds = new DIMACSDataSource(fileNYCoords, fileNYArcs); 34 35 //TestRouter(new DijkstraAlgorithm(graph), 529102170, 1001363194, true); 34 //IDataSource ds = new DIMACSDataSource(fileNYCoords, fileNYArcs); 35 //IDataSource ds = new OsmDataSource(file5); 36 37 TestRouter(new DijkstraAlgorithm(graph), 529102170, 1001363194, true); 36 38 //TestRouter(new DijkstraAlgorithmV2(graphNew), 529102170, 1001363194, true); 37 //TestRouter(new DijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb39 TestRouter(new DijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb 38 40 //TestRouter(new DijkstraAlgorithmV2(graphNew), 529102170, 31372732, false); // inz - hgb 39 //TestRouter(new BidrectionalDijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb41 TestRouter(new BidrectionalDijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb 40 42 //TestRouter(new BidrectionalDijkstraAlgorithmV2(graphNew), 529102170, 31372732, false); // inz - hgb 41 43 //TestRouter(new AStarAlgorithm(graph), 529102170, 31372732, false); // inz - hgb 42 //TestRouter(new AStarAlgorithmV2(graph), 529102170, 31372732, false); // inz - hgb44 TestRouter(new AStarAlgorithmV2(graph), 529102170, 31372732, false); // inz - hgb 43 45 //TestRouter(new AStarAlgorithmV3(graphNew), 529102170, 31372732, false); // inz - hgb 44 46 47 //TestRouter(new AStarAlgorithmV2(graph), 763113382, 1078628481, false); // bregenz (bahnhofstr) - podersdorf (??) 48 //TestRouter(new AStarAlgorithmV3(graphNew), 346151602, 33196510, false); // bregenz (bahnhofstr) - wien (stepansplatz) 45 49 //TestRouter(new AStarAlgorithmV2(graph), 346151602, 33196510, false); // bregenz (bahnhofstr) - wien (stepansplatz) 46 //TestRouter(new AStarAlgorithmV3(graphNew), 346151602, 33196510, false); // bregenz (bahnhofstr) - wien (stepansplatz) 50 51 //TestRouter(new AStarAlgorithmV2(graph), 32044987, 261576106, false); //vorarblberg 52 //TestRouter(new AStarAlgorithmV3(graphNew), 32044987, 261576106, false); //vorarblberg 47 53 48 54 //TestLoadAndRouter(file6, typeof(DijkstraAlgorithm), 529102170, 31372732, false, false); // inz - hgb … … 64 70 //TestLoadAndRouterNew(file6, typeof(AStarAlgorithmV3), 529102170, 31372732, false, true); 65 71 72 //TestLoadAndRouter(file7, typeof(AStarAlgorithmV2), 346151602, 33196510, false, true); // bregenz (bahnhofstr) - wien (stepansplatz) 73 //TestLoadAndRouterNew(file7, typeof(AStarAlgorithmV3), 346151602, 33196510, false, true); // bregenz (bahnhofstr) - wien (stepansplatz) 74 75 TestLoadAndRouter(file8, typeof(AStarAlgorithmV2), 32044987, 261576106, false, true); //vorarblberg 76 66 77 System.Console.Read(); 67 78 } … … 89 100 } 90 101 91 private static IDataSource TestLoad( string filepath) {92 FileInfo file = new FileInfo( filepath);102 private static IDataSource TestLoad(Type dsType, params string[] paths) { 103 FileInfo file = new FileInfo(paths[0]); 93 104 Console.WriteLine("Test Load Data BEGIN ------------------------------"); 94 105 Console.WriteLine("File name: {0}", file.Name); … … 96 107 Console.Write("Loading data ... "); 97 108 var sw = Stopwatch.StartNew(); 98 XmlDataSource xmlDs = new XmlDataSource(filepath);109 IDataSource ds = (IDataSource)Activator.CreateInstance(dsType, paths); 99 110 sw.Stop(); 100 111 Console.WriteLine("done."); … … 103 114 Console.WriteLine("==================================================="); 104 115 Console.WriteLine(); 105 return xmlDs;116 return ds; 106 117 } 107 118 -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm.Data/OsmDataSource.cs
r8488 r8504 16 16 vertices = new Dictionary<long, Vertex>(); 17 17 18 ReadData ();18 ReadDataV2(); 19 19 } 20 20 … … 134 134 } 135 135 } 136 137 private void ReadDataV2() { 138 XmlReaderSettings settings = new XmlReaderSettings(); 139 settings.IgnoreComments = true; 140 settings.IgnoreWhitespace = true; 141 NameTable nt = new NameTable(); 142 string osmName = nt.Add("osm"); 143 string nodeName = nt.Add("node"); 144 object tagName = nt.Add("tag"); 145 object wayName = nt.Add("way"); 146 string latName = nt.Add("lat"); 147 string lonName = nt.Add("lon"); 148 string idName = nt.Add("id"); 149 string ndName = nt.Add("nd"); 150 string refName = nt.Add("ref"); 151 string kName = nt.Add("k"); 152 string vName = nt.Add("v"); 153 settings.NameTable = nt; 154 string ns = ""; 155 156 using (XmlReader reader = XmlReader.Create(file.FullName, settings)) { 157 reader.ReadStartElement(osmName, ns); 158 reader.Read(); 159 while (reader.LocalName.Equals(nodeName)) { 160 double lat = XmlConvert.ToDouble(reader.GetAttribute(latName, ns)); 161 double lon = XmlConvert.ToDouble(reader.GetAttribute(lonName, ns)); 162 long id = XmlConvert.ToInt64(reader.GetAttribute(idName, ns)); 163 164 Vertex v = new Vertex(id, lon, lat); 165 vertices.Add(v.Id, v); 166 167 reader.Read(); 168 if (reader.LocalName.Equals(tagName)) { 169 reader.ReadToFollowing(nodeName, ns); 170 } 171 } 172 while (reader.LocalName.Equals(wayName)) { 173 List<Vertex> way = new List<Vertex>(); 174 bool missingNodes = false; 175 HighwayType category = HighwayType.null_type; 176 bool oneWayRoad = false; 177 178 reader.Read(); 179 while (reader.LocalName.Equals(nodeName) || reader.LocalName.Equals(tagName)) { 180 if (reader.LocalName.Equals(ndName)) { 181 long refNodeId = XmlConvert.ToInt64(reader.GetAttribute(refName, ns)); 182 Vertex vertex = GetVertex(refNodeId); 183 if (vertex != null) { 184 way.Add(vertex); 185 } else { 186 missingNodes = true; 187 } 188 189 } else if (reader.LocalName.Equals(tagName)) { 190 string key = reader.GetAttribute(kName, ns); 191 string value = reader.GetAttribute(vName, ns); 192 193 if (key == TagConstants.HighwayTagKey) { 194 if (Enum.IsDefined(typeof(HighwayType), value)) { 195 HighwayType ht = (HighwayType)Enum.Parse(typeof(HighwayType), value, true); 196 category = ht; 197 } else { 198 category = HighwayType.null_type; 199 } 200 } else if (key == TagConstants.OneWayTag) { 201 oneWayRoad = value.Equals(TagConstants.YesValue); 202 } 203 } 204 reader.Read(); 205 } 206 if (missingNodes) { 207 // TODO: Error/Trace output 208 // if Way xxx has incomplete nodes. At least one node was missing in the data. 209 } 210 for (int i = 0; i < way.Count - 1; i++) { 211 Vertex v1 = way[i]; 212 graph.AddVertex(v1); 213 Vertex v2 = way[i + 1]; 214 graph.AddVertex(v2); 215 short vertexCategory = (short)category; 216 if (oneWayRoad) { 217 Edge<Vertex> edge = new Edge<Vertex>(v1, v2, vertexCategory); 218 graph.AddEdge(edge); 219 } else { 220 Edge<Vertex> edgeForward = new Edge<Vertex>(v1, v2, vertexCategory); 221 graph.AddEdge(edgeForward); 222 223 Edge<Vertex> edgeBackward = new Edge<Vertex>(v2, v1, vertexCategory); 224 graph.AddEdge(edgeBackward); 225 } 226 } 227 reader.Read(); 228 } 229 reader.Close(); 230 } 231 } 136 232 } 137 233 }
Note: See TracChangeset
for help on using the changeset viewer.