Beispiel #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);
                        }
                    }
                }
            }
        }
 private static 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);
                 }
             }
         }
     }
 }
 public void AddReachableNode(ReachableNode rn)
 {
     if (_nodes.Contains(rn.Node))
     {
         ReachableNode oldRN = GetReachableNodeFromNode(rn.Node);
         if (rn.Edge.Length < oldRN.Edge.Length)
             oldRN.Edge = rn.Edge;
     }
     else
     {
         _rnList.Add(rn);
         _nodes.Add(rn.Node);
         _rnDictionary.Add(rn.Node, rn);
     }
 }
Beispiel #4
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);
                        }
                    }
                }
            }
        }
Beispiel #5
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>
        public void DijkstraAddReachableNodes(Node node)
        {
            Node          neighbour;
            ReachableNode rn;

            foreach (Edge edge in node.Edges)
            {
                neighbour = GetNeighbour(node, edge);       // TODO: Komşuyu veriyor = neighbour
                                                            // TODO: benden
                                                            //Application.Current.Dispatcher.Invoke((Action)delegate
                                                            //{
                                                            //    // TODO: s1s0 start node yazma
                                                            //    txt2 = new TextBlock();
                                                            //    txt2.Text = node.Label;
                                                            //    txt2.FontSize = 12;
                                                            //    txt2.TextAlignment = TextAlignment.Center;
                                                            //    Grid.SetRow(txt2, 1);
                                                            //    Grid.SetColumn(txt2, 0);

                //    myGrid.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                //        (ThreadStart)delegate ()
                //        {
                //            myGrid.Children.Add(txt2);

                //        });
                //    Thread.Sleep(100);
                //});
                //buraya

                /* Application.Current.Dispatcher.Invoke((Action)delegate
                 * {
                 *   //TODO: ADD (kenar,...)
                 *   txtSatir = new TextBlock();
                 *   txtSatir.Text = neighbour.Edges[0].Length + "," + txt2.Text;
                 *   txtSatir.FontSize = 12;
                 *   txtSatir.TextAlignment = TextAlignment.Center;
                 *   for (int j = 1; j < _nodes.Count; j++)
                 *   {//TODO: sıkıntı burada kayma var!
                 *       if (neighbour.Label != txt2.Text && neighbour.Label == dizi[j]) //kayma komşular
                 *       {
                 *           Console.WriteLine(j + ". Komşu: \n" + txtSatir.Text);
                 *           Grid.SetColumn(txtSatir, j);
                 *       }
                 *   }
                 *
                 *   Grid.SetRow(txtSatir, 1);
                 *
                 *   myGrid.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                 *       (ThreadStart)delegate ()
                 *       {
                 *           myGrid.Children.Add(txtSatir);
                 *
                 *       });
                 *   Thread.Sleep(100);
                 * });*/
                //make sure we don't add the node we came from
                //geldiğimiz düğümü eklememek için
                if (node.EdgeCameFrom == null || neighbour != GetNeighbour(node, node.EdgeCameFrom))
                {
                    //make sure we don't add a node already in the cloud
                    //zaten bulutta bulunan bir düğümü eklememek için
                    if (!_cloud.Contains(neighbour))
                    {
                        //if the node is already reachable
                        //düğüm ulaşılabilirse
                        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

                            //bu kenardaki mesafe mevcut toplam maliyetten küçükse,
                            //geçerli kenar kullanılarak ulaşılabilir düğümü değiştirilir
                            if (node.TotalCost + edge.Length < neighbour.TotalCost)
                            {
                                rn      = _reachableNodes.GetReachableNodeFromNode(neighbour);
                                rn.Edge = edge;
                            }
                        }
                        else
                        {
                            rn = new ReachableNode(neighbour, edge);
                            _reachableNodes.AddReachableNode(rn);
                        }
                    }
                }
            }
        }
 public void RemoveReachableNode(ReachableNode rn)
 {
     _rnList.Remove(rn);
     _nodes.Remove(rn.Node);
 }