コード例 #1
0
        private void asignaPesos(Point p)
        {
            int pmx, pmy; // PUNTO MEDIO EN X Y PUNTO MEDIO EN Y

            temp = grafo.encuentraArista(p);
            if (temp != null)
            {
                //    MessageBox.Show("Nodo Origen " + temp.origen.nombre + "\nNodo Destino " + temp.destino.nombre);
                numeric         = new NumericUpDown();
                numeric.Maximum = 10;
                numeric.Minimum = 1;
                if (temp.peso != 0)
                {
                    numeric.Value = temp.peso;
                }

                pmx          = (temp.origen.centro.X + temp.destino.centro.X) / 2;
                pmy          = (temp.origen.centro.Y + temp.destino.centro.Y) / 2;
                pmx         += 5;
                pmy         += 5;
                numeric.Name = "numeric";

                numeric.Width         = 40;
                numeric.Location      = new Point(pmx, pmy);
                numeric.ValueChanged += Numeric_ValueChanged;
                temp.peso             = Convert.ToInt32(numeric.Value);
                Controls.Add(numeric);
            }
        }
コード例 #2
0
        public override void grafoCn(int nodos, Graphics g)
        {
            double posx, posy;
            double centrox, centroy, distancia, angulo, angulo2;
            int    nomb = 1, a;
            Arista aux;
            Point  pos = new Point(200, 200);

            centrox   = 400;
            centroy   = 400;
            distancia = 220;
            angulo    = 10;
            angulo2   = (double)(360 / (double)nodos);

            for (a = 0; a < nodos; a++)
            {
                if (a == 0)
                {
                    posx   = (int)(centrox - (distancia * Math.Cos((90 * Math.PI) / 180.0)));
                    posy   = (int)(centroy - (distancia * Math.Sin((90 * Math.PI) / 180.0)));
                    pos.X  = (int)posx;
                    pos.Y  = (int)posy;
                    angulo = 90;
                }
                else
                {
                    angulo = (double)(angulo + angulo2);
                    posx   = (int)(centrox - distancia * Math.Cos((angulo * Math.PI) / 180.0));
                    posy   = (int)(centroy - distancia * Math.Sin((angulo * Math.PI) / 180.0));
                    pos.X  = (int)posx;
                    pos.Y  = (int)posy;
                }
                this.Add(new NodoP(nomb, pos));
                nomb++;
                if (nomb > 27)
                {
                    this.edoNom = true;
                }
                if (a > 0)
                {
                    aux         = new Arista(0);
                    aux.origen  = this[a - 1];
                    aux.destino = this[a];
                    this[a - 1].aristas.Add(aux);
                    aux         = new Arista(0);
                    aux.origen  = this[a];
                    aux.destino = this[a - 1];
                    this[a].aristas.Add(aux);
                }
            }
            aux         = new Arista(0);
            aux.origen  = this[a - 1];
            aux.destino = this[0];
            this[a - 1].aristas.Add(aux);
            aux         = new Arista(0);
            aux.origen  = this[0];
            aux.destino = this[a - 1];
            this[0].aristas.Add(aux);
            // this.ImprimirGrafo(g);
        }
コード例 #3
0
        public override void pintaEuler(Graphics g, List <NodoP> nodos)
        {
            coloreate();
            ImprimirGrafo(g, true);
            for (int i = 0; i < nodos.Count; i++)
            {
                NodoP aux = this.Find(x => x.Equals(nodos[i]));
                if (aux != null)
                {
                    aux.colorN = new SolidBrush(Color.LightBlue);
                    ImprimirGrafo(g, true);
                    if (i < nodos.Count - 1)
                    {
                        Arista aux2 = aux.aristas.Find(x => x.destino.Equals(nodos[i + 1]));
                        if (aux2 != null)
                        {
                            aux2.colorA = new Pen(Color.Red, 5);
                        }
                    }


                    Thread.Sleep(700);
                    ImprimirGrafo(g, true);
                }
            }
        }
