Ejemplo n.º 1
0
        public Destination Calculate(long callerId, Destination carDestination, Destination endDestination)
        {
            var network   = NodeNetwork.NodeNetwork.GetInstance();
            var startNode = new Node(GPSSystem.FindIntersection(carDestination.Location).Location);
            var endNodes  = AlgorithmTools.IntersectionTupleToNodeTuple(
                AlgorithmTools.GetIntersectionOrderForRoadSide(endDestination.Road, endDestination.Location));

            if (startNode.Equals(endNodes.Item1))
            {
                #if DEBUG
                AlgorithmDebuggerWindow.Instance.AddNetworkResult(_debuggerIndex++.ToString(), network,
                                                                  startNode, endNodes.Item2, endNodes);
                #endif
                return(endDestination);
            }

            AssignNodeValues(ref network, ref startNode);

            var nextNode = FindNextNodeOnBestRoute(ref network, endNodes.Item1);
            #if DEBUG
            AlgorithmDebuggerWindow.Instance.AddNetworkResult("DY" + _debuggerIndex++, network,
                                                              startNode, nextNode, endNodes);
            #endif
            var roadX = (startNode.PositionX - nextNode.PositionX) / 2.0 + nextNode.PositionX;
            var roadY = (startNode.PositionY - nextNode.PositionY) / 2.0 + nextNode.PositionY;
            return(new Destination
            {
                Location = new Vector(nextNode.PositionX, nextNode.PositionY),
                Road = GPSSystem.NearestRoad(new Vector(roadX, roadY))
            });
        }
Ejemplo n.º 2
0
 private void rd_Kruskal_CheckedChanged(object sender, EventArgs e)
 {
     if (rd_Kruskal.Checked)
     {
         algorithmTools = AlgorithmTools.Kruskal;
     }
 }
Ejemplo n.º 3
0
 private void rd_eule_CheckedChanged(object sender, EventArgs e)
 {
     if (rd_eule.Checked)
     {
         algorithmTools = AlgorithmTools.Euler;
     }
 }
Ejemplo n.º 4
0
 bool PrimNext()
 {
     if (!graph.nodeCollection.IsAllVisit)
     {
         graphUI1.Data.edgeCollection.Reset();
         GetEdge_prime();
         graphUI1.Invalidate();
         return(false);
     }
     else
     {
         graphUI1.Data.edgeCollection.Reset();
         graphUI1.Invalidate();
         MessageBox.Show("Thuật toán xong");
         string text = "Kết quả là \r\n";
         foreach (var item in graphUI1._list)
         {
             text += item.ToString() + "\r\n";
         }
         textBox.Text += text;
         MessageBox.Show(text);
         algorithmTools = AlgorithmTools.None;
         return(true);
     }
 }
Ejemplo n.º 5
0
 private void rd_prim_CheckedChanged(object sender, EventArgs e)
 {
     if (rd_prim.Checked)
     {
         algorithmTools = AlgorithmTools.Prim;
     }
 }
Ejemplo n.º 6
0
 private void btnResetEdge_Click(object sender, EventArgs e)
 {
     algorithmTools     = AlgorithmTools.None;
     rd_Kruskal.Checked = false;
     rd_prim.Checked    = false;
     graphUI1.Reset();
 }
