示例#1
0
 /// <summary>
 /// Creates a new router point.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="vehicle"></param>
 /// <param name="location"></param>
 public RouterPoint(long id, Vehicle vehicle, GeoCoordinate location)
 {
     _id = id;
     this.Location = location;
     this.Vehicle = vehicle;
     this.Tags = new List<KeyValuePair<string, string>>();
 }
示例#2
0
        /// <summary>
        /// Calculcates the metrics.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public override Dictionary<string, double> Calculate(Vehicle vehicle, AggregatedPoint p)
        {
            Dictionary<string, double> result = new Dictionary<string, double>();
            result.Add(DISTANCE_KEY, 0);
            result.Add(TIME_KEY, 0);

            Aggregated next = p;
            while (next != null)
            {
                if (next is AggregatedPoint)
                {
                    AggregatedPoint point = (next as AggregatedPoint);
                    this.CalculatePointMetrics(vehicle, result, point);
                }
                if (next is AggregatedArc)
                {
                    AggregatedArc arc = (next as AggregatedArc);
                    this.CalculateArcMetrics(vehicle, result, arc);
                }

                next = next.GetNext();
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="vehicle"></param>
        public CHEdgeGraphFileStreamTarget(Stream stream, Vehicle vehicle)
        {
            _graphStream = stream;

            var tagsIndex = new SimpleTagsIndex();
            var interpreter = new OsmRoutingInterpreter();
            _graph = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
            _graphTarget = new CHEdgeGraphOsmStreamTarget(
                _graph, interpreter, _graph.TagsIndex, vehicle);
        }
示例#4
0
        /// <summary>
        /// Tests the probable speed.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="speed"></param>
        /// <param name="tags"></param>
        protected void TextProbableSpeed(Vehicle vehicle, double speed, params string[] tags)
        {
            // build tags collection.
            SimpleTagsCollection tagsCollection = new SimpleTagsCollection();
            for (int idx = 0; idx < tags.Length; idx = idx + 2)
            {
                tagsCollection.Add(tags[idx], tags[idx + 1]);
            }

            Assert.AreEqual(speed, vehicle.ProbableSpeed(tagsCollection).Value);
        }
示例#5
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();
 }
示例#6
0
        /// <summary>
        /// Calculates the TSP.
        /// </summary>
        /// <param name="dataStream"></param>
        /// <param name="csvStream"></param>
        /// <param name="pbf"></param>
        /// <param name="vehicleEnum"></param>
        /// <returns></returns>
        private Route CalculateTSP(Stream dataStream, Stream csvStream, bool pbf, Vehicle vehicleEnum)
        {
            // create the router.
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();
            Router router = Router.CreateLiveFrom(
                new XmlOsmStreamSource(dataStream), interpreter);

            // read the source files.
            const int latitudeIdx = 2;
            const int longitudeIdx = 3;
            string[][] pointStrings = DelimitedFileHandler.ReadDelimitedFileFromStream(
                csvStream,
                DelimiterType.DotCommaSeperated);
            var points = new List<RouterPoint>();
            int cnt = 10;
            foreach (string[] line in pointStrings)
            {
                if (points.Count >= cnt)
                {
                    break;
                }
                var latitudeString = (string)line[latitudeIdx];
                var longitudeString = (string)line[longitudeIdx];

                //string route_ud = (string)line[1];

                double longitude = 0;
                double latitude = 0;
                if (double.TryParse(longitudeString, System.Globalization.NumberStyles.Any,
                    System.Globalization.CultureInfo.InvariantCulture, out longitude) &&
                   double.TryParse(latitudeString, System.Globalization.NumberStyles.Any,
                    System.Globalization.CultureInfo.InvariantCulture, out latitude))
                {
                    var point = new GeoCoordinate(latitude, longitude);

                    RouterPoint resolved = router.Resolve(Vehicle.Car, point);
                    if (resolved != null && router.CheckConnectivity(Vehicle.Car, resolved, 100))
                    {
                        points.Add(resolved);
                    }
                }
            }

            var tspSolver = new RouterTSPWrapper<RouterTSP>(
                new RouterTSPAEXGenetic(), router, interpreter);
            return tspSolver.CalculateTSP(vehicleEnum, points.ToArray());
        }
示例#7
0
        /// <summary>
        /// Tests the can traverse functionality.
        /// </summary>
        protected void TestVehicleCanTranverse(Vehicle vehicle, bool result, params string[] tags)
        {
            // build tags collection.
            SimpleTagsCollection tagsCollection = new SimpleTagsCollection();
            for (int idx = 0; idx < tags.Length; idx = idx + 2)
            {
                tagsCollection.Add(tags[idx], tags[idx + 1]);
            }

            if (result)
            { // assume the result is true.
                Assert.IsTrue(vehicle.CanTraverse(tagsCollection));
            }
            else
            { // assume the result is false.
                Assert.IsFalse(vehicle.CanTraverse(tagsCollection));
            }
        }
示例#8
0
        /// <summary>
        /// Returns true if the edge is a suitable candidate as a target for a point to be resolved on.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="pointTags"></param>
        /// <param name="edgeTags"></param>
        /// <returns></returns>
        public bool MatchWithEdge(Vehicle vehicle,
            TagsCollectionBase pointTags, TagsCollectionBase edgeTags)
        {
            if (pointTags == null || pointTags.Count == 0)
            { // when the point has no tags it has no requirements.
                return true;
            }

            if (edgeTags == null || edgeTags.Count == 0)
            { // when the edge has no tags, no way to verify.
                return false;
            }

            string pointName, edgeName;
            if (pointTags.TryGetValue("name", out pointName) &&
                edgeTags.TryGetValue("name", out edgeName))
            { // both have names.
                return (pointName == edgeName);
            }
            return false;
        }
示例#9
0
 /// <summary>
 /// Returns true if the given vehicle type is supported.
 /// </summary>
 /// <param name="vehicle"></param>
 /// <returns></returns>
 public bool SupportsVehicle(Vehicle vehicle)
 {
     return _router.SupportsVehicle(vehicle);
 }
示例#10
0
 /// <summary>
 /// Does the metric calculations.
 /// </summary>
 /// <param name="vehicle"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 public abstract Dictionary<string, double> Calculate(Vehicle vehicle, AggregatedPoint p);
示例#11
0
 /// <summary>
 /// Searches for a closeby link to the road network.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="coordinate">The location of the point to search.</param>
 /// <returns></returns>
 /// <remarks>Similar to resolve except no resolved point is created.</remarks>
 public GeoCoordinate Search(Vehicle vehicle, GeoCoordinate coordinate)
 {
     return _router.Search(vehicle, coordinate);
 }
示例#12
0
 /// <summary>
 /// Searches for a closeby link to the road network.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="delta">The size of the box to search in.</param>
 /// <param name="coordinate">The location of the point to search.</param>
 /// <returns></returns>
 /// <remarks>Similar to resolve except no resolved point is created.</remarks>
 public GeoCoordinate Search(Vehicle vehicle, float delta, GeoCoordinate coordinate)
 {
     return _router.Search(vehicle, delta, coordinate);
 }
示例#13
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);
 }