コード例 #4
0
        public void algoritmoKruskal()
        {
            GrafoNoDirigido      grafoK      = new GrafoNoDirigido(grafo);
            List <List <NodoP> > componentes = grafoK.kruskal();

            rel = new List <Arista>();
            Arista temp;

            foreach (List <NodoP> np in componentes)
            {
                for (int i = 0; i < np.Count; i++)
                {
                    temp = new Arista(0);
                    int j = i + 1;
                    temp.peso   = buscaPeso(np[i], np[j]);
                    temp.origen = np[i];
                    i++;
                    temp.destino = np[i];
                    rel.Add(temp);
                }
            }

            rel = rel.OrderBy(x => x.peso).ToList();
            Componente componente = new Componente();

            componente.Show();
            componente.Next.Click += Next_Click;
        }
コード例 #5
0
        public Arista encuentraArista(Point p)
        {
            double m, b, y;
            double xp, yp, xn, yn, xnr, ynr;

            xp = p.X;
            yp = p.Y;
            int    sensibilidad = 5;
            Arista temp         = null;

            foreach (NodoP n in this)
            {
                foreach (Arista nr in n.aristas)
                {
                    xn  = n.centro.X;
                    yn  = n.centro.Y;
                    xnr = nr.destino.centro.X;
                    ynr = nr.destino.centro.Y;

                    if (n.Equals(nr.destino))
                    {
                        NodoP nAux = BuscaNodo(p);
                        if (nAux != null && nAux.Equals(n))
                        {
                            //n.aristas.Remove(nr);
                            temp = nr;
                            return(temp);
                        }
                    }

                    if ((xnr - xn) == 0)
                    {
                        if ((yp < yn && yp > ynr) || (yp > yn && yp < ynr))
                        {
                            if ((xp < xnr + sensibilidad && xp > xn - sensibilidad) || (xp > xnr - sensibilidad && xp < xn + sensibilidad))
                            {
                                //n.aristas.Remove(nr);
                                temp = nr;
                                return(temp);
                            }
                        }
                    }

                    m = (ynr - yn) / (xnr - xn);
                    b = yn - (m * xn);
                    y = m * xp + b;

                    if (yp >= y - sensibilidad && yp <= y + sensibilidad)
                    {
                        if ((xp < xnr + sensibilidad && xp > xn - sensibilidad) || (xp > xnr - sensibilidad && xp < xn + sensibilidad))
                        {
                            return(nr);
                        }
                    }
                }
            }
            return(null);
        }
コード例 #6
0
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            cordx = e.Location.X;
            cordy = e.Location.Y;
            int final = 1000;                     //punto final dar clic

            if (bandera == 4)                     //arista dirigida
            {
                if (binicio == true)              //nodo inicial tocado
                {
                    Arista arista = new Arista(); //crear nueva arista
                    for (int i = 0; i < nodos.Count(); i++)
                    {
                        if (cordx > nodos[i].getX() - 40 && cordx <nodos[i].getX() + 40 && cordy> nodos[i].getY() - 40 && cordy < nodos[i].getY() + 40)
                        {
                            final  = i;                              //punto final (i) guardado en final
                            bfinal = true;                           //ya se toco el punto final
                            arista.llenaArista(inicio, final, 0, 0); //le pongo sus datos
                            nodos[inicio].llenaarista(arista);       //agrega una arista a la lista de aristas
                        }
                    }
                }
            }
            if (bandera == 5) //arista no dirigida
            {
                if (binicio == true)
                {
                    Arista arista = new Arista();
                    for (int i = 0; i < nodos.Count(); i++)
                    {
                        if (cordx > nodos[i].getX() - 40 && cordx <nodos[i].getX() + 40 && cordy> nodos[i].getY() - 40 && cordy < nodos[i].getY() + 40)
                        {
                            final  = i;
                            bfinal = true; //ya se toco el punto final
                            //arista.llenaArista(inicio, final, 0, 0);
                            //nodos[inicio].llenaarista(arista); //puede ir, en la misma linea
                            arista.llenaArista(final, inicio, 0, 1);
                            nodos[final].llenaarista(arista); //puede regresar, en la misma linea
                        }
                    }
                }
            }
            if (bandera == 6)
            {
                bool uuu = false;
                for (int i = 0; i < nodos.Count; i++)
                {
                    for (int j = 0; j < nodos[i].aristas.Count; j++)
                    {
                        //y2-y1/x2-x1
                        int m = (nodos[nodos[i].aristas[j].getOrigen()].getX() - nodos[nodos[i].aristas[j].getDestino()].getX()) / (nodos[nodos[i].aristas[j].getOrigen()].getY() - nodos[nodos[i].aristas[j].getDestino()].getY());
                    }
                }
            }

            acciones1();
        }
