public int getYde(CNodoVertice cnv)
        {
            List <int> yes  = new List <int>();
            int        ymin = -1;

            foreach (CArista a in arcos_arbol)
            {
                CVertice or = a.getVOrigen(), de = a.getVDestino();
                int      num_or = or.getNumero(), num_de = de.getNumero();
                if (or.getId() == cnv.getVertice().getId() && num_or < num_de)
                {
                    if (de.getBajo() != 0)
                    {
                        yes.Add(de.getBajo());
                    }
                }
                else if (de.getId() == cnv.getVertice().getId() && num_de < num_or)
                {
                    if (or.getBajo() != 0)
                    {
                        yes.Add(or.getBajo());
                    }
                }

                if (yes.Count != 0)
                {
                    yes.Sort();
                    ymin = yes[0];
                }
            }

            return(ymin);
        }
        public CGrafo construyeK33()
        {
            CGrafo k33 = new CGrafo(1, 0);

            for (int i = 0; i < 6; i++)
            {
                CVertice v = new CVertice(i + 1, 0, 0, Color.White, Color.Black);
                v.setGrado(3);
                CNodoVertice cnv = new CNodoVertice(v);
                k33.getListaAdyacencia().Add(cnv);
            }

            for (int i = 0; i < 3; i++)
            {
                for (int j = 3; j < 6; j++)
                {
                    k33.getListaAdyacencia()[i].getRelaciones().Add(k33.getListaAdyacencia()[j]);
                    k33.getListaAdyacencia()[i].getVertice().getVecinos().Add(k33.getListaAdyacencia()[j].getVertice());
                    k33.getListaAdyacencia()[j].getRelaciones().Add(k33.getListaAdyacencia()[i]);
                    k33.getListaAdyacencia()[j].getVertice().getVecinos().Add(k33.getListaAdyacencia()[i].getVertice());
                    CArista ar = new CArista(k33.getListaAdyacencia()[i].getVertice(), k33.getListaAdyacencia()[j].getVertice(), new Point(0, 0), new Point(0, 0), 0);
                    k33.getListaAristas().Add(ar);
                }
            }

            k33.setNumeroAristas(9);
            k33.setNumeroVertices(6);

            return k33;
        }
Exemple #3
0
        public CGrafo construyeK5()
        {
            CGrafo k5 = new CGrafo(1, 0);

            for (int i = 0; i < 5; i++)
            {
                CVertice v = new CVertice(i + 1, 0, 0, Color.White, Color.Black);
                v.setGrado(4);
                CNodoVertice cnv = new CNodoVertice(v);
                k5.getListaAdyacencia().Add(cnv);
            }

            foreach (CNodoVertice nv in k5.getListaAdyacencia())
            {
                foreach (CNodoVertice nv2 in k5.getListaAdyacencia())
                {
                    if (nv.getVertice().getId() != nv2.getVertice().getId())
                    {
                        nv.getRelaciones().Add(nv2);
                        nv.getVertice().getVecinos().Add(nv2.getVertice());
                        if (!k5.aristaRepetida(nv.getVertice(), nv2.getVertice()))
                        {
                            CArista ar = new CArista(nv.getVertice(), nv2.getVertice(), new Point(0, 0), new Point(0, 0), 0);
                            k5.getListaAristas().Add(ar);
                        }
                    }
                }
            }

            k5.setNumeroAristas(10);
            k5.setNumeroVertices(5);

            return(k5);
        }
