Ejemplo n.º 1
0
        public Nod(Nod x)
        {
            Template = (ControlTemplate)FindResource("ButtonControlRound");

            Height = 40;
            Width = 40;
            AllowDrop = true;
            Cursor = Cursors.SizeAll;

            this.ApplyTemplate();
            vec = x.vec;
            myCanvas = x.myCanvas;
            val = x.val;
            Content = x.Content;

        }
Ejemplo n.º 2
0
        public Nod new_nod(Point epos)
        {
            Nod nod = new Nod();
          //  Nod.myCanvas = myCanvas;
            nod.PreviewMouseLeftButtonDown += this.MouseDown;
            nod.PreviewMouseLeftButtonUp += this.MouseUp;
            nod.PreviewMouseRightButtonUp += this.DeleteNod;
            nod.Content = noduri.Count + 1;
            Canvas.SetLeft(nod, 53);
            Canvas.SetTop(nod, 42);
            Canvas.SetZIndex(nod, noduri.Count + 51);

            MovingObject = nod;
            noduri.Add(nod);
            FirstX =  epos.X;
            FirstY =  epos.Y;

            nod.myCanvas = myCanvas;
            myCanvas.Children.Add(nod);
            
            return nod;
        }
Ejemplo n.º 3
0
        void setup(object sender = null, EventArgs e = null)
        {
            n = graf.noduri.Count;
            for (int i = 0; i < n; i++)
            {
                graf.noduri[i].val = i + 1;
                graf.noduri[i].Disable();
                graf.noduri[i].Update();
            }

            for (int i = 0; i < graf.muchii.Count; i++)
                graf.muchii[i].textBox.IsReadOnly = true;

            graf.muchii.Sort(cmp);


            CoadaMuchii = new List<Muchie>();
            Rez.Clear();


            WatchMuchii.ItemsSource = CoadaMuchii;

            WatchNoduri.Items.Refresh();
            WatchMuchii.Items.Refresh();
            WatchSelected.Items.Refresh();

            Nr = 0;
            sum = 0;
            this.WatchNr.Content = "Muchii selectate: 0";

            NoduriSol = new List<int>();
            if (n > 0)
                nextSelected = graf.noduri[0];
            addMuchii();

            prepare_next_step();
        }
Ejemplo n.º 4
0
        void prepare_next_step()
        {
            graf.refresh(1);

            if (Nr == n - 1)
                System.Windows.MessageBox.Show("Terminat cu succes", "Succes", MessageBoxButton.OK, MessageBoxImage.Information);

            if (n == 0) { Explicatii.Text = "Introduceți graful."; return; }

            if (Nr == n - 1)
            {
                Explicatii.Text = "S-a obținut arborele parțial de cost minim pentru graful dat:\n";
                Explicatii.Text += "Suma costurilor este: " + sum;
                return;
            }

            if (graf.muchii.Count == 0) { Explicatii.Text = "Nu există muchii - graful nu este conex!"; return; }
            if (CoadaMuchii.Count == 0) { Explicatii.Text = "Graful nu este conex!"; return; }


            if (NoduriSol.Count == 0)
            {
                NoduriSol.Add(1);
                Explicatii.Text = "Alegem ca nod de început nodul 1 și adăugăm la Heap toate muchiile care pornesc de aici\n";
            }
            else
            {
                Explicatii.Text = "Selectat fiind nodul " + nextSelected.Content.ToString() + " adaugam la Heap toate muchiile către noduri care nu fac parte din arborele curent\n";
            }



            Muchie m = selectMuchie();
            if (NoduriSol.Contains(numar(m.x)))
                nextSelected = m.y;
            else
                nextSelected = m.x;



            Explicatii.Text += "Muchia dintre nodurile " + m.Xstr + " si " + m.Ystr + " are cost minim asa ca selectam nodul " + nextSelected.Content.ToString() + " si adăugăm muchia la soluție"; 

        }
Ejemplo n.º 5
0
 int numar(Nod nod)
 {
     return Int32.Parse(nod.Content.ToString());
 }
Ejemplo n.º 6
0
        public Muchie new_muchie(Nod n1, Nod n2, int dist = 0)
        {
            if (muchii.FindAll(muci => muci.x == n1 && muci.y == n2 || muci.x == n2 && muci.y == n1).Count != 0) return null;
            Muchie muc = new Muchie(n1, n2, dist, myCanvas, this);

            n1.vec.Add(muc);
            n2.vec.Add(muc);
            muchii.Add(muc);
            myCanvas.Children.Add(muc);

            muc.Actual_Pos();
        
            n1.IsEnabled = true;
            n2.IsEnabled = true;

            return muc;
        }
 void new_nod(object sender, MouseEventArgs e)
 {
     if (construct == 0) return;
     if (muchiestate == 1)
         add_muchie(sender, e);
     n1 = null;
     Nod b = graf.new_nod(e.GetPosition(graf_nod_but));
     b.Click += draw_muchie;
 }
        void draw_muchie(object sender, EventArgs e)
        {
            if (construct == 0 || muchiestate == 0) return;

            if (n1 == null)
            {
                n1 = sender as Nod;
                n1.IsEnabled = false;
                return;
            }

            Nod n2 = sender as Nod;
            graf.new_muchie(n1, n2);

            n1 = null;
            add_muchie(sender, e);
        }