コード例 #7
0
        public override Grafo complemento(Graphics g)
        {
            NodoP  nn;
            Arista nnr;
            Grafo  nuevo = new Grafo();

            foreach (NodoP np in this)
            {
                nn = new NodoP(np.nombre, np.centro);
                nuevo.Add(nn);
            }
            nuevo = new GrafoNoDirigido(nuevo);

            foreach (NodoP aux1 in this)                // Ciclo que recorre los nodos del grafo
            {
                if (aux1.aristas.Count == 0)            // si el nodo no tiene aristas
                {
                    foreach (NodoP aux2 in nuevo)       // Ciclo que recorre los nodos del grafo "copia"
                    {
                        if (aux1.nombre != aux2.nombre) // Condición para que el nodo no apunte a si mismo
                        {
                            nnr         = new Arista(0);
                            nnr.origen  = nuevo.Find(x => x.nombre.Equals(aux1.nombre));
                            nnr.destino = aux2;
                            nuevo.Find(x => x.nombre.Equals(aux1.nombre)).aristas.Add(nnr);
                        }
                    }
                }

                else // Si el nodo ya tiene Aristas
                {
                    foreach (NodoP aux2 in nuevo) // Ciclo que recorre los nodos
                    {
                        if (aux1.nombre != aux2.nombre) // Compara que el nodo no se apunte a si mismo
                        {
                            Arista r = new Arista(0);
                            r = aux1.aristas.Find(x => x.destino.nombre.Equals(aux2.nombre));
                            if (r == null)
                            {
                                nnr         = new Arista(0);
                                nnr.origen  = nuevo.Find(x => x.nombre.Equals(aux1.nombre));
                                nnr.destino = aux2;
                                if (nnr != null)
                                {
                                    nuevo.Find(x => x.nombre.Equals(aux1.nombre)).aristas.Add(nnr);
                                }
                            }
                        }
                    }
                }
            }

            //base.complemento(g);

            return(nuevo);
        }
コード例 #8
0
        public Grafo creaKn(int nodos)
        {
            Grafo  grafo = new Grafo();
            double posx, posy;
            double centrox, centroy, distancia, angulo, angulo2;
            int    nomb = 1, a;
            Arista aux;
            Point  pos = new Point(200, 200);

            centrox   = 400;
            centroy   = 400;
            distancia = 220;
            angulo    = 10;
            angulo2   = (double)(360 / (double)nodos);

            for (a = 0; a < nodos; a++)
            {
                if (a == 0)
                {
                    posx   = (int)(centrox - (distancia * Math.Cos((90 * Math.PI) / 180.0)));
                    posy   = (int)(centroy - (distancia * Math.Sin((90 * Math.PI) / 180.0)));
                    pos.X  = (int)posx;
                    pos.Y  = (int)posy;
                    angulo = 90;
                }
                else
                {
                    angulo = (float)(angulo + angulo2);
                    posx   = (int)(centrox - distancia * Math.Cos((angulo * Math.PI) / 180.0));
                    posy   = (int)(centroy - distancia * Math.Sin((angulo * Math.PI) / 180.0));
                    pos.X  = (int)posx;
                    pos.Y  = (int)posy;
                }
                grafo.Add(new NodoP(nomb, pos));
                nomb++;
                if (nomb > 27)
                {
                    grafo.edoNom = true;
                }
            }
            foreach (NodoP np in grafo)
            {
                foreach (NodoP np2 in grafo)
                {
                    if (np != np2)
                    {
                        aux         = new Arista(0);
                        aux.origen  = np;
                        aux.destino = np2;
                        np.aristas.Add(aux);
                    }
                }
            }
            return(grafo);
        }
