Пример #1
0
        public Grafo creaKmn(int v, int e)
        {
            Grafo        nuevo = new Grafo();
            NodoP        aux;
            List <NodoP> dominio = new List <NodoP>();
            List <NodoP> rango   = new List <NodoP>();
            int          j       = v;

            for (int i = 0; i < v; i++)
            {
                aux = new NodoP(i, new Point());
                dominio.Add(aux);
            }
            for (int i = 0; i < e; i++)
            {
                aux = new NodoP(j, new Point());
                rango.Add(aux);
                j++;
            }
            // AGREGAR REALCIONES
            foreach (NodoP np in dominio)
            {
                nuevo.Add(np);
            }
            foreach (NodoP np in rango)
            {
                nuevo.Add(np);
            }



            return(nuevo);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            p1 = e.Location;
            if (activa)
            {
                nodoW  = grafo.BuscaNodo(p1);
                activa = false;
            }

            switch (opcion)
            {
            case 1:
                if (/*grafo.Count == 1 &&*/ grafo.numN == 1)
                {
                    grafo.numN++;
                }
                if (grafo.Count > 0)
                {
                    nodoP = new NodoP(grafo.Count - 1, p1);
                }
                else
                {
                    nodoP = new NodoP(grafo.numN - 1, p1);
                }
                grafo.Add(nodoP);
                grafo.nomb   = nodoP.nombre;
                nodoP.nombre = grafo.Count;
                band         = false;
                bandF        = true;
                if (grafo.numN == 28 && grafo.Count == 28)
                {
                    bandI        = true;
                    grafo.edoNom = true;
                }
                else
                {
                    bandI = false;
                }
                Form1_Paint(this, null);
                break;

            case 2:
            case 9:
                nodoP = grafo.BuscaNodo(p1);
                if (nodoP != null)
                {
                    band  = true;
                    bandA = true;
                }
                else
                {
                    band = false;
                }
                break;

            case 3:
                nodoP = grafo.BuscaNodo(p1);
                if (nodoP != null)
                {
                    bandA = true;
                }
                else
                {
                    band = false;
                }
                break;

            case 8:
                p1 = e.Location;


                break;
            }
        }