Beispiel #1
0
        void link(Node n1, Node n2)
        {
            if (GetRebro(n1, n2) == null)
            {
                Rebro r = new Rebro(n1, n2);
                r.Weight = Convert.ToInt32(WeightTB.Text);
                rebra.Add(r);
                n1.linkedN.Add(n2);
                n2.linkedN.Add(n1);
                for (int i = 0; i < n1.linkedN.Count; i++)
                {
                    int j = i;
                    int f = i;
                    while (j != n1.linkedN.Count)
                    {
                        if (n1.linkedN[f].num > n1.linkedN[j].num)
                        {
                            Node node = n1.linkedN[j];
                            n1.linkedN[j] = n1.linkedN[f];
                            n1.linkedN[f] = node;
                            f             = j;
                        }
                        j++;
                    }
                }
                for (int i = 0; i < n2.linkedN.Count; i++)
                {
                    int j = i;
                    int f = i;
                    while (j != n2.linkedN.Count)
                    {
                        if (n2.linkedN[f].num > n2.linkedN[j].num)
                        {
                            Node node = n2.linkedN[j];
                            n2.linkedN[j] = n2.linkedN[f];
                            n2.linkedN[f] = node;
                            f             = j;
                        }
                        j++;
                    }
                }
            }
            else
            {
                GetRebro(n1, n2).Weight = Convert.ToInt32(WeightTB.Text);
            }

            foreach (Node no in nodes)
            {
                if (no.CheckSelect())
                {
                    no.Select();
                }
            }
            //dataGridView1.Refresh();
        }
Beispiel #2
0
        void link(Node n1, Node n2)
        {
            Rebro r = new Rebro(n1, n2);

            rebra.Add(r);
            n1.linkedN.Add(n2);
            n2.linkedN.Add(n1);
            foreach (Node no in nodes)
            {
                if (no.CheckSelect())
                {
                    no.Select();
                }
            }
        }
Beispiel #3
0
        private void button5_Click(object sender, EventArgs e)
        {
            Graphics g = pBox.CreateGraphics();

            label2.Text = "";
            foreach (Node n in nodes)
            {
                n.IsChecked  = false;
                n.predPoint  = null;
                n.ValueMetka = 99999;
                n.nonfillEllipse(g);
            }
            foreach (Rebro r in rebra)
            {
                r.visited = false;
            }
            this.Refresh();
            pBox.Select();

            Node[] nodesD = new Node[nodes.Count];
            nodes.CopyTo(nodesD);
            Rebro[] rebraD = new Rebro[rebra.Count];
            rebra.CopyTo(rebraD);
            int  start  = Convert.ToInt32(FirstTB.Text);
            int  finish = Convert.ToInt32(LastTB.Text);
            Node begin  = new Node();
            Node end    = new Node();

            foreach (Node no in nodes)
            {
                if (no.num == start)
                {
                    begin = no;
                }
            }
            foreach (Node n in nodes)
            {
                if (n.num == finish)
                {
                    end = n;
                }
            }
            Dejkstra d = new Dejkstra(nodesD, rebraD);

            d.AlgoritmRun(begin);
            List <Node> minPath = d.MinPath1(end);

            Node[] Path = new Node[minPath.Count];
            minPath.CopyTo(Path);
            label2.Text += " " + start.ToString() + " >> ";
            Array.Reverse(Path);
            Pen pen;

            pen       = new Pen(Brushes.Blue);
            pen.Width = 2;
            begin.fillEllipse();
            begin.draw(g);
            Wait(0.5);
            g.DrawLine(pen, GetRebro(begin, Path[0]).node1.x, GetRebro(begin, Path[0]).node1.y, GetRebro(begin, Path[0]).node2.x, GetRebro(begin, Path[0]).node2.y);
            Wait(0.5);

            for (int i = 0; i < Path.Count(); i++)
            {
                Path[i].fillEllipse();
                Path[i].draw(g);
                Wait(0.5);
                if (i + 1 != Path.Count())
                {
                    g.DrawLine(pen, GetRebro(Path[i + 1], Path[i]).node1.x, GetRebro(Path[i + 1], Path[i]).node1.y, GetRebro(Path[i + 1], Path[i]).node2.x, GetRebro(Path[i + 1], Path[i]).node2.y);
                    Wait(0.5);
                }
                label2.Text += Path[i].num.ToString() + " >> ";
            }
        }