コード例 #9
0
 private bool todoVisitado(NodoP nodo)
 {
     if (visitado == null)
     {
         visitado = new List <Arista>();
     }
     foreach (Arista nr in nodo.aristas)
     {
         Arista existeA = visitado.Find(x => x.Equals(nr));
         if (existeA == null)
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #10
0
        private void asignaPesos2(Point p) // pesos
        {
            int pmx, pmy;                  // PUNTO MEDIO EN X Y PUNTO MEDIO EN Y

            aux = grafo.encuentraArista(p);
            if (grafo.tipo == 2)
            {
                aux2 = grafo.encuentraSegundaArista(p);
            }
            if (aux != null)
            {
                // MessageBox.Show("Nodo Origen " + temp.origen.nombre + "\nNodo Destino " + temp.destino.nombre);
                //  numeric = new NumericUpDown();
                //  numeric.Maximum = 100;
                // numeric.Minimum = 1;
                texaux      = new TextBox();
                texaux.Text = "1";


                if (aux.peso != 0)
                {
                    texaux.Text = aux.peso.ToString();
                }

                pmx                 = (aux.origen.centro.X + aux.destino.centro.X) / 2;
                pmy                 = (aux.origen.centro.Y + aux.destino.centro.Y) / 2;
                pmx                += 5;
                pmy                += 5;
                texaux.Name         = "texaux";
                texaux.Width        = 40;
                texaux.Location     = new Point(pmx, pmy);
                texaux.TextChanged += texaux_TextChanged;
                aux.peso            = int.Parse(texaux.Text);
                if (grafo.tipo == 2)
                {
                    try { aux2.peso = int.Parse(texaux.Text); }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Area No Valida");
                    }
                }
                //aux2.peso = int.Parse(texaux.Text); //
                Controls.Add(texaux); //
            }
        }
コード例 #11
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            //  grafo.coloreate();
            //  asignaPropiedades();

            if (tope > circuito.Count)
            {
                asignaPropiedades();
                foreach (NodoP np in grafo)
                {
                    foreach (Arista nr in np.aristas)
                    {
                        np.colorN = new SolidBrush(Color.White);
                        nr.colorA = new Pen(Color.Black, 1);
                    }
                }
                grafo.coloreate();
                tope = 0;

                Form1_Paint(this, null);
            }
            else
            {
                for (int i = 0; i < tope; i++)
                {
                    NodoP aux = grafo.Find(x => x.Equals(circuito[i]));
                    if (aux != null)
                    {
                        aux.colorN = new SolidBrush(Color.LightBlue);
                        grafo.ImprimirGrafo(g, true);
                        if (i < circuito.Count - 1)
                        {
                            Arista aux2 = aux.aristas.Find(x => x.destino.Equals(circuito[i + 1]));
                            if (aux2 != null)
                            {
                                aux2.colorA = new Pen(Color.Red, 5);
                            }
                        }
                        grafo.ImprimirGrafo(g, true);
                    }
                }
            }

            tope++;
        }
