コード例 #1
0
        ///// <summary>
        ///// Adds an edge.
        ///// </summary>
        ///// <param name="forward"></param>
        ///// <param name="from"></param>
        ///// <param name="to"></param>
        ///// <param name="tags"></param>
        ///// <param name="intermediates"></param>
        //protected override void AddRoadEdge(TagsCollectionBase tags, bool forward, uint from, uint to, List<GeoCoordinateSimple> intermediates)
        //{
        //    float latitude;
        //    float longitude;
        //    GeoCoordinate fromCoordinate = null;
        //    if (this.DynamicGraph.GetVertex(from, out latitude, out longitude))
        //    { //
        //        fromCoordinate = new GeoCoordinate(latitude, longitude);
        //    }
        //    GeoCoordinate toCoordinate = null;
        //    if (this.DynamicGraph.GetVertex(to, out latitude, out longitude))
        //    { //
        //        toCoordinate = new GeoCoordinate(latitude, longitude);
        //    }

        //    if (fromCoordinate != null && toCoordinate != null)
        //    { // calculate the edge data.
        //        var edgeData = this.CalculateEdgeData(this.Interpreter.EdgeInterpreter, this.TagsIndex, tags, forward, fromCoordinate, toCoordinate, intermediates);

        //        ICoordinateCollection intermediatesCollection = null;
        //        if(intermediates != null)
        //        {
        //            intermediatesCollection = new CoordinateArrayCollection<GeoCoordinateSimple>(intermediates.ToArray());
        //        }
        //        this.DynamicGraph.AddEdge(from, to, edgeData, intermediatesCollection, this.EdgeComparer);
        //    }
        //}

        /// <summary>
        /// Calculates edge data.
        /// </summary>
        /// <param name="tagsIndex"></param>
        /// <param name="tags"></param>
        /// <param name="directionForward"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="edgeInterpreter"></param>
        /// <param name="intermediates"></param>
        /// <returns></returns>
        protected override LiveEdge CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsCollectionIndex tagsIndex,
                                                      TagsCollectionBase tags, bool tagsForward, GeoCoordinate from, GeoCoordinate to, List <GeoCoordinateSimple> intermediates)
        {
            if (edgeInterpreter == null)
            {
                throw new ArgumentNullException("edgeInterpreter");
            }
            if (tagsIndex == null)
            {
                throw new ArgumentNullException("tagsIndex");
            }
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            uint tagsId = tagsIndex.Add(tags);

            return(new LiveEdge()
            {
                Forward = tagsForward,
                Tags = tagsId,
                Distance = (float)from.DistanceEstimate(to).Value
            });
        }
コード例 #2
0
 /// <summary>
 /// Creates a new routing interpreter with given constraints.
 /// </summary>
 /// <param name="constraints"></param>
 public OsmRoutingInterpreter(IRoutingConstraints constraints)
 {
     _edgeInterpreter = new Edge.EdgeInterpreter();
     _constraints = constraints;
     
     this.FillRelevantTags();
 } 
コード例 #3
0
        /// <summary>
        /// Calculates edge data.
        /// </summary>
        /// <param name="edgeInterpreter"></param>
        /// <param name="tagsIndex"></param>
        /// <param name="tags"></param>
        /// <param name="directionForward"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        protected override CHEdgeData CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsCollectionIndex tagsIndex,
                                                        TagsCollectionBase tags, bool directionForward, GeoCoordinate from, GeoCoordinate to)
        {
            double weight    = _vehicle.Weight(tags, from, to);
            bool?  direction = _vehicle.IsOneWay(tags);
            bool   forward   = false;
            bool   backward  = false;

            if (!direction.HasValue)
            { // both directions.
                forward  = true;
                backward = true;
            }
            else
            { // define back/forward.
                forward = (directionForward && direction.Value) ||
                          (!directionForward && !direction.Value);
                backward = (directionForward && !direction.Value) ||
                           (!directionForward && direction.Value);
            }

            // initialize the edge data.
            CHEdgeData edgeData = new CHEdgeData()
            {
                Weight = (float)weight,
                Tags   = tagsIndex.Add(
                    tags),
                ContractedVertexId = 0
            };

            edgeData.SetDirection(forward, backward, true);
            return(edgeData);
        }
