/// <summary> /// Builds a route. /// </summary> public static Route Build(RouterDb db, Profile profile, Func <ushort, Profiles.Factor> getFactor, RouterPoint source, RouterPoint target, List <uint> path) { return(FastRouteBuilder.TryBuild(db, profile, getFactor, source, target, path).Value); }
/// <summary> /// Tries to calculate an earliest arrival route from stop1 to stop2. /// </summary> public abstract Result <Route> TryEarliestArrival(DateTime departureTime, RouterPoint sourcePoint, Profile sourceProfile, RouterPoint targetPoint, Profile targetProfile, EarliestArrivalSettings settings);
/// <summary> /// Builds a route. /// </summary> public static Result <Route> TryBuild(RouterDb db, Profile profile, Func <ushort, Profiles.Factor> getFactor, RouterPoint source, RouterPoint target, EdgePath <float> path) { var pathList = new List <uint>(); path.AddToListAsVertices(pathList); return(FastRouteBuilder.TryBuild(db, profile, getFactor, source, target, pathList)); }
/// <summary> /// Tries to calculate a tree starting at the given location. /// </summary> public static Tree CalculateTree(this RouterBase router, Profile profile, RouterPoint origin, float max) { return(router.TryCalculateTree(profile, origin, max).Value); }
public void RoutingRegressionTest2() { var interpreter = new OsmRoutingInterpreter(); var tagsIndex = new TagsIndex(); // do the data processing. var memoryData = new RouterDataSource <Edge>(new Graph <Edge>(), tagsIndex); var targetData = new GraphOsmStreamTarget(memoryData, interpreter, tagsIndex); var dataProcessorSource = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_network.osm")); var sorter = new OsmStreamFilterSort(); sorter.RegisterSource(dataProcessorSource); targetData.RegisterSource(sorter); targetData.Pull(); var basicRouter = new Dykstra(); var router = Router.CreateFrom(memoryData, basicRouter, interpreter); // build coordinates list of resolved points. var testPoints = new List <GeoCoordinate>(); testPoints.Add(new GeoCoordinate(51.0582204, 3.7193524)); testPoints.Add(new GeoCoordinate(51.0582199, 3.7194002)); testPoints.Add(new GeoCoordinate(51.0581727, 3.7195833)); testPoints.Add(new GeoCoordinate(51.0581483, 3.7195553)); testPoints.Add(new GeoCoordinate(51.0581883, 3.7196617)); testPoints.Add(new GeoCoordinate(51.0581628, 3.7196889)); // build a matrix of routes between all points. var referenceRoutes = new Route[testPoints.Count][]; var permuationArray = new int[testPoints.Count]; for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++) { permuationArray[fromIdx] = fromIdx; referenceRoutes[fromIdx] = new Route[testPoints.Count]; for (int toIdx = 0; toIdx < testPoints.Count; toIdx++) { // create router from scratch. router = Router.CreateFrom( memoryData, basicRouter, interpreter); // resolve points. var from = router.Resolve(Vehicle.Car, testPoints[fromIdx]); var to = router.Resolve(Vehicle.Car, testPoints[toIdx]); // calculate route. referenceRoutes[fromIdx][toIdx] = router.Calculate(Vehicle.Car, from, to); } } // resolve points in some order and compare the resulting routes. // they should be identical in length except for some numerical rounding errors. var enumerator = new PermutationEnumerable <int>(permuationArray); foreach (int[] permutation in enumerator) { // create router from scratch. router = Router.CreateFrom(memoryData, basicRouter, interpreter); // resolve in the order of the permutation. var resolvedPoints = new RouterPoint[permutation.Length]; for (int idx = 0; idx < permutation.Length; idx++) { resolvedPoints[permutation[idx]] = router.Resolve(Vehicle.Car, testPoints[permutation[idx]]); } for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++) { for (int toIdx = 0; toIdx < testPoints.Count; toIdx++) { // calculate route. var route = router.Calculate(Vehicle.Car, resolvedPoints[fromIdx], resolvedPoints[toIdx]); // TODO: changed the resolve accuracy to .5m. Make sure this is more accurate in the future. Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 1); } } } }
/// <summary> /// Builds a route. /// </summary> public static Result <Route> TryBuild <T>(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, EdgePath <T> path) { return(CompleteRouteBuilder1.TryBuild(db, profile, source, target, path, CancellationToken.None)); }
/// <summary> /// Builds a route. /// </summary> public static Route Build(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, List <uint> path) { return(CompleteRouteBuilder1.Build(db, profile, source, target, path, CancellationToken.None)); }
public void RoutingSerializationV2CHRoutingComparisonTest() { const string embeddedString = "OsmSharp.UnitTests.test_network_real1.osm"; // creates a new interpreter. var interpreter = new OsmRoutingInterpreter(); // do the data processing. var original = CHEdgeGraphOsmStreamWriter.Preprocess(new XmlOsmStreamSource( Assembly.GetExecutingAssembly() .GetManifestResourceStream(embeddedString)), interpreter, Vehicle.Car); // create serializer. var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(true); // serialize/deserialize. byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, original); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } IBasicRouterDataSource <CHEdgeData> deserializedVersion = routingSerializer.Deserialize(new MemoryStream(byteArray)); Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0)); // create reference router. original = CHEdgeGraphOsmStreamWriter.Preprocess(new XmlOsmStreamSource( Assembly.GetExecutingAssembly() .GetManifestResourceStream(embeddedString)), interpreter, Vehicle.Car); var basicRouterOriginal = new CHRouter(original); Router referenceRouter = Router.CreateCHFrom( original, basicRouterOriginal, interpreter); // try to do some routing on the deserialized version. var basicRouter = new CHRouter(deserializedVersion); Router router = Router.CreateCHFrom( deserializedVersion, basicRouter, interpreter); // loop over all nodes and resolve their locations. var resolvedReference = new RouterPoint[original.VertexCount]; var resolved = new RouterPoint[original.VertexCount]; for (uint idx = 1; idx < original.VertexCount + 1; idx++) { // resolve each vertex. float latitude, longitude; if (original.GetVertex(idx, out latitude, out longitude)) { resolvedReference[idx - 1] = referenceRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude)); resolved[idx - 1] = router.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude)); } Assert.IsNotNull(resolvedReference[idx - 1]); Assert.IsNotNull(resolved[idx - 1]); //Assert.AreEqual(resolvedReference[idx - 1].Location.Latitude, // resolved[idx - 1].Location.Latitude, 0.0001); //Assert.AreEqual(resolvedReference[idx - 1].Location.Longitude, // resolved[idx - 1].Location.Longitude, 0.0001); } //// check all the routes having the same weight(s). //for (int fromIdx = 0; fromIdx < resolved.Length; fromIdx++) //{ // for (int toIdx = 0; toIdx < resolved.Length; toIdx++) // { // OsmSharpRoute referenceRoute = referenceRouter.Calculate(Vehicle.Car, // resolvedReference[fromIdx], resolvedReference[toIdx]); // OsmSharpRoute route = router.Calculate(Vehicle.Car, // resolved[fromIdx], resolved[toIdx]); // if (route != null) // { // Assert.IsNotNull(referenceRoute); // } // else // { // Assert.IsNull(referenceRoute); // } // //Assert.AreEqual(referenceRoute.TotalDistance, route.TotalDistance, 0.1); // // TODO: meta data is missing in some CH routing; see issue // //Assert.AreEqual(reference_route.TotalTime, route.TotalTime, 0.0001); // } //} }
public void TestUncontractedManyToMany() { var eMeter = 20f; // build and load network. var routerDb = new RouterDb(); routerDb.LoadTestNetwork( System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( "Itinero.Test.test_data.networks.network9.geojson")); // get the vertex locations to verify the resulting routes. var vertices = new Coordinate[] { routerDb.Network.GetVertex(0), routerDb.Network.GetVertex(1), routerDb.Network.GetVertex(2), routerDb.Network.GetVertex(3), routerDb.Network.GetVertex(4), routerDb.Network.GetVertex(5), routerDb.Network.GetVertex(6), routerDb.Network.GetVertex(7) }; // sort the network. routerDb.Network.Sort(); // defined and add the supported profile. var vehicle = Itinero.Osm.Vehicles.Vehicle.Pedestrian.Fastest(); routerDb.AddSupportedVehicle(vehicle.Parent); var router = new Router(routerDb); // route between two locations for all 4 options. var location1 = new Coordinate(52.35286546406f, 6.66554092450f); var resolved1 = router.Resolve(vehicle, location1); var location2 = new Coordinate(52.3547616807f, 6.66636669078f); var resolved2 = router.Resolve(vehicle, location2); var location3 = new Coordinate(52.35502840541f, 6.66461193744f); var resolved3 = router.Resolve(vehicle, location3); var location5 = new Coordinate(52.35525746742958f, 6.665166020393372f); var resolved5 = router.Resolve(vehicle, location5); var resolved = new RouterPoint[] { resolved1, resolved2, resolved3, resolved5 }; // route and verify (a few select routes). var routes = router.TryCalculate(vehicle, resolved, resolved); // matrix of distance results: // 1 2 3 5 // 1 [ 0, 210, 400, 370] // 2 [210, 0, 191, 140] // 3 [400, 191, 0, 50] // 5 [370, 140, 50, 0] Assert.AreEqual(0, routes.Value[0][0].TotalDistance, eMeter); Assert.AreEqual(210, routes.Value[0][1].TotalDistance, eMeter); Assert.AreEqual(400, routes.Value[0][2].TotalDistance, eMeter); Assert.AreEqual(370, routes.Value[0][3].TotalDistance, eMeter); Assert.AreEqual(210, routes.Value[1][0].TotalDistance, eMeter); Assert.AreEqual(0, routes.Value[1][1].TotalDistance, eMeter); Assert.AreEqual(191, routes.Value[1][2].TotalDistance, eMeter); Assert.AreEqual(140, routes.Value[1][3].TotalDistance, eMeter); Assert.AreEqual(400, routes.Value[2][0].TotalDistance, eMeter); Assert.AreEqual(191, routes.Value[2][1].TotalDistance, eMeter); Assert.AreEqual(0, routes.Value[2][2].TotalDistance, eMeter); Assert.AreEqual(50, routes.Value[2][3].TotalDistance, eMeter); Assert.AreEqual(370, routes.Value[3][0].TotalDistance, eMeter); Assert.AreEqual(140, routes.Value[3][1].TotalDistance, eMeter); Assert.AreEqual(50, routes.Value[3][2].TotalDistance, eMeter); Assert.AreEqual(0, routes.Value[3][3].TotalDistance, eMeter); }
/// <summary> /// Converts the router point to paths leading to the closest 2 vertices always returning the backward path first, forward path second. /// </summary> public static EdgePath <T>[] ToEdgePathsDirectedFixed <T>(this RouterPoint point, RouterDb routerDb, Weights.WeightHandler <T> weightHandler, bool asSource) where T : struct { var graph = routerDb.Network.GeometricGraph; var edge = graph.GetEdge(point.EdgeId); float distance; ushort profileId; Data.Edges.EdgeDataSerializer.Deserialize(edge.Data[0], out distance, out profileId); Profiles.Factor factor; var edgeWeight = weightHandler.Calculate(profileId, distance, out factor); var offset = point.Offset / (float)ushort.MaxValue; if (factor.Direction == 0) { // bidirectional. if (offset == 0) { // the first part is just the first vertex. return(new EdgePath <T>[] { new EdgePath <T>(edge.From, weightHandler.Zero, -edge.IdDirected(), new EdgePath <T>(edge.To)), new EdgePath <T>(edge.To, weightHandler.Calculate(profileId, distance * (1 - offset)), edge.IdDirected(), new EdgePath <T>(edge.From)) }); } else if (offset == 1) { // the second path it just the second vertex. return(new EdgePath <T>[] { new EdgePath <T>(edge.From, weightHandler.Calculate(profileId, distance * offset), -edge.IdDirected(), new EdgePath <T>(edge.To)), new EdgePath <T>(edge.To, weightHandler.Zero, edge.IdDirected(), new EdgePath <T>(edge.From)) }); } return(new EdgePath <T>[] { new EdgePath <T>(edge.From, weightHandler.Calculate(profileId, distance * offset), -edge.IdDirected(), new EdgePath <T>(edge.To)), new EdgePath <T>(edge.To, weightHandler.Calculate(profileId, distance * (1 - offset)), edge.IdDirected(), new EdgePath <T>(edge.From)) }); } else if (factor.Direction == 1) { // edge is forward oneway. if (asSource) { if (offset == 1) { // just return the to-vertex. return(new EdgePath <T>[] { null, new EdgePath <T>(edge.To, weightHandler.Zero, edge.IdDirected(), new EdgePath <T>(edge.From)) }); } return(new EdgePath <T>[] { null, new EdgePath <T>(edge.To, weightHandler.Calculate(profileId, distance * (1 - offset)), edge.IdDirected(), new EdgePath <T>(edge.From)) }); } if (offset == 0) { // just return the from vertex. return(new EdgePath <T>[] { new EdgePath <T>(edge.From, weightHandler.Zero, -edge.IdDirected(), new EdgePath <T>(edge.To)), null }); } return(new EdgePath <T>[] { new EdgePath <T>(edge.From, weightHandler.Calculate(profileId, distance * offset), -edge.IdDirected(), new EdgePath <T>(edge.To)), null }); } else { // edge is backward oneway. if (!asSource) { if (offset == 1) { // just return the to-vertex. return(new EdgePath <T>[] { null, new EdgePath <T>(edge.To, weightHandler.Zero, edge.IdDirected(), new EdgePath <T>(edge.From)) }); } return(new EdgePath <T>[] { null, new EdgePath <T>(edge.To, weightHandler.Calculate(profileId, distance * (1 - offset)), edge.IdDirected(), new EdgePath <T>(edge.From)) }); } if (offset == 0) { // just return the from-vertex. return(new EdgePath <T>[] { new EdgePath <T>(edge.From, weightHandler.Zero, new EdgePath <T>(edge.To)), null }); } return(new EdgePath <T>[] { new EdgePath <T>(edge.From, weightHandler.Calculate(profileId, distance * offset), -edge.IdDirected(), new EdgePath <T>(edge.To)), null }); } }
public void RoutingSerializationV2CompressedRoutingTest() { const string embeddedString = "OsmSharp.UnitTests.test_network.osm"; // create the tags index. var tagsIndex = new SimpleTagsIndex(); // creates a new interpreter. var interpreter = new OsmRoutingInterpreter(); // do the data processing. var original = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex); var targetData = new LiveGraphOsmStreamWriter( original, interpreter, original.TagsIndex); var dataProcessorSource = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)); targetData.RegisterSource(dataProcessorSource); targetData.Pull(); // create serializer. var routingSerializer = new V2RoutingDataSourceLiveEdgeSerializer(true); // serialize/deserialize. byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, original); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } IBasicRouterDataSource <LiveEdge> deserializedVersion = routingSerializer.Deserialize(new MemoryStream(byteArray)); Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0)); // try to do some routing on the deserialized version. var basicRouter = new DykstraRoutingLive(deserializedVersion.TagsIndex); Router router = Router.CreateLiveFrom(deserializedVersion, basicRouter, interpreter); RouterPoint source = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0578532, 3.7192229)); RouterPoint target = router.Resolve(Vehicle.Car, new GeoCoordinate(51.0576193, 3.7191801)); // calculate the route. OsmSharpRoute route = router.Calculate(Vehicle.Car, source, target); Assert.IsNotNull(route); Assert.AreEqual(5, route.Entries.Length); float latitude, longitude; deserializedVersion.GetVertex(20, out latitude, out longitude); Assert.AreEqual(latitude, route.Entries[0].Latitude, 0.00001); Assert.AreEqual(longitude, route.Entries[0].Longitude, 0.00001); Assert.AreEqual(RoutePointEntryType.Start, route.Entries[0].Type); deserializedVersion.GetVertex(21, out latitude, out longitude); Assert.AreEqual(latitude, route.Entries[1].Latitude, 0.00001); Assert.AreEqual(longitude, route.Entries[1].Longitude, 0.00001); Assert.AreEqual(RoutePointEntryType.Along, route.Entries[1].Type); deserializedVersion.GetVertex(16, out latitude, out longitude); Assert.AreEqual(latitude, route.Entries[2].Latitude, 0.00001); Assert.AreEqual(longitude, route.Entries[2].Longitude, 0.00001); Assert.AreEqual(RoutePointEntryType.Along, route.Entries[2].Type); deserializedVersion.GetVertex(22, out latitude, out longitude); Assert.AreEqual(latitude, route.Entries[3].Latitude, 0.00001); Assert.AreEqual(longitude, route.Entries[3].Longitude, 0.00001); Assert.AreEqual(RoutePointEntryType.Along, route.Entries[3].Type); deserializedVersion.GetVertex(23, out latitude, out longitude); Assert.AreEqual(latitude, route.Entries[4].Latitude, 0.00001); Assert.AreEqual(longitude, route.Entries[4].Longitude, 0.00001); Assert.AreEqual(RoutePointEntryType.Stop, route.Entries[4].Type); }
/// <summary> /// Calculates isochrones for the given profile based on the given limits. /// </summary> public static List <LocalGeo.Polygon> CalculateIsochrones(this RouterBase router, Profile profile, RouterPoint origin, List <float> limits, int zoom = 16) { if (profile.Metric != ProfileMetric.TimeInSeconds) { throw new ArgumentException(string.Format("Profile {0} not supported, only profiles with metric TimeInSeconds are supported.", profile.FullName)); } // get the weight handler. var weightHandler = router.GetDefaultWeightHandler(profile); var getFactor = router.GetDefaultGetFactor(profile); // calculate isochrones. var isochrone = new TileBasedIsochroneBuilder(router.Db.Network.GeometricGraph, new Algorithms.Default.Dykstra(router.Db.Network.GeometricGraph.Graph, weightHandler, null, origin.ToEdgePaths <float>(router.Db, weightHandler, true), limits.Max() * 1.1f, false), limits, zoom); isochrone.Run(); return(isochrone.Polygons); }
/// <summary> /// Called right after the contraction. /// </summary> /// <param name="vertex"></param> /// <param name="edges"></param> void pre_processor_OnAfterContractionEvent(uint vertex, KeyValuePair <uint, CHEdgeData>[] edges) { // create a new CHRouter var router = new CHRouter(); // calculate all the routes between the neighbours of the contracted vertex. foreach (KeyValuePair <uint, CHEdgeData> from in edges) { // initialize the from-list. var fromList = new PathSegmentVisitList(); fromList.UpdateVertex(new PathSegment <long>(from.Key)); // initalize the from dictionary. Dictionary <uint, PathSegment <long> > fromDic = _pathsBeforeContraction[from.Key]; foreach (KeyValuePair <uint, CHEdgeData> to in edges) { // initialize the to-list. var toList = new PathSegmentVisitList(); toList.UpdateVertex(new PathSegment <long>(to.Key)); // calculate the route. PathSegment <long> route = router.Calculate(_data, _interpreter, OsmSharp.Routing.Vehicle.Car, fromList, toList, double.MaxValue); if ((fromDic[to.Key] == null && route != null) || (fromDic[to.Key] != null && route == null) || ((fromDic[to.Key] != null && route != null) && fromDic[to.Key] != route)) { // the route match! Assert.Fail("Routes are different before/after contraction!"); } } } if (_referenceRouter != null) { // do crazy verification! Router chRouter = Router.CreateCHFrom(_data, router, new OsmRoutingInterpreter()); // loop over all nodes and resolve their locations. var resolvedReference = new RouterPoint[_data.VertexCount - 1]; var resolved = new RouterPoint[_data.VertexCount - 1]; for (uint idx = 1; idx < _data.VertexCount; idx++) { // resolve each vertex. float latitude, longitude; if (_data.GetVertex(idx, out latitude, out longitude)) { resolvedReference[idx - 1] = _referenceRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude)); resolved[idx - 1] = chRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude)); } Assert.IsNotNull(resolvedReference[idx - 1]); Assert.IsNotNull(resolved[idx - 1]); Assert.AreEqual(resolvedReference[idx - 1].Location.Latitude, resolved[idx - 1].Location.Latitude, 0.0001); Assert.AreEqual(resolvedReference[idx - 1].Location.Longitude, resolved[idx - 1].Location.Longitude, 0.0001); } // limit tests to a fixed number. int maxTestCount = 100; int testEveryOther = (resolved.Length * resolved.Length) / maxTestCount; testEveryOther = System.Math.Max(testEveryOther, 1); // check all the routes having the same weight(s). for (int fromIdx = 0; fromIdx < resolved.Length; fromIdx++) { for (int toIdx = 0; toIdx < resolved.Length; toIdx++) { int testNumber = fromIdx * resolved.Length + toIdx; if (testNumber % testEveryOther == 0) { Route referenceRoute = _referenceRouter.Calculate(Vehicle.Car, resolvedReference[fromIdx], resolvedReference[toIdx]); Route route = chRouter.Calculate(Vehicle.Car, resolved[fromIdx], resolved[toIdx]); if (referenceRoute != null) { Assert.IsNotNull(referenceRoute); Assert.IsNotNull(route); this.CompareRoutes(referenceRoute, route); } } } } } }
/// <summary> /// Tries to calculate a tree starting at the given location. /// </summary> public static Result <Tree> TryCalculateTree(this RouterBase router, Profile profile, RouterPoint origin, float max) { if (!router.SupportsAll(profile)) { return(new Result <Tree>(string.Format("Profile {0} not supported.", profile.Name))); } if (profile.Metric != ProfileMetric.TimeInSeconds) { return(new Result <Tree>(string.Format("Profile {0} not supported, only profiles with metric TimeInSeconds are supported.", profile.Name))); } // get the weight handler. var weightHandler = router.GetDefaultWeightHandler(profile); var getFactor = router.GetDefaultGetFactor(profile); // calculate isochrones. TreeBuilder treeBuilder = null; if (!router.Db.HasComplexRestrictions(profile)) { treeBuilder = new TreeBuilder(router.Db.Network.GeometricGraph, new Algorithms.Default.Dykstra(router.Db.Network.GeometricGraph.Graph, weightHandler, null, origin.ToEdgePaths <float>(router.Db, weightHandler, true), max, false)); } else { treeBuilder = new TreeBuilder(router.Db.Network.GeometricGraph, new Algorithms.Default.EdgeBased.Dykstra(router.Db.Network.GeometricGraph.Graph, weightHandler, router.Db.GetGetRestrictions(profile, true), origin.ToEdgePaths <float>(router.Db, weightHandler, true), max, false)); } treeBuilder.Run(); return(new Result <Tree>(treeBuilder.Tree)); }
/// <summary> /// Creates a router builder. /// </summary> public FastRouteBuilder(RouterDb routerDb, Profile profile, Func <ushort, Factor> getFactor, RouterPoint source, RouterPoint target, List <uint> path) { _routerDb = routerDb; _path = path; _source = source; _target = target; _profile = profile; _getFactor = getFactor; }
public override Result <bool> TryCheckConnectivity(IProfileInstance profile, RouterPoint point, float radiusInMeters, bool?forward = null) { throw new System.NotImplementedException(); }
/// <summary> /// Issue with generation instructions but where streetnames seem to be stripped. /// Some streetnames are missing from the instructions. /// </summary> protected void DoInstructionRegressionTest1() { OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter(); Router router = this.CreateRouter(interpreter, "OsmSharp.Test.Unittests.test_routing_regression1.osm"); // resolve the three points in question. GeoCoordinate point35 = new GeoCoordinate(51.01257, 4.000753); RouterPoint point35resolved = router.Resolve(Vehicle.Car, point35, true); GeoCoordinate point45 = new GeoCoordinate(51.01315, 3.999588); RouterPoint point45resolved = router.Resolve(Vehicle.Car, point45, true); GeoCoordinate point40 = new GeoCoordinate(51.01250, 4.000013); RouterPoint point40resolved = router.Resolve(Vehicle.Car, point40, true); // calculate two smaller routes. Route route3545 = router.Calculate(Vehicle.Car, point35resolved, point45resolved); Route route4540 = router.Calculate(Vehicle.Car, point45resolved, point40resolved); Route route3540concatenated = Route.Concatenate(route3545, route4540, true); Route route3540 = router.Calculate(Vehicle.Car, point35resolved, point40resolved); // check if both routes are equal. Assert.AreEqual(route3540.Entries.Length, route3540concatenated.Entries.Length); for (int idx = 0; idx < route3540.Entries.Length; idx++) { Assert.AreEqual(route3540.Entries[idx].Distance, route3540concatenated.Entries[idx].Distance); Assert.AreEqual(route3540.Entries[idx].Latitude, route3540concatenated.Entries[idx].Latitude); Assert.AreEqual(route3540.Entries[idx].Longitude, route3540concatenated.Entries[idx].Longitude); Assert.AreEqual(route3540.Entries[idx].Time, route3540concatenated.Entries[idx].Time); Assert.AreEqual(route3540.Entries[idx].Type, route3540concatenated.Entries[idx].Type); Assert.AreEqual(route3540.Entries[idx].WayFromName, route3540concatenated.Entries[idx].WayFromName); // something that is allowed to be different in this case! // route3540.Entries[idx].Points != null // // check sidestreets. // if (route3540.Entries[idx].SideStreets != null && // route3540.Entries[idx].SideStreets.Length > 0) // { // check if the sidestreets represent the same information. // for (int metricIdx = 0; metricIdx < route3540concatenated.Entries[idx].SideStreets.Length; metricIdx++) // { // Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].WayName, // route3540concatenated.Entries[idx].SideStreets[metricIdx].WayName); // Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].Latitude, // route3540concatenated.Entries[idx].SideStreets[metricIdx].Latitude); // Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].Longitude, // route3540concatenated.Entries[idx].SideStreets[metricIdx].Longitude); // } // } // else // { // Assert.IsTrue(route3540concatenated.Entries[idx].SideStreets == null || // route3540concatenated.Entries[idx].SideStreets.Length == 0); // } // if (route3540.Entries[idx].Tags != null && // route3540.Entries[idx].Tags.Length > 0) // { // check if the Tags represent the same information. // for (int metricIdx = 0; metricIdx < route3540concatenated.Entries[idx].Tags.Length; metricIdx++) // { // Assert.AreEqual(route3540.Entries[idx].Tags[metricIdx].Key, // route3540concatenated.Entries[idx].Tags[metricIdx].Key); // Assert.AreEqual(route3540.Entries[idx].Tags[metricIdx].Value, // route3540concatenated.Entries[idx].Tags[metricIdx].Value); // } // } // else // { // Assert.IsTrue(route3540concatenated.Entries[idx].Tags == null || // route3540concatenated.Entries[idx].Tags.Length == 0); // } // Assert.AreEqual(route3540.Entries[idx].Distance, route3540concatenated.Entries[idx].Distance); } if (route3540.Tags != null && route3540.Tags.Length > 0) { for (int tagIdx = 0; tagIdx < route3540.Tags.Length; tagIdx++) { if (route3540.Tags[tagIdx].Key != "debug_route") { Assert.AreEqual(route3540.Tags[tagIdx].Key, route3540concatenated.Tags[tagIdx].Key); Assert.AreEqual(route3540.Tags[tagIdx].Value, route3540concatenated.Tags[tagIdx].Value); } } } else { Assert.IsTrue(route3540concatenated.Tags == null || route3540concatenated.Tags.Length == 0); } if (route3540.Metrics != null) { for (int metricIdx = 0; metricIdx < route3540concatenated.Entries.Length; metricIdx++) { Assert.AreEqual(route3540.Metrics[metricIdx].Key, route3540concatenated.Metrics[metricIdx].Key); Assert.AreEqual(route3540.Metrics[metricIdx].Value, route3540concatenated.Metrics[metricIdx].Value); } } else { Assert.IsNull(route3540concatenated.Metrics); } // remove the point in between, the only difference between the regular and the concatenated route. route3540concatenated.Entries[7].Points = null; // create the language generator. var languageGenerator = new LanguageTestGenerator(); // generate the instructions. List <Instruction> instructions = InstructionGenerator.Generate(route3540, interpreter, languageGenerator); List <Instruction> instructionsConcatenated = InstructionGenerator.Generate(route3540concatenated, interpreter, languageGenerator); Assert.AreEqual(instructions.Count, instructionsConcatenated.Count); for (int idx = 0; idx < instructions.Count; idx++) { Assert.AreEqual(instructions[idx].Location.Center, instructionsConcatenated[idx].Location.Center); Assert.AreEqual(instructions[idx].Text, instructionsConcatenated[idx].Text); } }
public override Result <EdgePath <T> > TryCalculateRaw <T>(Itinero.Profiles.IProfileInstance profile, WeightHandler <T> weightHandler, RouterPoint source, RouterPoint target, RoutingSettings <T> settings) { return(new Result <EdgePath <T> >(new EdgePath <T>())); }
/// <summary> /// Builds a route. /// </summary> public static Result <Route> TryBuild <T>(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, EdgePath <T> path, CancellationToken cancellationToken) { var pathList = new List <uint>(); path.AddToListAsVertices(pathList); return(CompleteRouteBuilder1.TryBuild(db, profile, source, target, pathList, cancellationToken)); }
public override Result <Route> BuildRoute <T>(IProfileInstance profile, WeightHandler <T> weightHandler, RouterPoint source, RouterPoint target, EdgePath <T> path) { var route = new Route(); route.Shape = new Coordinate[] { source.Location(), target.Location() }; return(new Result <Route>(route)); }
/// <summary> /// Builds a route. /// </summary> public static Route Build(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, List <uint> path, CancellationToken cancellationToken) { return(CompleteRouteBuilder1.TryBuild(db, profile, source, target, path, cancellationToken).Value); }
/// <summary> /// Initializes the View property. /// </summary> public override void LoadView() { base.LoadView(); // enable the logggin. OsmSharp.Logging.Log.Enable(); OsmSharp.Logging.Log.RegisterListener(new OsmSharp.iOS.UI.Log.ConsoleTraceListener()); // initialize map. var map = new Map(); // add a tile layer. //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png")); // add an online osm-data->mapCSS translation layer. //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter)); // add a pre-processed vector data file. var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream( "OsmSharp.iOS.UI.Sample.default.map"); map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true))); // define dummy from and to points. var from = new GeoCoordinate(51.261203, 4.780760); var to = new GeoCoordinate(51.267797, 4.801362); // deserialize the pre-processed graph. var routingSerializer = new CHEdgeDataDataSourceSerializer(false); TagsCollectionBase metaData = null; var graphStream = Assembly.GetExecutingAssembly().GetManifestResourceStream( "OsmSharp.iOS.UI.Sample.kempen-big.osm.pbf.routing"); var graphDeserialized = routingSerializer.Deserialize(graphStream, out metaData, true); // initialize router. _router = Router.CreateCHFrom(graphDeserialized, new CHRouter(), new OsmRoutingInterpreter()); // resolve points. RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from); RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to); // calculate route. Route route = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2); RouteTracker routeTracker = new RouteTracker(route, new OsmRoutingInterpreter()); _enumerator = route.GetRouteEnumerable(10).GetEnumerator(); // add a router layer. _routeLayer = new LayerRoute(map.Projection); _routeLayer.AddRoute(route, SimpleColor.FromKnownColor(KnownColor.Blue, 125).Value, 12); map.AddLayer(_routeLayer); // define the mapview. _mapView = new MapView(); //_mapView.MapTapEvent += new MapViewEvents.MapTapEventDelegate(_mapView_MapTapEvent); _mapView.Map = map; _mapView.MapMaxZoomLevel = 20; _mapView.MapMinZoomLevel = 10; _mapView.MapTilt = 0; _mapView.MapCenter = new GeoCoordinate(51.26371, 4.78601); _mapView.MapZoom = 18; // add markers. _mapView.AddMarker(from); _mapView.AddMarker(to); // create the route tracker animator. _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5, 17); // simulate a number of gps-location update along the calculated route. Timer timer = new Timer(250); timer.Elapsed += new ElapsedEventHandler(TimerHandler); timer.Start(); View = _mapView; }