예제 #1
0
 /// <summary>
 /// Checks connectivity of all given points and returns only those that are valid.
 /// </summary>
 /// <param name="router"></param>
 /// <param name="vehicle"></param>
 /// <param name="resolvedPoints"></param>
 /// <param name="weight"></param>
 /// <returns></returns>
 public static RouterPoint[] CheckConnectivityAndRemoveInvalid(
     this Router router, Vehicle vehicle, RouterPoint[] resolvedPoints, float weight)
 {
     var connectedPoints = new List<RouterPoint>();
     for (int idx = 0; idx < resolvedPoints.Length; idx++)
     {
         RouterPoint resolvedPoint = resolvedPoints[idx];
         if (resolvedPoint != null &&
             router.CheckConnectivity(vehicle, resolvedPoint, weight))
         { // the point is connected.
             connectedPoints.Add(resolvedPoint);
         }
     }
     return connectedPoints.ToArray();
 }
        /// <summary>
        /// Called right after the contraction.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="edges"></param>
        void pre_processor_OnAfterContractionEvent(uint vertex, List<Edge<CHEdgeData>> edges)
        {
            // get dictionary for vertex.
            var pathsBeforeContraction = _pathsBeforeContraction[vertex];

            // create a new CHRouter
            var router = new CHRouter();

            // calculate all the routes between the neighbours of the contracted vertex.
            foreach (var from in edges)
            {
                // initialize the from-list.
                var fromList = new PathSegmentVisitList();
                fromList.UpdateVertex(new PathSegment<long>(from.Neighbour));

                // initalize the from dictionary.
                var fromDic = pathsBeforeContraction[from.Neighbour];
                foreach (var to in edges)
                {
                    // initialize the to-list.
                    var toList = new PathSegmentVisitList();
                    toList.UpdateVertex(new PathSegment<long>(to.Neighbour));

                    // calculate the route.
                    var route = router.Calculate(_data, _interpreter, Vehicle.Car, fromList, toList, double.MaxValue, null);
                    if ((fromDic[to.Neighbour] == null && route != null) ||
                        (fromDic[to.Neighbour] != null && route == null))
                    { // the route match!
                        Assert.Fail("Routes are different before/after contraction!");
                    }
                    else if (fromDic[to.Neighbour] != null && route != null)
                    {
                        this.ComparePaths(fromDic[to.Neighbour], route);
                    }
                }
            }

            if (_referenceRouter != null)
            { // do crazy verification!
                var 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);
                            }
                        }
                    }
                }
            }

            _pathsBeforeContraction.Remove(vertex);
        }
예제 #3
0
        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.Routing.Test.data.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);
                    }
                }
            }
        }
예제 #4
0
파일: Router.cs 프로젝트: JoeCooper/routing
 /// <summary>
 /// Calculates a route between one source and many target points.
 /// </summary>
 /// <returns></returns>
 public double[] CalculateOneToManyWeight(Vehicle vehicle, RouterPoint source, RouterPoint[] targets, CancellationToken cancellationToken = new CancellationToken())
 {
     return this.CalculateOneToManyWeight(vehicle, source, targets, new HashSet<int>(), cancellationToken);
 }
예제 #5
0
파일: Router.cs 프로젝트: JoeCooper/routing
        /// <summary>
        /// Returns true if the given point is connected for a radius of at least the given weight.
        /// </summary>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <param name="points"></param>
        /// <param name="weight"></param>
        /// <returns></returns>
        public bool[] CheckConnectivity(Vehicle vehicle, RouterPoint[] points, float weight, CancellationToken cancellationToken = new CancellationToken())
        {
            if (vehicle == null) { throw new ArgumentNullException("vehicle"); }
            if (points == null) { throw new ArgumentNullException("points"); }

            foreach (var point in points)
            {
                if (vehicle.UniqueName != point.Vehicle.UniqueName)
                { // vehicles are different.
                    throw new ArgumentException(string.Format("Given vehicle profile does not match resolved points, {0} and {1} are given, expecting identical profiles.",
                        vehicle.UniqueName, point.Vehicle.UniqueName));
                }
            }

            return _router.CheckConnectivity(vehicle, points, weight, cancellationToken);
        }