コード例 #4
0
        /// <summary>
        /// Creates a new routing intepreter with default settings.
        /// </summary>
        public OsmRoutingInterpreter()
        {
            _edgeInterpreter = new Edge.EdgeInterpreter();
            _constraints = null;

            this.FillRelevantTags();
        }
コード例 #5
0
        /// <summary>
        /// Creates a new routing intepreter with default settings.
        /// </summary>
        public OsmRoutingInterpreter()
        {
            _edgeInterpreter = new Edge.EdgeInterpreter();
            _constraints     = null;

            this.FillRelevantTags();
        }
コード例 #6
0
        /// <summary>
        /// Calculates edge data.
        /// </summary>
        /// <param name="tagsIndex"></param>
        /// <param name="tags"></param>
        /// <param name="directionForward"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="edgeInterpreter"></param>
        /// <returns></returns>
        protected override LiveEdge CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsIndex tagsIndex,
                                                      TagsCollection tags, bool directionForward, GeoCoordinate from, GeoCoordinate to)
        {
            if (edgeInterpreter == null)
            {
                throw new ArgumentNullException("edgeInterpreter");
            }
            if (tagsIndex == null)
            {
                throw new ArgumentNullException("tagsIndex");
            }
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            return(new LiveEdge()
            {
                Forward = directionForward,
                Tags = tagsIndex.Add(tags)
            });
        }
コード例 #7
0
        /// <summary>
        /// Creates a new routing interpreter with given constraints.
        /// </summary>
        /// <param name="constraints"></param>
        public OsmRoutingInterpreter(IRoutingConstraints constraints)
        {
            _edgeInterpreter = new Edge.EdgeInterpreter();
            _constraints     = constraints;

            this.FillRelevantTags();
        }
コード例 #8
0
        /// <summary>
        /// Calculates edge data.
        /// </summary>
        /// <param name="tagsIndex"></param>
        /// <param name="tags"></param>
        /// <param name="tagsForward"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="edgeInterpreter"></param>
        /// <param name="intermediates"></param>
        /// <returns></returns>
        protected override Edge CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsIndex tagsIndex,
                                                  TagsCollectionBase tags, bool tagsForward, GeoCoordinate from, GeoCoordinate to, List <GeoCoordinateSimple> intermediates)
        {
            if (edgeInterpreter == null)
            {
                throw new ArgumentNullException("edgeInterpreter");
            }
            if (tagsIndex == null)
            {
                throw new ArgumentNullException("tagsIndex");
            }
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            uint tagsId = tagsIndex.Add(tags);

            var shapeInBox = true;

            if (intermediates != null)
            { // verify shape-in-box.
                var box = new GeoCoordinateBox(from, to);
                for (int idx = 0; idx < intermediates.Count; idx++)
                {
                    if (!box.Contains(intermediates[idx].Longitude, intermediates[idx].Latitude))
                    { // shape not in box.
                        shapeInBox = false;
                        break;
                    }
                }
            }

            return(new Edge()
            {
                Forward = tagsForward,
                Tags = tagsId,
                Distance = (float)from.DistanceEstimate(to).Value,
                ShapeInBox = shapeInBox
            });
        }
コード例 #9
0
 /// <summary>
 /// Returns true if the edge is traversable.
 /// </summary>
 /// <param name="edgeInterpreter"></param>
 /// <param name="tagsIndex"></param>
 /// <param name="tags"></param>
 /// <returns></returns>
 protected override bool CalculateIsTraversable(IEdgeInterpreter edgeInterpreter,
                                                ITagsIndex tagsIndex, TagsCollection tags)
 {
     if (_vehicles.Count > 0)
     { // limit only to vehicles in this list.
         foreach (Vehicle vehicle in _vehicles)
         {
             if (vehicle.CanTraverse(tags))
             { // one of them is enough.
                 return(true);
             }
         }
         return(false);
     }
     return(edgeInterpreter.IsRoutable(tags));
 }