Exemple #4
0
        public CGrafo construyeK33()
        {
            CGrafo k33 = new CGrafo(1, 0);

            for (int i = 0; i < 6; i++)
            {
                CVertice v = new CVertice(i + 1, 0, 0, Color.White, Color.Black);
                v.setGrado(3);
                CNodoVertice cnv = new CNodoVertice(v);
                k33.getListaAdyacencia().Add(cnv);
            }

            for (int i = 0; i < 3; i++)
            {
                for (int j = 3; j < 6; j++)
                {
                    k33.getListaAdyacencia()[i].getRelaciones().Add(k33.getListaAdyacencia()[j]);
                    k33.getListaAdyacencia()[i].getVertice().getVecinos().Add(k33.getListaAdyacencia()[j].getVertice());
                    k33.getListaAdyacencia()[j].getRelaciones().Add(k33.getListaAdyacencia()[i]);
                    k33.getListaAdyacencia()[j].getVertice().getVecinos().Add(k33.getListaAdyacencia()[i].getVertice());
                    CArista ar = new CArista(k33.getListaAdyacencia()[i].getVertice(), k33.getListaAdyacencia()[j].getVertice(), new Point(0, 0), new Point(0, 0), 0);
                    k33.getListaAristas().Add(ar);
                }
            }

            k33.setNumeroAristas(9);
            k33.setNumeroVertices(6);

            return(k33);
        }
        public CGrafo construyeK5()
        {
            CGrafo k5 = new CGrafo(1, 0);

            for (int i = 0; i < 5; i++)
            {
                CVertice v = new CVertice(i+1,0,0,Color.White,Color.Black);
                v.setGrado(4);
                CNodoVertice cnv = new CNodoVertice(v);
                k5.getListaAdyacencia().Add(cnv);
            }

            foreach (CNodoVertice nv in k5.getListaAdyacencia())
            {
                foreach (CNodoVertice nv2 in k5.getListaAdyacencia())
                {
                    if (nv.getVertice().getId() != nv2.getVertice().getId())
                    {
                        nv.getRelaciones().Add(nv2);
                        nv.getVertice().getVecinos().Add(nv2.getVertice());
                        if (!k5.aristaRepetida(nv.getVertice(), nv2.getVertice()))
                        {
                            CArista ar = new CArista(nv.getVertice(), nv2.getVertice(),new Point(0,0),new Point(0,0),0);
                            k5.getListaAristas().Add(ar);
                        }
                    }
                }
            }

            k5.setNumeroAristas(10);
            k5.setNumeroVertices(5);

            return k5;
        }
        } //Con teorema de los 4 colores

        public void despintarNodosAdyacentesA(CVertice vertice)
        {
            foreach (CVertice v in vertice.getVecinos())
            {
                v.setRelleno(Color.LightGoldenrodYellow.ToArgb());
                v.setPintado(false);
            }
        }
Exemple #7
0
 //Constructor
 public CArista(CVertice or,CVertice de, Point o, Point d,int tipo_ar)
 {
     po = o;
     pd = d;
     origen = or;
     destino = de;
     tipo = tipo_ar;
     peso = 0;
 }
 public bool esXDescendienteDeY(CVertice X, CVertice Y)
 {
     if (Y.getNumero() <= X.getNumero() &&
         X.getNumero() <= (Y.getNumero() + descendientes[G.getListaAdyacencia().IndexOf(G.buscaNodoVertice(Y))]))
     {
         return(true);
     }
     return(false);
 }