예제 #6
0
 /// <summary>
 /// Calculates a shortest route from a given point to any of the targets points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="source">The source point.</param>
 /// <param name="targets">The target point(s).</param>
 /// <param name="max">The maximum weight to stop the calculation.</param>
 /// <returns></returns>
 public Route CalculateToClosest(Vehicle vehicle, RouterPoint source, RouterPoint[] targets, float max)
 {
     return(_router.CalculateToClosest(vehicle, source, targets, max));
 }
예제 #7
0
파일: Router.cs 프로젝트: JoeCooper/routing
        /// <summary>
        /// Calculates all routes between many sources/targets.
        /// </summary>
        /// <returns></returns>
        public double[][] CalculateManyToManyWeight(Vehicle vehicle, RouterPoint[] sources, RouterPoint[] targets, HashSet<int> invalidSet, CancellationToken cancellationToken = new CancellationToken())
        {
            if (vehicle == null) { throw new ArgumentNullException("vehicle"); }
            if (sources == null) { throw new ArgumentNullException("source"); }
            if (targets == null) { throw new ArgumentNullException("targets"); }
            if (invalidSet == null) { throw new ArgumentNullException("invalidSet"); }

            foreach (var source in sources)
            {
                foreach (var target in targets)
                {
                    if (source.Vehicle.UniqueName != target.Vehicle.UniqueName)
                    { // vehicles are different.
                        throw new ArgumentException(string.Format("Not all vehicle profiles match, {0} and {1} are given, expecting identical profiles.",
                            source.Vehicle.UniqueName, target.Vehicle.UniqueName));
                    }
                    if (vehicle.UniqueName != target.Vehicle.UniqueName)
                    { // vehicles are different.
                        throw new ArgumentException(string.Format("Given vehicle profile does not match resolved points, {0} and {1} are given, expecting identical profiles.",
                            vehicle.UniqueName, target.Vehicle.UniqueName));
                    }
                }
            }

            return _router.CalculateManyToManyWeight(vehicle, sources, targets, invalidSet, cancellationToken);
        }