コード例 #10
0
        /// <summary>
        /// Calculates edge data.
        /// </summary>
        /// <param name="edgeInterpreter"></param>
        /// <param name="tagsIndex"></param>
        /// <param name="tags"></param>
        /// <param name="tagsForward"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="intermediates"></param>
        /// <returns></returns>
        protected override CHEdgeData CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsCollectionIndex tagsIndex,
                                                        TagsCollectionBase tags, bool tagsForward, GeoCoordinate from, GeoCoordinate to, List <GeoCoordinateSimple> intermediates)
        {
            var direction = _vehicle.IsOneWay(tags);
            var forward   = false;
            var backward  = false;

            if (!direction.HasValue)
            { // both directions.
                forward  = true;
                backward = true;
            }
            else
            {     // define back/forward.
                if (tagsForward)
                { // relatively same direction.
                    forward  = direction.Value;
                    backward = !direction.Value;
                }
                else
                { // relatively opposite direction.
                    forward  = !direction.Value;
                    backward = direction.Value;
                }
            }

            // add tags.
            var tagsId = tagsIndex.Add(tags);

            // calculate weight including intermediates.
            float weight   = 0;
            var   previous = from;

            if (intermediates != null)
            {
                for (int idx = 0; idx < intermediates.Count; idx++)
                {
                    var current = new GeoCoordinate(intermediates[idx].Latitude, intermediates[idx].Longitude);
                    weight   = weight + (float)_vehicle.Weight(tags, previous, current);
                    previous = current;
                }
            }
            weight = weight + (float)_vehicle.Weight(tags, previous, to);

            // initialize the edge data.
            return(new CHEdgeData(tagsId, tagsForward, forward, backward, weight));
        }
コード例 #11
0
        /// <summary>
        /// Calculates edge data.
        /// </summary>
        /// <param name="tagsIndex"></param>
        /// <param name="tags"></param>
        /// <param name="directionForward"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="edgeInterpreter"></param>
        /// <param name="intermediates"></param>
        /// <returns></returns>
        protected override LiveEdge CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsCollectionIndex tagsIndex,
                                                      TagsCollectionBase tags, bool directionForward, GeoCoordinate from, GeoCoordinate to, List <GeoCoordinateSimple> intermediates)
        {
            if (edgeInterpreter == null)
            {
                throw new ArgumentNullException("edgeInterpreter");
            }
            if (tagsIndex == null)
            {
                throw new ArgumentNullException("tagsIndex");
            }
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            uint tagsId = tagsIndex.Add(tags);

            GeoCoordinateSimple[] coordinates = null;
            if (intermediates != null && intermediates.Count > 0)
            { // only instiate if needed.
                coordinates = intermediates.ToArray();
            }

            return(new LiveEdge()
            {
                Forward = directionForward,
                Tags = tagsId,
                Distance = (float)from.DistanceEstimate(to).Value
            });
        }
コード例 #12
0
 /// <summary>
 /// Returns true if the edge can be traversed.
 /// </summary>
 /// <param name="edgeInterpreter"></param>
 /// <param name="tagsIndex"></param>
 /// <param name="tags"></param>
 /// <returns></returns>
 protected abstract bool CalculateIsTraversable(IEdgeInterpreter edgeInterpreter, ITagsCollectionIndex tagsIndex,
                                                TagsCollectionBase tags);
コード例 #13
0
 /// <summary>
 /// Calculates the edge data.
 /// </summary>
 /// <returns></returns>
 protected abstract TEdgeData CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsCollectionIndex tagsIndex, TagsCollectionBase tags,
                                                bool directionForward, GeoCoordinate from, GeoCoordinate to);
コード例 #14
0
 /// <summary>
 /// Creates a new highway constraint.
 /// </summary>
 /// <param name="edge_intepreter"></param>
 public DefaultHighwayConstraints(IEdgeInterpreter edge_intepreter)
 {
     _edge_intepreter = edge_intepreter;
 }