示例#14
0
 /// <summary>
 /// Resolves all the given points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="delta">The size of the box to search in.</param>
 /// <param name="coordinates">The location of the points to resolve.</param>
 /// <param name="matcher">The matcher containing some matching algorithm.</param>
 /// <param name="matchingTags">Extra matching data.</param>
 /// <returns></returns>
 public RouterPoint[] Resolve(Vehicle vehicle, float delta, GeoCoordinate[] coordinates, 
     IEdgeMatcher matcher, TagsCollection[] matchingTags)
 {
     return _router.Resolve(vehicle, delta, coordinates, matcher, matchingTags);
 }
示例#15
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)
        {
            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);
        }
示例#16
0
        /// <summary>
        /// Tests the edge matcher in combination with dykstra routing.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="highway"></param>
        /// <param name="vehicle"></param>
        /// <param name="matcher"></param>
        /// <param name="pointName"></param>
        /// <param name="notFound"></param>
        private void TestResolveOnEdgeSingle(string name, string highway, 
            Vehicle vehicle, IEdgeMatcher matcher, 
            string pointName, bool notFound)
        {
            var fromName = new GeoCoordinate(51.0003, 4.0007);
            var toName = new GeoCoordinate(51.0003, 4.0008);

            var fromNoname = new GeoCoordinate(51.0, 4.0007);
            var toNoname = new GeoCoordinate(51.0, 4.0008);

            TagsCollection pointTags = new SimpleTagsCollection();
            pointTags["name"] = pointName;

            TagsCollection tags = new SimpleTagsCollection();
            tags["highway"] = highway;
            //tags["name"] = name;

            var tagsIndex = new SimpleTagsIndex();

            // do the data processing.
            var data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            uint vertexNoname1 = data.AddVertex((float)fromNoname.Latitude, (float)fromNoname.Longitude);
            uint vertexNoname2 = data.AddVertex((float)toNoname.Latitude, (float)toNoname.Longitude);
            data.AddArc(vertexNoname1, vertexNoname2, new LiveEdge()
            {
                Forward = true,
                Tags = tagsIndex.Add(tags)
            }, null);
            tags = new SimpleTagsCollection();
            tags["highway"] = highway;
            tags["name"] = name;
            uint vertexName1 = data.AddVertex((float)fromName.Latitude, (float)fromName.Longitude);
            uint vertexName2 = data.AddVertex((float)toName.Latitude, (float)toName.Longitude);
            data.AddArc(vertexName1, vertexName2, new LiveEdge()
            {
                Forward = true,
                Tags = tagsIndex.Add(tags)
            }, null);

            IRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            // creates the data.
            IBasicRouter<LiveEdge> router = new DykstraRoutingLive();

            var nonameLocation = new GeoCoordinate(
                (fromNoname.Latitude + toNoname.Latitude) / 2.0,
                (fromNoname.Longitude + toNoname.Longitude) / 2.0);
            //            var nameLocation = new GeoCoordinate(
            //                (fromName.Latitude + toName.Latitude) / 2.0,
            //                (fromName.Longitude + toName.Longitude) / 2.0);

            const float delta = 0.01f;
            SearchClosestResult result = router.SearchClosest(data, interpreter, vehicle, nonameLocation, delta, matcher, pointTags);
            if (result.Distance < double.MaxValue)
            { // there is a result.
                Assert.IsFalse(notFound, "A result was found but was supposed not to  be found!");

                if (name == pointName)
                { // the name location was supposed to be found!
                    Assert.IsTrue(result.Vertex1 == vertexName1 || result.Vertex1 == vertexName2);
                    Assert.IsTrue(result.Vertex2 == vertexName1 || result.Vertex2 == vertexName2);
                }
                else
                { // the noname location was supposed to be found!
                    Assert.IsTrue(result.Vertex1 == vertexNoname1 || result.Vertex1 == vertexNoname2);
                    Assert.IsTrue(result.Vertex2 == vertexNoname1 || result.Vertex2 == vertexNoname2);
                }
                return;
            }
            Assert.IsTrue(notFound, "A result was not found but was supposed to be found!");
        }