예제 #8
0
        /// <summary>
        /// Compares all routes against the reference router.
        /// </summary>
        public void TestCompareAll(string embedded_name)
        {
            // build the routing settings.
            IRoutingInterpreter interpreter = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();

            // get the osm data source.
            IBasicRouterDataSource<PreProcessedEdge> data = this.BuildDykstraDataSource(interpreter, embedded_name);

            // build the reference router.;
            IRouter<RouterPoint> reference_router = this.BuildDykstraRouter(
                this.BuildDykstraDataSource(interpreter, embedded_name), interpreter, new DykstraRoutingPreProcessed(data.TagsIndex));

            // build the router to be tested.
            IRouter<RouterPoint> router = this.BuildRouter(interpreter, embedded_name);

            // loop over all nodes and resolve their locations.
            RouterPoint[] resolved_reference = new RouterPoint[data.VertexCount - 1];
            RouterPoint[] 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))
                {
                    resolved_reference[idx - 1] = reference_router.Resolve(VehicleEnum.Car, new GeoCoordinate(latitude, longitude));
                    resolved[idx - 1] = router.Resolve(VehicleEnum.Car, new GeoCoordinate(latitude, longitude));
                }

                Assert.IsNotNull(resolved_reference[idx - 1]);
                Assert.IsNotNull(resolved[idx - 1]);

                Assert.AreEqual(resolved_reference[idx - 1].Location.Latitude,
                    resolved[idx - 1].Location.Latitude, 0.0001);
                Assert.AreEqual(resolved_reference[idx - 1].Location.Longitude,
                    resolved[idx - 1].Location.Longitude, 0.0001);
            }

            // check all the routes having the same weight(s).
            for (int from_idx = 0; from_idx < resolved.Length; from_idx++)
            {
                for (int to_idx = 0; to_idx < resolved.Length; to_idx++)
                {
                    OsmSharpRoute reference_route = reference_router.Calculate(VehicleEnum.Car,
                        resolved_reference[from_idx], resolved_reference[to_idx]);
                    OsmSharpRoute route = router.Calculate(VehicleEnum.Car,
                        resolved[from_idx], resolved[to_idx]);

                    Assert.IsNotNull(reference_route);
                    Assert.IsNotNull(route);
                    Assert.AreEqual(reference_route.TotalDistance, route.TotalDistance, 0.0001);
                    // TODO: meta data is missing in some CH routing; see issue
                    //Assert.AreEqual(reference_route.TotalTime, route.TotalTime, 0.0001);
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Builds a route along all the given points.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="resolved"></param>
        /// <param name="coordinates"></param>
        /// <returns></returns>
        public Route BuildRoute(Vehicle vehicle, RouterPoint[] resolved, GeoCoordinate[] coordinates)
        {
            var routes = new Route[resolved.Length - 1];
            for (int idx = 1; idx < resolved.Length; idx++)
            {
                if (resolved[idx - 1] == null || resolved[idx] == null)
                { // failed to resolve point(s), replace with a dummy route.
                    routes[idx - 1] = null;
                }
                else
                { // both points are resolved, calculate route.
                    var localRoute = _router.Calculate(vehicle, resolved[idx - 1], resolved[idx]);
                    if (localRoute != null)
                    { // route was found.
                        routes[idx - 1] = localRoute;
                    }
                    else
                    { // failed to calculate route, replace with a dummy route.
                        routes[idx - 1] = null;
                    }
                }
            }

            // add dummy routes in place of routes that have not been found.
            for (int idx = 0; idx < routes.Length; idx++)
            {
                if (routes[idx] == null)
                { // the route is null here.
                    GeoCoordinate coordinate1, coordinate2;
                    if (idx > 0 &&
                        routes[idx - 1] != null)
                    { // there is a route before this one, take the last point of it as start of this one.
                        coordinate1 = new GeoCoordinate(
                            routes[idx - 1].Segments[routes[idx - 1].Segments.Length - 1].Latitude,
                            routes[idx - 1].Segments[routes[idx - 1].Segments.Length - 1].Longitude);
                    }
                    else
                    { // take the coordinate itself.
                        coordinate1 = coordinates[idx];
                    }
                    if (routes.Length > idx + 1 &&
                        routes[idx + 1] != null)
                    { // there is a route before this one, take the last point of it as start of this one.
                        coordinate2 = new GeoCoordinate(
                            routes[idx + 1].Segments[0].Latitude,
                            routes[idx + 1].Segments[0].Longitude);
                    }
                    else
                    { // take the coordinate itself.
                        coordinate2 = coordinates[idx + 1];
                    }

                    // build the dummy route.
                    routes[idx] = this.BuildDummyRoute(vehicle, coordinate1, coordinate2);
                }
            }

            // concatenate the routes.
            var route = routes[0];
            for (int idx = 1; idx < routes.Length; idx++)
            {
                route = Route.Concatenate(route, routes[idx]);
            }
            return route;
        }
예제 #10
0
 /// <summary>
 /// Returns true if the given point is connected for a radius of at least the given weight.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="point"></param>
 /// <param name="weight"></param>
 /// <returns></returns>
 public bool CheckConnectivity(Vehicle vehicle, RouterPoint point, float weight)
 {
     return(_router.CheckConnectivity(vehicle, point, weight));
 }
        /// <summary>
        /// Compares all routes against the reference router.
        /// </summary>
        public void TestCompareAll(string embeddedName, bool contract)
        {
            // build the routing settings.
            IOsmRoutingInterpreter interpreter = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();

            // get the osm data source.
            IBasicRouterDataSource<LiveEdge> data = this.BuildDykstraDataSource(interpreter, embeddedName);

            // build the reference router.;
            Router referenceRouter = this.BuildDykstraRouter(
                this.BuildDykstraDataSource(interpreter, embeddedName), interpreter,
                    new DykstraRoutingLive(data.TagsIndex));

            // build the router to be tested.
            Router router = this.BuildRouter(interpreter, embeddedName, contract);

            // 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] = 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);
            }

            // limit tests to a fixed number.
            int maxTestCount = 1000;
            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 = router.Calculate(Vehicle.Car,
                            resolved[fromIdx], resolved[toIdx]);

                        if (referenceRoute != null)
                        {
                            Assert.IsNotNull(referenceRoute);
                            Assert.IsNotNull(route);
                            this.CompareRoutes(referenceRoute, route);
                        }
                    }
                }
            }
        }
예제 #12
0
 /// <summary>
 /// Returns all points located at a given weight (distance/time) from the orgin.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="orgine"></param>
 /// <param name="weight"></param>
 /// <returns></returns>
 public HashSet <GeoCoordinate> CalculateRange(Vehicle vehicle, RouterPoint orgine, float weight)
 {
     return(_router.CalculateRange(vehicle, orgine, weight));
 }