Ejemplo n.º 7
0
        public Destination Calculate(long callerId, Destination carDestination, Destination endDestination)
        {
            var network   = NodeNetwork.NodeNetwork.GetInstance();
            var startNode = new Node(GPSSystem.FindIntersection(carDestination.Location).Location);
            var endNodes  = AlgorithmTools.IntersectionTupleToNodeTuple(
                AlgorithmTools.GetIntersectionOrderForRoadSide(endDestination.Road, endDestination.Location));

            Node   nextNode;
            double roadX, roadY;

            if (startNode.Equals(endNodes.Item1))
            {
                #if DEBUG
                AlgorithmDebuggerWindow.Instance.AddNetworkResult(_debuggerIndex++.ToString(), network,
                                                                  startNode, endNodes.Item2, endNodes);
                #endif
                return(endDestination);
            }

            if (_calculationCache.ContainsKey(callerId))
            {
                var tuple = _calculationCache[callerId];
                if (tuple.Item1.Equals(endDestination))
                {
                    var path     = tuple.Item2;
                    var thisNode = path.Single(n => n.Equals(startNode));
                    nextNode = thisNode.ConnectedTo;

                    #if DEBUG
                    AlgorithmDebuggerWindow.Instance.AddNetworkResult(_debuggerIndex++.ToString(), network,
                                                                      startNode, nextNode, endNodes);
                    #endif
                    roadX = (startNode.PositionX - nextNode.PositionX) / 2.0 + nextNode.PositionX;
                    roadY = (startNode.PositionY - nextNode.PositionY) / 2.0 + nextNode.PositionY;
                    return(new Destination
                    {
                        Location = new Vector(nextNode.PositionX, nextNode.PositionY),
                        Road = GPSSystem.NearestRoad(new Vector(roadX, roadY))
                    });
                }

                _calculationCache.Remove(callerId);
            }

            var endNode = endNodes.Item1;
            nextNode = CalculatePathNextNode(callerId, ref network, ref startNode, ref endNode, endDestination);

            #if DEBUG
            AlgorithmDebuggerWindow.Instance.AddNetworkResult("AS" + _debuggerIndex++, network,
                                                              startNode, nextNode, endNodes);
            #endif
            roadX = (startNode.PositionX - nextNode.PositionX) / 2.0 + nextNode.PositionX;
            roadY = (startNode.PositionY - nextNode.PositionY) / 2.0 + nextNode.PositionY;
            return(new Destination
            {
                Location = new Vector(nextNode.PositionX, nextNode.PositionY),
                Road = GPSSystem.NearestRoad(new Vector(roadX, roadY))
            });
        }
Ejemplo n.º 8
0
        bool KruskalNext()
        {
            graph.edgeCollection.Reset();
            int    lab1 = 0;
            int    lab2 = 0;
            string text = null;

            if (sodem_kruskal >= graph.edgeCollection.Count || graphUI1._list.Count == graph.n - 1)
            {
                graphUI1.Invalidate();
                MessageBox.Show("Thuật toán xong");
                text = "Kết quả là \r\n";
                foreach (var item in graphUI1._list)
                {
                    text += item.ToString() + "\r\n";
                }
                MessageBox.Show(text);
                textBox.Text  += text;
                algorithmTools = AlgorithmTools.None;
                return(true);
            }
            Edge edge = rd_euler.Items[sodem_kruskal] as Edge;

            text            = "Kiếm tra cạnh " + edge.ToString() + "\r\n";
            edge.IsSelected = true;
            if (label[edge.start.Index] != label[edge.end.Index])
            {
                text += "Lấy vì không tạo thành chu trình với các cạnh còn lại\r\n";
                graphUI1._list.Add(edge);
                if (label[edge.start.Index] > label[edge.end.Index])
                {
                    lab1 = label[edge.end.Index];
                    lab2 = label[edge.start.Index];
                }
                else
                {
                    lab2 = label[edge.end.Index];
                    lab1 = label[edge.start.Index];
                }
                for (int i = 0; i < graph.nodeCollection.Count; i++)
                {
                    if (label[i] == lab2)
                    {
                        label[i] = lab1;
                    }
                }
            }
            else
            {
                text += "Không lấy vì tạo thành chu trình với các cạnh còn lại\r\n";
            }
            textBox.Text += text;
            sodem_kruskal++;
            return(false);
        }
Ejemplo n.º 9
0
 public Form1()
 {
     InitializeComponent();
     rd_euler.FormattingEnabled = false;
     foreach (ToolStripItem item in toolStrip1.Items)
     {
         item.Click += new EventHandler(toolStripButton_Click);
     }
     graphUI1.DrawEvent   += GraphUI1_DrawEvent;
     graphUI1.GraphChange += GraphUI1_GraphChange;
     algorithmTools        = AlgorithmTools.None;
 }
Ejemplo n.º 10
0
 private void button1_Click(object sender, EventArgs e)
 {
     graphUI1.Reset();
     algorithmTools = AlgorithmTools.Prim;
     if (graphUI1.SelectedNode == null)
     {
         MessageBox.Show("Chọn đỉnh bắt đầu trước");
     }
     else
     {
         graphUI1.Prim(graphUI1.SelectedNode.node);
     }
 }
Ejemplo n.º 11
0
 private void button3_Click(object sender, EventArgs e)
 {
     graphUI1.Reset();
     algorithmTools = AlgorithmTools.Kruskal;
     graphUI1.Kruskal();
 }