コード例 #12
0
        public int dameA(NodoP np, Arista nr, Grafo grafo)
        {
            foreach (Arista aux2 in np.aristas)
            {
                foreach (NodoP nodo in grafo)
                {
                    if (aux2.destino.nombre == nodo.nombre)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
            }

            return(1);
        }
コード例 #13
0
ファイル: Nodo.cs プロジェクト: azdran/EditorGrafos
 public void llenaarista(Arista ar)
 {
     aristas.Add(ar);
 }
コード例 #14
0
        public override int warner(Graphics g, NodoP pNodo)
        {
            Grafo              copia = new Grafo();
            Grafo              K5, K33;
            NodoP              aux;
            NodoP              elimina;
            Arista             arista;
            bool               band;
            List <List <int> > partita = new List <List <int> >();

            foreach (NodoP np in this)
            {
                aux = new NodoP(np.nombre, np.centro);
                foreach (Arista nr in np.aristas)
                {
                    arista         = new Arista(0);
                    arista.destino = nr.destino;
                    arista.origen  = nr.origen;
                    aux.aristas.Add(arista);
                }
                copia.Add(aux);
            }

            eliminaNodo(copia, pNodo);

            if (copia.Count >= 6)
            {
                if (copia.Count == 6)
                {
                    // verificar si todas tienen el mismo grafo
                    int  grado   = copia[0].aristas.Count;
                    bool bandera = false;
                    foreach (NodoP np in copia)
                    {
                        if (grado == np.aristas.Count)
                        {
                            bandera = true;
                        }
                        else
                        {
                            bandera = false;
                            break;
                        }
                    }
                    if (bandera)
                    {
                        partita = nPartitaG(g, copia);
                        if (partita.Count == 2)
                        {
                            return(2);
                        }
                    }
                }
            }
            else
            {
                // compara con un K5
                K5 = creaKn(5);
                //K33 = creaKmn(3,3);
                band = isomorfico(copia, K5);
                if (band == true)
                {
                    return(1);
                }
                else
                {
                    //se verifica con un K33


                    return(0);
                }
            }
            return(0);
        }
コード例 #15
0
        // ********************************************************************************************************************CAMNINO EULERIANO
        public override List <NodoP> caminoEuleriano()
        {
            string        cad      = "";
            List <NodoP>  cirucuto = new List <NodoP>();
            List <Arista> caminos  = new List <Arista>();
            int           pos      = 0;
            int           nodos    = 0;
            NodoP         aux;

            // pintaGrafoDefault();

            foreach (NodoP np in this)
            {
                np.colorN = new SolidBrush(Color.White);
                foreach (Arista E in np.aristas)
                {
                    E.colorA = new Pen(Color.Black, 1);
                }
            }
            Random srand;

            srand = new Random();

            foreach (NodoP np in this)
            {
                if (np.aristas.Count % 2 != 0 && np.aristas.Count > 0)
                {
                    break;
                }
                pos++;
            }

            aux = this[pos];
            int    j = 0;
            Arista compara;
            int    grado = 0;
            NodoP  anterior;

            foreach (NodoP np in this)
            {
                grado = grado + np.aristas.Count;
            }
            j = 0;
            while (nodos < grado / 2)
            {
                j       = srand.Next(0, aux.aristas.Count);
                compara = caminos.Find(x => x.Equals(aux.aristas[j]));
                if (compara == null)
                {
                    anterior = aux;
                    caminos.Add(aux.aristas[j]);
                    Arista invertida = buscaInvertida(aux, aux.aristas[j].destino);
                    caminos.Add(invertida);
                    cirucuto.Add(aux);
                    aux = aux.aristas[j].destino;
                    nodos++;
                }
            }
            cad += (char)(aux.nombre + 64);
            cirucuto.Add(aux);
            return(cirucuto);
        }
コード例 #16
0
        // ***************************************************************************************************** CIRCUITO EULERIANO
        public override List <NodoP> circuitoEuleriano()
        {
            List <NodoP>  circuito = new List <NodoP>();
            string        cad      = "";
            List <Arista> caminos  = new List <Arista>();
            int           nodos    = 0;
            NodoP         aux;
            NodoP         primero;
            Random        srand;

            srand = new Random();
            coloreate();
            int ariA = 0;

            aux     = this[0];
            primero = aux;
            int    j = 0;
            Arista compara;
            int    grado = 0;

            foreach (NodoP np in this)
            {
                grado = grado + np.aristas.Count;
            }
            j = 0;
            caminos.Clear();
            circuito.Clear();
            while (nodos < grado)// grado / 2)
            {
                j       = srand.Next(0, aux.aristas.Count);
                compara = caminos.Find(x => x.Equals(aux.aristas[j]));
                if (aux.aristas[j].destino == this[0])
                {
                    ariA++;
                }


                if (compara == null)
                {
                    caminos.Add(aux.aristas[j]);
                    Arista invertida = buscaInvertida(aux, aux.aristas[j].destino);
                    caminos.Add(invertida);
                    circuito.Add(aux);
                    aux    = aux.aristas[j].destino;
                    nodos += 2;
                }
                else
                {
                    ariA++;
                }
                if (ariA > 1000)
                {
                    caminos.Clear();
                    circuito.Clear();
                    nodos = 0;
                    ariA  = 0;
                }
            }
            circuito.Add(aux);
            // circuito.Add(primero);

            return(circuito);
        }
コード例 #17
0
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //Agregar Grafo
                if (bandera_agrega_grafo == true)
                {
                    Grafo g = new Grafo(e.X, e.Y, list_grafo.Count);
                    list_grafo.Add(g);
                    bandera_agrega_grafo = false;
                }
            }
            else if (e.Button == MouseButtons.Right) //Agregar arista con click Derecho
            {
                double  dist = 0;
                Vertice aux;

                if (bandera_agrega_arista_segundo == true) //Segundo click para agregar aristas
                {
                    bandera_agrega_arista_segundo = false;

                    if (nuevo_nodo != null)
                    {
                        dist = Math.Sqrt(Math.Pow(e.X - nuevo_nodo.x, 2) + Math.Pow(e.Y - nuevo_nodo.y, 2));
                        if (dist <= (nuevo_nodo.ANCHO / 2))
                        {
                            auxv2 = nuevo_nodo;
                        }
                    }

                    foreach (Grafo item in list_grafo)
                    {
                        aux = item.buscaNodo(e.X, e.Y);
                        if (aux != null)
                        {
                            auxv2 = aux;
                            break;
                        }
                    }

                    Arista nueva_arista = null;
                    if (auxv1 != null)
                    {
                        if (this.auxv1.indice_grafo == this.auxv2.indice_grafo || this.auxv1.indice_grafo == -1 || this.auxv2.indice_grafo == -1)
                        {
                            nueva_arista = new Arista(this.auxv1, this.auxv2, list_grafo);
                            foreach (Grafo item in list_grafo)
                            {
                                if (item.indice_grafo == auxv1.indice_grafo || item.indice_grafo == auxv2.indice_grafo)
                                {
                                    if (-1 == auxv1.indice_grafo)
                                    {
                                        nueva_arista.origen.indice_grafo = auxv2.indice_grafo;
                                        auxv1.indice_vertice             = item.list_vertice.Count();
                                        item.list_vertice.Add(this.auxv1);
                                    }
                                    else if (-1 == auxv2.indice_grafo)
                                    {
                                        nueva_arista.destino.indice_grafo = auxv1.indice_grafo;
                                        auxv2.indice_vertice = item.list_vertice.Count();
                                        item.list_vertice.Add(this.auxv2);
                                    }
                                    nueva_arista.indice_arista = item.list_arista.Count();
                                    nueva_arista.indice_grafo  = item.indice_grafo;
                                    item.list_arista.Add(nueva_arista);
                                    break;
                                }
                            }
                            this.auxv1 = null;
                            this.auxv2 = null;
                        }
                    }
                }
                else //Primer click derecho
                {
                    bandera_agrega_arista_segundo = true;
                    if (nuevo_nodo != null)
                    {
                        dist = Math.Sqrt(Math.Pow(e.X - nuevo_nodo.x, 2) + Math.Pow(e.Y - nuevo_nodo.y, 2));
                        if (dist <= (nuevo_nodo.ANCHO / 2))
                        {
                            auxv1 = nuevo_nodo;
                        }
                    }

                    foreach (Grafo item in list_grafo)
                    {
                        aux = item.buscaNodo(e.X, e.Y);
                        if (aux != null)
                        {
                            auxv1 = aux;
                            break;
                        }
                    }
                }
            }
            pictureBox1.Invalidate();
        }