예제 #13
0
 /// <summary>
 /// Calculates a route between one source and many target points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="source"></param>
 /// <param name="targets"></param>
 /// <returns></returns>
 public double[] CalculateOneToManyWeight(Vehicle vehicle, RouterPoint source, RouterPoint[] targets)
 {
     return(_router.CalculateOneToManyWeight(vehicle, source, targets));
 }
예제 #14
0
 /// <summary>
 /// Calculates the weight between two given points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <returns></returns>
 public double CalculateWeight(Vehicle vehicle, RouterPoint source, RouterPoint target)
 {
     return(_router.CalculateWeight(vehicle, source, target));
 }
예제 #15
0
파일: Router.cs 프로젝트: UnifyKit/OsmSharp
        /// <summary>
        /// Returns all points located at a given weight (distance/time) from the orgin.
        /// </summary>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <param name="orgine"></param>
        /// <param name="weight"></param>
        /// <returns></returns>
        public HashSet<GeoCoordinate> CalculateRange(Vehicle vehicle, RouterPoint orgine, float weight)
        {
            if (vehicle.UniqueName != orgine.Vehicle.UniqueName)
            { // vehicles are different.
                throw new ArgumentException(string.Format("Given vehicle profile does not match resolved points, {0} and {1} are given, expecting identical profiles.",
                    vehicle.UniqueName, orgine.Vehicle.UniqueName));
            }

            return _router.CalculateRange(vehicle, orgine, weight);
        }
예제 #16
0
        /// <summary>
        /// Builds a route along all the given point in the order given by the tsp solution.
        /// </summary>
        /// <returns></returns>
        public Route BuildRoute(Vehicle vehicle, RouterPoint[] resolved, GeoCoordinate[] coordinates, OsmSharp.Logistics.Routes.IRoute tspSolution, bool isRound)
        {
            // sort resolved and coordinates.
            var solution = tspSolution.ToArray();
            var size = isRound ? solution.Length + 1 : solution.Length;
            var sortedResolved = new RouterPoint[size];
            var sortedCoordinates = new GeoCoordinate[size];
            for (int idx = 0; idx < solution.Length; idx++)
            {
                sortedResolved[idx] = resolved[solution[idx]];
                sortedCoordinates[idx] = coordinates[solution[idx]];
            }

            // make round if needed.
            if (isRound)
            {
                sortedResolved[size - 1] = sortedResolved[0];
                sortedCoordinates[size - 1] = sortedCoordinates[0];
            }

            // build the route.
            return this.BuildRoute(vehicle, sortedResolved, sortedCoordinates);
        }
예제 #17
0
파일: Router.cs 프로젝트: UnifyKit/OsmSharp
        /// <summary>
        /// Calculates the weight between two given points.
        /// </summary>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public double CalculateWeight(Vehicle vehicle, RouterPoint source, RouterPoint target)
        {
            if (source.Vehicle.UniqueName != target.Vehicle.UniqueName)
            { // vehicles are different.
                throw new ArgumentException(string.Format("Not all vehicle profiles match, {0} and {1} are given, expecting identical profiles.",
                    source.Vehicle.UniqueName, target.Vehicle.UniqueName));
            }
            if (vehicle.UniqueName != target.Vehicle.UniqueName)
            { // vehicles are different.
                throw new ArgumentException(string.Format("Given vehicle profile does not match resolved points, {0} and {1} are given, expecting identical profiles.",
                    vehicle.UniqueName, target.Vehicle.UniqueName));
            }

            return _router.CalculateWeight(vehicle, source, target);
        }