コード例 #15
0
 /// <summary>
 /// Returns true if the edge is traversable.
 /// </summary>
 /// <param name="edgeInterpreter"></param>
 /// <param name="tagsIndex"></param>
 /// <param name="tags"></param>
 /// <returns></returns>
 protected override bool CalculateIsTraversable(IEdgeInterpreter edgeInterpreter,
                                                ITagsCollectionIndex tagsIndex, TagsCollectionBase tags)
 {
     return(_vehicle.CanTraverse(tags));
 }
コード例 #16
0
 /// <summary>
 /// Calculates the edge data.
 /// </summary>
 /// <returns></returns>
 protected abstract TEdgeData CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsIndex tagsIndex, TagsCollectionBase tags,
                                                bool tagsForward, GeoCoordinate from, GeoCoordinate to, List <GeoCoordinateSimple> intermediates);
コード例 #17
0
 //        /// <summary>
 //        /// Holds the local label.
 //        /// </summary>
 //        private RoutingLabel _local_label =
 //            new RoutingLabel('L', "OnlyLocalAccessible");
 //        /// <summary>
 //        /// Holds the general label.
 //        /// </summary>
 //        private RoutingLabel _general_label =
 //            new RoutingLabel('R', "GeneralAccessible");
 /// <summary>
 /// Creates a new highway constraint.
 /// </summary>
 /// <param name="edge_intepreter"></param>
 public DefaultHighwayConstraints(IEdgeInterpreter edge_intepreter)
 {
     _edge_intepreter = edge_intepreter;
 }
コード例 #18
0
 /// <summary>
 /// Creates a new highway constraint.
 /// </summary>
 /// <param name="edge_intepreter"></param>
 public DefaultCarConstraints(IEdgeInterpreter edge_intepreter)
 {
     _edge_intepreter = edge_intepreter;
 }
コード例 #19
0
 /// <summary>
 /// Returns true if the edge is traversable.
 /// </summary>
 /// <param name="edgeInterpreter"></param>
 /// <param name="tagsIndex"></param>
 /// <param name="tags"></param>
 /// <returns></returns>
 protected override bool CalculateIsTraversable(IEdgeInterpreter edgeInterpreter,
                                                ITagsIndex tagsIndex, TagsCollection tags)
 {
     return(edgeInterpreter.IsRoutable(tags));
 }
コード例 #20
0
 /// <summary>
 /// Creates a new highway constraint.
 /// </summary>
 /// <param name="edge_intepreter"></param>
 public DefaultCarConstraints(IEdgeInterpreter edge_intepreter)
 {
     _edge_intepreter = edge_intepreter;
 }
コード例 #21
0
 /// <summary>
 /// Creates a new routing interpreter a custom edge interpreter.
 /// </summary>
 /// <param name="interpreter"></param>
 public OsmRoutingInterpreter(IEdgeInterpreter interpreter)
 {
     _edgeInterpreter = interpreter;
     _constraints     = null;
 }
コード例 #22
0
 /// <summary>
 /// Creates a new routing interpreter with given constraints.
 /// </summary>
 /// <param name="constraints"></param>
 public OsmRoutingInterpreter(IRoutingConstraints constraints)
 {
     _edge_interpreter = new Edge.EdgeInterpreter();
     _constraints = constraints;
 }
コード例 #23
0
 /// <summary>
 /// Creates a new routing intepreter with default settings.
 /// </summary>
 public OsmRoutingInterpreter()
 {
     _edge_interpreter = new Edge.EdgeInterpreter();
     _constraints = null;
     //_constraints = new DefaultHighwayConstraints(_edge_interpreter);
 }
コード例 #24
0
 /// <summary>
 /// Creates a new routing interpreter a custom edge interpreter.
 /// </summary>
 /// <param name="interpreter"></param>
 public OsmRoutingInterpreter(IEdgeInterpreter interpreter)
 {
     _edgeInterpreter = interpreter;
     _constraints = null;
 }