示例#17
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);
 }
示例#18
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);
 }
示例#19
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);
 }
示例#20
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);
 }
示例#21
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);
 }
示例#22
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>
        /// <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);
        }
示例#23
0
 /// <summary>
 /// Resolves a point.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="coordinate">The location of the point to resolve.</param>
 /// <param name="verticesOnly">Returns vertices only..</param>
 /// <returns></returns>
 public RouterPoint Resolve(Vehicle vehicle, GeoCoordinate coordinate, bool verticesOnly)
 {
     return _router.Resolve(vehicle, coordinate, verticesOnly);
 }
示例#24
0
 /// <summary>
 /// Tests the edge matcher in combination with dykstra routing.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="highway"></param>
 /// <param name="vehicle"></param>
 /// <param name="matcher"></param>
 /// <param name="found"></param>
 private void TestResolveOnEdge(string name, string highway,
     Vehicle vehicle, IEdgeMatcher matcher, bool found)
 {
     this.TestResolveOnEdgeSingle(name, highway, vehicle, null, null, !found);
     this.TestResolveOnEdgeSingle(name, highway, vehicle, matcher, null, !found);
     this.TestResolveOnEdgeSingle(name, highway, vehicle, matcher, name, !found);
 }
示例#25
0
 /// <summary>
 /// Resolves all the given points.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="delta">The size of the box to search in.</param>
 /// <param name="coordinate">The location of the point to resolve.</param>
 /// <returns></returns>
 public RouterPoint[] Resolve(Vehicle vehicle, float delta, GeoCoordinate[] coordinate)
 {
     return _router.Resolve(vehicle, delta, coordinate);
 }
示例#26
0
 /// <summary>
 /// Calculates all routes from a given resolved point to the routable graph.
 /// </summary>
 public new PathSegmentVisitList RouteResolvedGraph(OsmSharp.Routing.Vehicle vehicle, RouterPoint resolvedPoint, bool?backwards)
 {
     return(base.RouteResolvedGraph(vehicle, resolvedPoint, backwards));
 }
示例#27
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);
 }
示例#28
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);
 }
示例#29
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="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);
        }
示例#30
0
 /// <summary>
 /// Returns true if the given vehicle is supported.
 /// </summary>
 public override bool SupportsVehicle(OsmSharp.Routing.Vehicle vehicle)
 {
     // TODO: ask interpreter.
     return(true);
 }
示例#31
0
 /// <summary>
 /// Resolves a point.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="coordinate">The location of the point to resolve.</param>
 /// <returns></returns>
 public RouterPoint Resolve(Vehicle vehicle, GeoCoordinate coordinate)
 {
     return _router.Resolve(vehicle, coordinate);
 }
示例#32
0
 /// <summary>
 /// Constructs a route from a given path.
 /// </summary>
 public Route ConstructRouteFromPath(OsmSharp.Routing.Vehicle vehicle, PathSegment <long> route, RouterPoint source, RouterPoint target, bool geometryOnly)
 {
     return(this.ConstructRoute(vehicle, route, source, target, geometryOnly));
 }
示例#33
0
 /// <summary>
 /// Resolves a point.
 /// </summary>
 /// <param name="vehicle">The vehicle profile.</param>
 /// <param name="coordinate">The location of the point to resolve.</param>
 /// <param name="matcher">The matcher containing some matching algorithm.</param>
 /// <param name="matchingTags">Extra matching data.</param>
 /// <returns></returns>
 public RouterPoint Resolve(Vehicle vehicle, GeoCoordinate coordinate, IEdgeMatcher matcher, 
     TagsCollection matchingTags)
 {
     return _router.Resolve(vehicle, coordinate, matcher, matchingTags);
 }