예제 #18
0
 void mapControl1_MapMouseClick(MapControlEventArgs e)
 {
     if (_router != null)
     {
         if (_point1 == null)
         {
             _point1 = _router.Resolve(Vehicle.Car, e.Position);
         }
         else if (_point2 == null)
         {
             _point2 = _router.Resolve(Vehicle.Car, e.Position);
         }
         else
         {
             _point1 = _point2;
             _point2 = _router.Resolve(Vehicle.Car, e.Position);
         }
         if (_point1 != null && _point2 != null)
         {
             Route route = _router.Calculate(Vehicle.Car,
                 _point1, _point2);
             if (route != null)
             {
                 _routeLayer.Clear();
                 _routeLayer.AddRoute(route);
             }
         }
     }
 }
        public void RoutingRegressionTest2()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            SimpleTagsIndex tags_index = new SimpleTagsIndex();

            // do the data processing.
            DynamicGraphRouterDataSource<LiveEdge> memory_data =
                new DynamicGraphRouterDataSource<LiveEdge>(tags_index);
            LiveGraphOsmStreamTarget target_data = new LiveGraphOsmStreamTarget(
                memory_data, interpreter, memory_data.TagsIndex);
            XmlOsmStreamSource data_processor_source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_network.osm"));
            OsmStreamFilterSort sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(data_processor_source);
            target_data.RegisterSource(sorter);
            target_data.Pull();

            IBasicRouter<LiveEdge> basic_router = new DykstraRoutingLive(memory_data.TagsIndex);
            Router router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);

            // build coordinates list of resolved points.
            List<GeoCoordinate> 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.0582178, 3.7195025));

            testPoints.Add(new GeoCoordinate(51.0581727, 3.7195833));
            testPoints.Add(new GeoCoordinate(51.0581483, 3.7195553));
            //testPoints.Add(new GeoCoordinate(51.0581219, 3.7195231));
            //testPoints.Add(new GeoCoordinate(51.0580965, 3.7194918));

            testPoints.Add(new GeoCoordinate(51.0581883, 3.7196617));
            testPoints.Add(new GeoCoordinate(51.0581628, 3.7196889));

            // build a matrix of routes between all points.
            Route[][] referenceRoutes = new Route[testPoints.Count][];
            int[] 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.CreateLiveFrom(
                        memory_data, basic_router, interpreter);

                    // resolve points.
                    RouterPoint from = router.Resolve(Vehicle.Car, testPoints[fromIdx]);
                    RouterPoint 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.
            PermutationEnumerable<int> enumerator = new PermutationEnumerable<int>(
                permuationArray);
            foreach (int[] permutation in enumerator)
            {
                //int[] permutation = new int[] { 5, 0, 1, 2, 4, 3, 6, 7, 8 };

                //// incrementally resolve points.
                //// create router from scratch.
                //router = new Router<SimpleWeighedEdge>(memory_data, interpreter, basic_router);

                //// resolve in the order of the permutation.
                //RouterPoint[] resolvedPoints = new RouterPoint[permutation.Length];
                //resolvedPoints[permutation[0]] = router.Resolve(VehicleEnum.Car, testPoints[permutation[0]]);
                //for (int idx = 1; idx < permutation.Length; idx++)
                //{
                //    resolvedPoints[permutation[idx]] = router.Resolve(VehicleEnum.Car, testPoints[permutation[idx]]);

                //    for (int fromIdx = 0; fromIdx <= idx; fromIdx++)
                //    {
                //        for (int toIdx = 0; toIdx <= idx; toIdx++)
                //        {
                //            // calculate route.
                //            OsmSharpRoute route = router.Calculate(VehicleEnum.Car,
                //                resolvedPoints[permutation[fromIdx]], resolvedPoints[permutation[toIdx]]);

                //            Assert.AreEqual(referenceRoutes[permutation[fromIdx]][permutation[toIdx]].TotalDistance,
                //                route.TotalDistance, 0.1);
                //        }
                //    }
                //}

                // create router from scratch.
                router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);

                // resolve in the order of the permutation.
                RouterPoint[] 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.
                        Route route = router.Calculate(Vehicle.Car, resolvedPoints[fromIdx], resolvedPoints[toIdx]);

                        Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 0.1);
                    }
                }
            }
        }
예제 #20
0
 /// <summary>
 /// Calculates a route between two given points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="source">The source point.</param>
 /// <param name="target">The target point.</param>
 /// <param name="max">The maximum weight to stop the calculation.</param>
 /// <returns></returns>
 public Route Calculate(Vehicle vehicle, RouterPoint source, RouterPoint target, float max)
 {
     return _router.Calculate(vehicle, source, target, max);
 }
