Example #1
0
        /// <summary>
        /// On each iteration we need to discover the reachable nodes by going through all the edges that are incident on the node
        /// </summary>
        /// <param name="node"></param>
        private void AddReachableNodes(Node node)
        {
            Node          neighbour;
            ReachableNode rn;

            foreach (Edge edge in node.Edges)
            {
                neighbour = GetNeighbour(node, edge);
                //make sure we don't add the node we came from
                if (node.EdgeCameFrom == null || neighbour != GetNeighbour(node, node.EdgeCameFrom))
                {
                    //make sure we don't add a node already in the cloud
                    if (!cloud.Contains(neighbour))
                    {
                        //if the node is already reachable
                        if (reachableNodes.HasNode(neighbour))
                        {
                            //if the distance from this edge is smaller than the current total cost
                            //amend the reachable node using the current edge
                            if (node.TotalCost + edge.Length < neighbour.TotalCost)
                            {
                                rn      = reachableNodes.GetReachableNodeFromNode(neighbour);
                                rn.Edge = edge;
                            }
                        }
                        else
                        {
                            rn = new ReachableNode(neighbour, edge);
                            reachableNodes.AddReachableNode(rn);
                        }
                    }
                }
            }
        }
Example #2
0
        public void BellmanAddReachableNodes(Node node)
        {
            Node          neighbour;
            ReachableNode rn;

            foreach (Edge edge in node.Edges)
            {
                neighbour = GetNeighbour(node, edge);
                //make sure we don't add the node we came from
                if (node.EdgeCameFrom == null || neighbour != GetNeighbour(node, node.EdgeCameFrom))
                {
                    //make sure we don't add a node already in the cloud
                    //zaten bulutta olan bir düğümü eklememek için
                    if (!_cloud.Contains(neighbour))
                    {
                        //if the node is already reachable
                        //erişilebilir düğümler içinde komşu varsa
                        if (_reachableNodes.HasNode(neighbour))
                        {
                            //if the distance from this edge is smaller than the current total cost
                            //amend the reachable node using the current edge
                            if (node.TotalCost + edge.Length < neighbour.TotalCost)
                            {
                                rn      = _reachableNodes.GetReachableNodeFromNode(neighbour);
                                rn.Edge = edge;
                            }
                        }
                        else
                        {
                            rn = new ReachableNode(neighbour, edge);
                            _reachableNodes.AddReachableNode(rn);
                        }
                    }
                }
            }
        }