コード例 #18
0
        public void bosqueAbarcador()
        {
            bosque = new List <List <NodoP> >();
            NodoP aux;

            aux   = grafo[0];
            nodos = new List <NodoP>();
            bosque.Add(new List <NodoP>());

            while (aux != null)
            {
                //   NodoP existeP = stack.nodos.Find(x => x.Equals(aux));
                // if(existeP == null)
                {
                    bosque[0].Add(aux); // Se añade A
                    //   stack.push(aux);
                }
                bool tv2 = todoVisitado(aux);
                if (tv2 == true)
                {
                    //          if (stack.tope == 1)
                    break;
                    //        stack.pop();
                    //        aux = stack.ultimo();
                }
                // Se recorren sus relaciones
                foreach (Arista nr in aux.aristas)
                {
                    // Verificar si la arista ha sido visitada
                    if (visitado == null)
                    {
                        visitado = new List <Arista>();
                    }
                    Arista existeA = visitado.Find(x => x.Equals(nr));

                    if (existeA == null) // La arista aun no ha sido visitada
                    {
                        //verificar si nodo destino existe
                        bool existeNodo = encuentraEnBosque(bosque, nr.destino);

                        if (existeNodo == false)
                        {
                            if (arbol == null)
                            {
                                arbol = new List <Arista>();
                            }
                            arbol.Add(nr);
                            aux = nr.destino;
                        }
                        else // El nodo ya existe en el bosque
                        {
                            // validar si es retroceso o avance
                            int posA = damePosicion(bosque, aux);
                            int posB = damePosicion(bosque, nr.destino);

                            if (posA < posB)
                            {
                                // avance
                                if (avance == null)
                                {
                                    avance = new List <Arista>();
                                }
                                avance.Add(nr);
                            }
                            else if (posA > posB)
                            {
                                // retroceso
                                if (retroceso == null)
                                {
                                    retroceso = new List <Arista>();
                                }
                                retroceso.Add(nr);
                            }
                        }
                        visitado.Add(nr);
                        // Si todas sus relaciones ya fueron visitadas
                        bool tv = todoVisitado(aux);
                        if (tv == true)
                        {
                            //stack.pop();
                            //aux = stack.ultimo();
                        }


                        break;
                    }
                }
            }
        }