예제 #21
0
파일: Router.cs 프로젝트: JoeCooper/routing
        /// <summary>
        /// Calculates all routes between one source and many target points.
        /// </summary>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <param name="source"></param>
        /// <param name="targets"></param>
        /// <param name="max">The maximum weight to stop the calculation.</param>
        /// <param name="geometryOnly">Flag to return .</param>
        /// <param name="cancellationToken">An optional cancellation token.</param>
        /// <returns></returns>
        public Route[] CalculateOneToMany(Vehicle vehicle, RouterPoint source, RouterPoint[] targets, float max = float.MaxValue, bool geometryOnly = false, CancellationToken cancellationToken = new CancellationToken())
        {
            if (vehicle == null) { throw new ArgumentNullException("vehicle"); }
            if (source == null) { throw new ArgumentNullException("source"); }
            if (targets == null) { throw new ArgumentNullException("targets"); }

            foreach (var target in targets)
            {
                if (source.Vehicle.UniqueName != target.Vehicle.UniqueName)
                { // vehicles are different.
                    throw new ArgumentException(string.Format("Not all vehicle profiles match, {0} and {1} are given, expecting identical profiles.",
                        source.Vehicle.UniqueName, target.Vehicle.UniqueName));
                }
                if (vehicle.UniqueName != target.Vehicle.UniqueName)
                { // vehicles are different.
                    throw new ArgumentException(string.Format("Given vehicle profile does not match resolved points, {0} and {1} are given, expecting identical profiles.",
                        vehicle.UniqueName, target.Vehicle.UniqueName));
                }
            }

            return _router.CalculateOneToMany(vehicle, source, targets, max, geometryOnly, cancellationToken);
        }
예제 #22
0
 /// <summary>
 /// Calculates all routes between many sources/targets.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="sources"></param>
 /// <param name="targets"></param>
 /// <returns></returns>
 public Route[][] CalculateManyToMany(Vehicle vehicle, RouterPoint[] sources, RouterPoint[] targets)
 {
     return _router.CalculateManyToMany(vehicle, sources, targets);
 }
예제 #23
0
파일: Router.cs 프로젝트: JoeCooper/routing
        /// <summary>
        /// Calculates the weight between two given points.
        /// </summary>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <param name="cancellationToken">An optional cancellation token.</param>
        /// <returns></returns>
        public double CalculateWeight(Vehicle vehicle, RouterPoint source, RouterPoint target, CancellationToken cancellationToken = new CancellationToken())
        {
            if (vehicle == null) { throw new ArgumentNullException("vehicle"); }
            if (source == null) { throw new ArgumentNullException("source"); }
            if (target == null) { throw new ArgumentNullException("target"); }

            if (source.Vehicle.UniqueName != target.Vehicle.UniqueName)
            { // vehicles are different.
                throw new ArgumentException(string.Format("Not all vehicle profiles match, {0} and {1} are given, expecting identical profiles.",
                    source.Vehicle.UniqueName, target.Vehicle.UniqueName));
            }
            if (vehicle.UniqueName != target.Vehicle.UniqueName)
            { // vehicles are different.
                throw new ArgumentException(string.Format("Given vehicle profile does not match resolved points, {0} and {1} are given, expecting identical profiles.",
                    vehicle.UniqueName, target.Vehicle.UniqueName));
            }

            return _router.CalculateWeight(vehicle, source, target, cancellationToken);
        }
예제 #24
0
 /// <summary>
 /// Calculates all routes between one source and many target points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="source"></param>
 /// <param name="targets"></param>
 /// <returns></returns>
 public Route[] CalculateOneToMany(Vehicle vehicle, RouterPoint source, RouterPoint[] targets)
 {
     return _router.CalculateOneToMany(vehicle, source, targets);
 }
        public void RoutingSerializationCHSortedRoutingComparisonTest()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";

            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // do the data processing.
            var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                   Assembly.GetExecutingAssembly()
                                                                           .GetManifestResourceStream(embeddedString)),
                                                               interpreter,
                                                               Vehicle.Car);

            // create serializer.
            var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(true);

            // serialize/deserialize.
            TagsCollectionBase metaData = new TagsCollection();
            metaData.Add("some_key", "some_value");
            byte[] byteArray;
            using (var stream = new MemoryStream())
            {
                try
                {
                    routingSerializer.Serialize(stream, original, metaData);
                    byteArray = stream.ToArray();
                }
                catch (Exception)
                {
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                    throw;
                }
            }

            IBasicRouterDataSource<CHEdgeData> deserializedVersion =
                routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData);
            Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0));
            Assert.IsTrue(deserializedVersion.SupportsProfile(Vehicle.Car));
            Assert.IsFalse(deserializedVersion.SupportsProfile(Vehicle.Bicycle));

            // create reference router.
            original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                   Assembly.GetExecutingAssembly()
                                                                           .GetManifestResourceStream(embeddedString)),
                                                               interpreter,
                                                               Vehicle.Car);
            var basicRouterOriginal = new CHRouter();
            Router referenceRouter = Router.CreateCHFrom(
                original, basicRouterOriginal, interpreter);

            // try to do some routing on the deserialized version.
            var basicRouter = new CHRouter();
            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(VehicleEnum.Car,
            //                resolvedReference[fromIdx], resolvedReference[toIdx]);
            //            OsmSharpRoute route = router.Calculate(VehicleEnum.Car,
            //                resolved[fromIdx], resolved[toIdx]);

            //            Assert.IsNotNull(referenceRoute);
            //            Assert.IsNotNull(route);
            //            //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);
            //        }
            //    }
        }
