public void ConnectionConstructorSetFromAndToProperties()
        {
            Node from = new Node();
            Node to = new Node();

            Connection target = new Connection(from, to);

            Assert.Equal(from, target.From);
            Assert.Equal(to, target.To);
        }
        public void ConnectionToPropertyReturnsCorrectNode()
        {
            Node from = new Node();
            Node to = new Node();

            Connection target = new Connection(from, to);

            Node newTo = new Node();
            target.To = newTo;

            Assert.Equal(newTo, target.To);
        }
        public void ConnectionFromPropertyReturnsCorrectNode()
        {
            Node from = new Node();
            Node to = new Node();

            Connection target = new Connection(from, to);

            Node newFrom = new Node();
            target.From = newFrom;

            Assert.Equal(newFrom, target.From);
        }
Beispiel #4
0
        /// <summary>
        /// Initializes internal properties before search
        /// </summary>
        /// <param name="from">The start point</param>
        /// <param name="to">The destination point</param>
        void Initialize(CandidatePoint from, CandidatePoint to)
        {
            _open.Clear();
            _close.Clear();

            // Add nodes reachable from the From point to the open list
            foreach (var connection in from.Road.Connections) {
                PartialPath path = new PartialPath() {End = connection.To, PathFromPrevious = connection.Geometry,
                                                                                            Length = Calculations.GetPathLength(from.MapPoint, connection.To.MapPoint, connection.Geometry),
                                                                                            EstimationToEnd = Calculations.GetDistance2D(connection.To.MapPoint, to.MapPoint)
                };

                if (_open.Contains(path)) {
                    if (_open[path.End].Length > path.Length) {
                        _open.Remove(_open[path.End]);
                        _open.Add(path);
                    }
                }
                else {
                    _open.Add(path);
                }
            }

            _temporaryConnections.Clear();
            // Add temporary connections to the TO point
            foreach (var targetConnections in to.Road.Connections) {
                Connection destinationConnection = new Connection(targetConnections.From, new Node(to.MapPoint)) { Geometry = to.Road };
                _temporaryConnections.Add(destinationConnection);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Builds road graph from map data
        /// </summary>
        /// <param name="map">OSMDB with preprocessed map data from OSM2Routing utility</param>
        public void Build(OSMDB map)
        {
            Dictionary<int, Node> usedNodes = new Dictionary<int, Node>();

            foreach (var segment in map.Ways) {
                Node start = GetOrCreateNode(segment.Nodes[0], usedNodes);
                try {
                    start.MapPoint = map.Nodes[segment.Nodes[0]];
                }
                catch (ArgumentException) {
                    continue; // If the start node was not found in the database, skip this path completely
                }

                Node end = GetOrCreateNode(segment.Nodes[segment.Nodes.Count - 1], usedNodes);
                try {
                    end.MapPoint = map.Nodes[segment.Nodes[segment.Nodes.Count - 1]];
                }
                catch (ArgumentException) {
                    continue; // If the end node was not found in the database, skip this path completely
                }

                double speed = double.Parse(segment.Tags["speed"].Value, System.Globalization.CultureInfo.InvariantCulture);
                int wayId = int.Parse(segment.Tags["way-id"].Value, System.Globalization.CultureInfo.InvariantCulture);

                ConnectionGeometry geometry = new ConnectionGeometry();
                geometry.WayID = wayId;
                foreach (var n in segment.Nodes) {
                    try {
                        OSMNode mapPoint = map.Nodes[n];
                        geometry.Nodes.Add(mapPoint);
                        //geometry.Nodes.Add(new PointGeo(mapPoint.Latitude, mapPoint.Longitude));
                    }
                    catch (ArgumentException) {
                    continue; // If an intermediate node was not found in the database, skip just that node
                    }
                }
                _connectionGeometries.Add(geometry);

                if (segment.Tags["accessible"].Value == "yes") {
                    Connection sc = new Connection(start, end) { Speed = speed, Geometry = geometry };
                    geometry.Connections.Add(sc);
                    _connections.Add(sc);
                }

                if (segment.Tags["accessible-reverse"].Value == "yes") {
                    Connection sc = new Connection(end, start) { Speed = speed, Geometry = geometry };
                    geometry.Connections.Add(sc);
                    _connections.Add(sc);
                }
            }
        }