コード例 #19
0
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            activa = true;

            //asignaPesos(e.Location);
            if (bandA && band && (opcion == 2 || opcion == 9))
            {
                p2      = e.Location;
                nodoAux = grafo.BuscaNodo(p2);

                if (nodoAux != null)
                {
                    if (opcion == 2)
                    {
                        //  grafo = new GrafoNoDirigido(grafo);
                        nodoR         = new Arista(0);
                        nodoR.destino = nodoAux;
                        nodoR.origen  = nodoP;
                        nodoP.aristas.Add(nodoR);


                        nodoR = new Arista(0);//(rnd.Next(100));

                        nodoR.destino = nodoP;
                        nodoR.origen  = nodoAux;

                        nodoAux.aristas.Add(nodoR);
                    }

                    else if (opcion == 9)
                    {
                        //    grafo = new GrafoDirigido(grafo);
                        grafo.penA.CustomEndCap = arrow;

                        nodoR         = new Arista(0);
                        nodoR.destino = nodoAux;
                        nodoR.origen  = nodoP;

                        nodoP.aristas.Add(nodoR);
                    }

                    bandF = true;
                    bandA = false;
                }
                else
                {
                    bandF = false;
                }
            }

            if (opcion == 4)
            {
                grafo.BorrarNodo(e.Location);
                bandF = false;
            }

            if (opcion == 5)
            {
                grafo.BorrarArista(e.Location);
                quitaNumeric();
                quitaTexaux();//cambios
                quitaPesos();

                bandF = false;
            }
            if (opcion == 41 || intercambiaColor == true) // agregar Peso a Arista
            {
                quitaPesos();
                quitaNumeric();//
                quitaTexaux();
                // asignaPesos(e.Location);
                asignaPesos2(e.Location);
                muestraPeso();
                bandF = false;
            }


            band  = false;
            bandA = false;
            Form1_Paint(this, null);
        }