예제 #26
0
 /// <summary>
 /// Calculates a route between one source and many target points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="source"></param>
 /// <param name="targets"></param>
 /// <returns></returns>
 public double[] CalculateOneToManyWeight(Vehicle vehicle, RouterPoint source, RouterPoint[] targets)
 {
     return _router.CalculateOneToManyWeight(vehicle, source, targets);
 }
        public void TestCHDataSourceTopologicalSortTest()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";

            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // do the data processing.
            var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                   Assembly.GetExecutingAssembly()
                                                                           .GetManifestResourceStream(embeddedString)),
                                                               interpreter,
                                                               Vehicle.Car);
            var sortedGraph = CHEdgeDataDataSourceSerializer.SortGraph(original);
            original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                   Assembly.GetExecutingAssembly()
                                                                           .GetManifestResourceStream(embeddedString)),
                                                               interpreter,
                                                               Vehicle.Car);
            var basicRouterOriginal = new CHRouter();
            Router referenceRouter = Router.CreateCHFrom(
                original, basicRouterOriginal, interpreter);

            // try to do some routing on the deserialized version.
            var basicRouter = new CHRouter();
            Router router = Router.CreateCHFrom(
                new DynamicGraphRouterDataSource<CHEdgeData>(sortedGraph, original.TagsIndex), 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]);

            //        Assert.IsNotNull(referenceRoute);
            //        Assert.IsNotNull(route);
            //        //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);
            //    }
            //}
        }
예제 #28
0
 /// <summary>
 /// Returns all points located at a given weight (distance/time) from the orgin.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="orgine"></param>
 /// <param name="weight"></param>
 /// <returns></returns>
 public HashSet<GeoCoordinate> CalculateRange(Vehicle vehicle, RouterPoint orgine, float weight)
 {
     return _router.CalculateRange(vehicle, orgine, weight);
 }
예제 #29
0
        public void RoutingRegressionTest3()
        {
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new TagsTableCollectionIndex();

            // do the data processing.
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(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.CreateLiveFrom(memoryData, basicRouter, interpreter);

            // build coordinates list of resolved points.
            var testPoints = new List<GeoCoordinate>();
            testPoints.Add(new GeoCoordinate(51.0581719, 3.7201622));
            testPoints.Add(new GeoCoordinate(51.0580439, 3.7202134));
            testPoints.Add(new GeoCoordinate(51.0580573, 3.7204378));
            testPoints.Add(new GeoCoordinate(51.0581862, 3.7203758));

            // 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.CreateLiveFrom(
                        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.CreateLiveFrom(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]);

                        Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 0.1);
                    }
                }
            }
        }
예제 #30
0
 /// <summary>
 /// Calculates a shortest route from a given point to any of the targets points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="source">The source point.</param>
 /// <param name="targets">The target point(s).</param>
 /// <param name="max">The maximum weight to stop the calculation.</param>
 /// <returns></returns>
 public Route CalculateToClosest(Vehicle vehicle, RouterPoint source, RouterPoint[] targets, float max)
 {
     return _router.CalculateToClosest(vehicle, source, targets, max);
 }