Exemple #9
0
 //Constructor
 public CArista(CVertice or, CVertice de, Point o, Point d, int tipo_ar)
 {
     po      = o;
     pd      = d;
     origen  = or;
     destino = de;
     tipo    = tipo_ar;
     peso    = 0;
 }
        public void pintaNodo4Colores(CVertice vertice, int color_asignado)
        {
            if (num_cromatico < (color_asignado + 1))
            {
                num_cromatico++;
            }

            vertice.setRelleno(colores[color_asignado].ToArgb());
            vertice.setPintado(true);
        } //Con teorema de los 4 colores
        public bool esElUltimoEnPintar(CVertice v)
        {
            foreach (CNodoVertice cnv in G.getListaAdyacencia())
            {
                if (cnv.getVertice().getId() != v.getId() && !v.estaPintado())
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #12
0
        public List <CVertice> componenteQueContiene(CVertice v)
        {
            List <CVertice> cv = null;

            foreach (List <CVertice> comp in componentes)
            {
                if (comp.Contains(v))
                {
                    cv = comp;
                    break;
                }
            }

            return(cv);
        }
        public bool hayVecinoConColor(CVertice vertice, int color)
        {
            foreach (CVertice vecino in vertice.getVecinos())
            {
                if (vecino.estaPintado())
                {
                    if (vecino.getArgbRelleno() == colores[color].ToArgb())
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #14
0
        public List<CVertice> componenteQueContiene(CVertice v)
        {
            List<CVertice> cv = null;

            foreach (List<CVertice> comp in componentes)
            {
                if (comp.Contains(v))
                {
                    cv = comp;
                    break;
                }
            }

            return cv;
        }
        public CVertice getNodoDeMayorGradoDeErrorSinPintar()
        {
            CVertice encontrado = null;
            int      mayorGE    = 0;

            foreach (CNodoVertice cnv in G.getListaAdyacencia())
            {
                if (!cnv.getVertice().estaPintado() && cnv.getVertice().getGradoError() >= mayorGE)
                {
                    mayorGE    = cnv.getVertice().getGrado();
                    encontrado = cnv.getVertice();
                }
            }
            return(encontrado);
        }
        public bool hayColorDisponibeNColores(CVertice vertice, ref int color)
        {
            bool band = false;

            for (int colori = AZUL; colori < NEGRO; colori++)
            {
                if (!hayVecinoConColor(vertice, colori))
                {
                    color = colori;
                    band  = true;
                    break;
                }
            }

            return(band);
        }
 public bool tieneHijosConBajoMayorOIgualAlNumDe(CNodoVertice cnv)
 {
     foreach (CArista a in arcos_arbol)
     {
         CVertice or = a.getVOrigen(), de = a.getVDestino();
         int      num_or = or.getNumero(), num_de = de.getNumero();
         if (or.getId() == cnv.getVertice().getId() && num_or < num_de && de.getBajo() >= cnv.getVertice().getNumero())
         {
             return(true);
         }
         else if (de.getId() == cnv.getVertice().getId() && num_de < num_or && or.getBajo() >= cnv.getVertice().getNumero())
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #18
0
 private void obtenerCentroToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (grafos != null && grafo_activo != null && grafo_activo.getTipo() == DIRIGIDO && grafo_activo.getNumeroAristas() > 0)
     {
         if (!grafo_activo.tienePeso())
         {
             DAddPeso dap = new DAddPeso(grafo_activo.getListaAristas());
             grafo_activo.showHideIdAristas(true, (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
             if (dap.ShowDialog() == DialogResult.OK)
             {
                 grafo_activo.setPesos(dap.getPesos());
                 grafo_activo.showHideIdAristas(false, (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
                 grafo_activo.showHidePesos(true, (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
                 CFloyd cf = new CFloyd(grafo_activo);
                 cf.Floyd();
                 CVertice centro = cf.dameCentro().getVertice();
                 centro.setRelleno(Color.SpringGreen.ToArgb());
                 centro.dibujate(Graphics.FromImage(grafo_activo.getBMP()), grafo_activo.getBMP(), (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
                 MessageBox.Show(" Vértice Central : " + centro.getId().ToString() + ".     ", "Centro del Grafo " + grafo_activo.getId().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                 centro.borrate(Graphics.FromImage(grafo_activo.getBMP()), grafo_activo.getBMP(), (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
                 centro.setRelleno(Color.LightGoldenrodYellow.ToArgb());
                 centro.dibujate(Graphics.FromImage(grafo_activo.getBMP()), grafo_activo.getBMP(), (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
                 grafo_activo.showHidePesos(false, (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
             }
             else
             {
                 grafo_activo.showHideIdAristas(false, (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
             }
         }
         else
         {
             grafo_activo.showHidePesos(true, (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
             CFloyd cf = new CFloyd(grafo_activo);
             cf.Floyd();
             CVertice centro = cf.dameCentro().getVertice();
             centro.setRelleno(Color.SpringGreen.ToArgb());
             centro.dibujate(Graphics.FromImage(grafo_activo.getBMP()), grafo_activo.getBMP(), (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
             MessageBox.Show(" Vértice Central : " + centro.getId().ToString() + ".     ", "Centro del Grafo " + grafo_activo.getId().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
             centro.borrate(Graphics.FromImage(grafo_activo.getBMP()), grafo_activo.getBMP(), (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
             centro.setRelleno(Color.LightGoldenrodYellow.ToArgb());
             centro.dibujate(Graphics.FromImage(grafo_activo.getBMP()), grafo_activo.getBMP(), (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
             grafo_activo.showHidePesos(false, (TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
         }
     }
 }
 public void enlistaArcosArbol(CVertice origen, CVertice destino)
 {
     foreach (CArista a in G.getListaAristas())
     {
         if (G.getTipo() == DIRIGIDO)
         {
             if (a.getVOrigen().getId() == origen.getId() && a.getVDestino().getId() == destino.getId())
             {
                 arcos_arbol.Add(a);
             }
         }
         else
         {
             if ((a.getVOrigen().getId() == origen.getId() && a.getVDestino().getId() == destino.getId()) ||
                 a.getVOrigen().getId() == destino.getId() && a.getVDestino().getId() == origen.getId())
             {
                 arcos_arbol.Add(a);
             }
         }
     }
 }
        public void pintaNodoNColores(CVertice vertice)
        {
            int color_asignado = AZUL;

            foreach (CVertice vecino in vertice.getVecinos())
            {
                if (vecino.estaPintado())
                {
                    if (vecino.getArgbRelleno() == colores[color_asignado].ToArgb())
                    {
                        if (color_asignado != NEGRO)
                        {
                            color_asignado++;
                        }
                    }
                }
            }

            vertice.setRelleno(colores[color_asignado].ToArgb());
            vertice.setPintado(true);
        } //General numero cromatico arbitrario
        public bool laRaizTiene2OMasHijos(CNodoVertice cnv_ini)
        {
            int num_hijos = 0;

            foreach (CArista a in arcos_arbol)
            {
                CVertice or = a.getVOrigen(), de = a.getVDestino();
                int      num_or = or.getNumero(), num_de = de.getNumero();
                if ((or.getId() == cnv_ini.getVertice().getId() && num_or < num_de) ||
                    (de.getId() == cnv_ini.getVertice().getId() && num_de < num_or))
                {
                    num_hijos++;
                }
            }

            if (num_hijos >= 2)
            {
                return(true);
            }

            return(false);
        }
 public void coloreoDeGrafoNColores(TabPage tp)
 {
     if (hayNodoSinPintar() && !band2)
     {
         CVertice vert_mge = getNodoDeMayorGradoDeErrorSinPintar();
         if (vert_mge != null)
         {
             int color = -1;
             if (hayColorDisponibeNColores(vert_mge, ref color) && color != -1)
             {
                 pintaNodo4Colores(vert_mge, color);
                 coloreoDeGrafoNColores(tp);
             }
             else
             {
                 band2 = true;
                 MessageBox.Show("\n El Grafo " + G.getId().ToString() + " ha sobrepasado el limite de colores disponible (10)...",
                                 "Número cromatico arbitrario!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
         }
     }
 }
 public void clasificaArcos(bool ramp)
 {
     foreach (CArista a in G.getListaAristas())
     {
         if (G.getTipo() == DIRIGIDO)
         {
             if (!arcos_arbol.Contains(a)) //Si no es arco de arbol
             {
                 CVertice u = a.getVOrigen(), v = a.getVDestino();
                 if (u.getNumero() >= v.getNumero() && esXDescendienteDeY(u, v))          //Si es arco de retroceso
                 {
                     arcos_retroceso.Add(a);
                 }
                 else if ((u.getNumero() <= v.getNumero() && esXDescendienteDeY(v, u)))    //Si es arco de avance
                 {
                     arcos_avance.Add(a);
                 }
                 else
                 {
                     arcos_cruzados.Add(a);                                              //Entonces es arco cruzado
                 }
             }
         }
         else
         {
             if (!arcos_arbol.Contains(a))
             {
                 if (ramp)
                 {
                     arcos_cruzados.Add(a);
                 }
                 else
                 {
                     arcos_retroceso.Add(a);
                 }
             }
         }
     }
 }
        public void coloreoDeGrafo4Colores(TabPage tp)
        {
            if (hayNodoSinPintar() && !band)
            {
                CVertice vert_mge = getNodoDeMayorGradoDeErrorSinPintar();
                if (vert_mge != null)
                {
                    int color = -1;
                    if (hayColorDisponibe(vert_mge, ref color) && color != -1)
                    {
                        pintaNodo4Colores(vert_mge, color);
                    }
                    else
                    {
                        if (vert_mge.getVecinos().Count != G.getNumeroVertices() - 1)
                        {
                            vert_mge.aumentaGE();
                            despintarNodosAdyacentesA(vert_mge);
                        }
                        else
                        {
                            band = true;
                        }
                    }

                    coloreoDeGrafo4Colores(tp);
                }
            }
            else
            {
                if (hayNodoSinPintar())
                {
                    coloreoDeGrafoNColores(tp);
                }

                G.dibujate(tp, G.getBMP());
            }
        }
        public bool hayColorDisponibeNColores(CVertice vertice, ref int color)
        {
            bool band = false;
            for (int colori = AZUL; colori < NEGRO; colori++)
            {
                if (!hayVecinoConColor(vertice, colori))
                {
                    color = colori;
                    band = true;
                    break;
                }
            }

            return band;
        }
Exemple #26
0
 public void setVDestino(CVertice de)
 {
     destino = de;
 }
        public void pintaNodo4Colores(CVertice vertice,int color_asignado)
        {
            if (num_cromatico < (color_asignado + 1))
                num_cromatico++;

            vertice.setRelleno(colores[color_asignado].ToArgb());
            vertice.setPintado(true);
        }
        public bool hayVecinoConColor(CVertice vertice, int color)
        {
            foreach (CVertice vecino in vertice.getVecinos())
            {
                if (vecino.estaPintado())
                {
                    if (vecino.getArgbRelleno() == colores[color].ToArgb())
                        return true;
                }
            }

            return false;
        }
Exemple #29
0
 public void setVDestino(CVertice de)
 {
     destino = de;
 }
Exemple #30
0
 public void setVOrigen(CVertice or)
 {
     origen = or;
 }
Exemple #31
0
 //Constructor
 public CNodoVertice(CVertice vert)
 {
     vertice    = vert;
     relaciones = new List <CNodoVertice>();
 }
        public bool esElUltimoEnPintar(CVertice v)
        {
            foreach (CNodoVertice cnv in G.getListaAdyacencia())
            {
                if (cnv.getVertice().getId() != v.getId() && !v.estaPintado())
                    return false;
            }

            return true;
        }
        public void pintaNodoNColores(CVertice vertice)
        {
            int color_asignado = AZUL;

            foreach (CVertice vecino in vertice.getVecinos())
            {
                if (vecino.estaPintado())
                {
                    if (vecino.getArgbRelleno() == colores[color_asignado].ToArgb())
                    {
                        if (color_asignado != NEGRO)
                        {
                            color_asignado++;
                        }
                    }
                }
            }

            vertice.setRelleno(colores[color_asignado].ToArgb());
            vertice.setPintado(true);
        }
 public bool esXDescendienteDeY(CVertice X, CVertice Y)
 {
     if( Y.getNumero() <= X.getNumero()
         && X.getNumero() <= (Y.getNumero() + descendientes[G.getListaAdyacencia().IndexOf(G.buscaNodoVertice(Y))]))
     {
         return true;
     }
     return false;
 }
 public void enlistaArcosArbol(CVertice origen, CVertice destino)
 {
     foreach (CArista a in G.getListaAristas())
     {
         if (G.getTipo() == DIRIGIDO)
         {
             if (a.getVOrigen().getId() == origen.getId() && a.getVDestino().getId() == destino.getId())
                 arcos_arbol.Add(a);
         }
         else
         {
             if ((a.getVOrigen().getId() == origen.getId() && a.getVDestino().getId() == destino.getId()) ||
                 a.getVOrigen().getId() == destino.getId() && a.getVDestino().getId() == origen.getId())
             {
                 arcos_arbol.Add(a);
             }
         }
     }
 }
 public void despintarNodosAdyacentesA(CVertice vertice)
 {
     foreach(CVertice v in vertice.getVecinos())
     {
         v.setRelleno(Color.LightGoldenrodYellow.ToArgb());
         v.setPintado(false);
     }
 }
Exemple #37
0
 public void setVOrigen(CVertice or)
 {
     origen = or;
 }