예제 #31
0
파일: Router.cs 프로젝트: UnifyKit/OsmSharp
        /// <summary>
        /// Calculates all routes between many sources/targets.
        /// </summary>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <param name="sources"></param>
        /// <param name="targets"></param>
        /// <returns></returns>
        public double[][] CalculateManyToManyWeight(Vehicle vehicle, RouterPoint[] sources, RouterPoint[] targets)
        {
            foreach (var source in sources)
            {
                foreach (var target in targets)
                {
                    if (source.Vehicle.UniqueName != target.Vehicle.UniqueName)
                    { // vehicles are different.
                        throw new ArgumentException(string.Format("Not all vehicle profiles match, {0} and {1} are given, expecting identical profiles.",
                            source.Vehicle.UniqueName, target.Vehicle.UniqueName));
                    }
                    if (vehicle.UniqueName != target.Vehicle.UniqueName)
                    { // vehicles are different.
                        throw new ArgumentException(string.Format("Given vehicle profile does not match resolved points, {0} and {1} are given, expecting identical profiles.",
                            vehicle.UniqueName, target.Vehicle.UniqueName));
                    }
                }
            }

            return _router.CalculateManyToManyWeight(vehicle, sources, targets);
        }
예제 #32
0
 /// <summary>
 /// Calculates the weight between two given points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <returns></returns>
 public double CalculateWeight(Vehicle vehicle, RouterPoint source, RouterPoint target)
 {
     return _router.CalculateWeight(vehicle, source, target);
 }
예제 #33
0
파일: Router.cs 프로젝트: UnifyKit/OsmSharp
        /// <summary>
        /// Calculates a shortest route from a given point to any of the targets points.
        /// </summary>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <param name="source">The source point.</param>
        /// <param name="targets">The target point(s).</param>
        /// <param name="max">The maximum weight to stop the calculation.</param>
        /// <param name="geometryOnly">Flag to return .</param>
        /// <returns></returns>
        public Route CalculateToClosest(Vehicle vehicle, RouterPoint source, RouterPoint[] targets, float max = float.MaxValue, bool geometryOnly = false)
        {
            foreach (var target in targets)
            {
                if (source.Vehicle.UniqueName != target.Vehicle.UniqueName)
                { // vehicles are different.
                    throw new ArgumentException(string.Format("Not all vehicle profiles match, {0} and {1} are given, expecting identical profiles.",
                        source.Vehicle.UniqueName, target.Vehicle.UniqueName));
                }
                if (vehicle.UniqueName != target.Vehicle.UniqueName)
                { // vehicles are different.
                    throw new ArgumentException(string.Format("Given vehicle profile does not match resolved points, {0} and {1} are given, expecting identical profiles.",
                        vehicle.UniqueName, target.Vehicle.UniqueName));
                }
            }

            return _router.CalculateToClosest(vehicle, source, targets, max);
        }
예제 #34
0
 /// <summary>
 /// Returns true if the given point is connected for a radius of at least the given weight.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="point"></param>
 /// <param name="weight"></param>
 /// <returns></returns>
 public bool[] CheckConnectivity(Vehicle vehicle, RouterPoint[] point, float weight)
 {
     return _router.CheckConnectivity(vehicle, point, weight);
 }
예제 #35
0
파일: Router.cs 프로젝트: UnifyKit/OsmSharp
        /// <summary>
        /// Returns true if the given point is connected for a radius of at least the given weight.
        /// </summary>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <param name="points"></param>
        /// <param name="weight"></param>
        /// <returns></returns>
        public bool[] CheckConnectivity(Vehicle vehicle, RouterPoint[] points, float weight)
        {
            foreach (var point in points)
            {
                if (vehicle.UniqueName != point.Vehicle.UniqueName)
                { // vehicles are different.
                    throw new ArgumentException(string.Format("Given vehicle profile does not match resolved points, {0} and {1} are given, expecting identical profiles.",
                        vehicle.UniqueName, point.Vehicle.UniqueName));
                }
            }

            return _router.CheckConnectivity(vehicle, points, weight);
        }
예제 #36
0
 /// <summary>
 /// Calculates a route between two given points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="source">The source point.</param>
 /// <param name="target">The target point.</param>
 /// <param name="max">The maximum weight to stop the calculation.</param>
 /// <returns></returns>
 public Route Calculate(Vehicle vehicle, RouterPoint source, RouterPoint target, float max)
 {
     return(_router.Calculate(vehicle, source, target, max));
 }