Ejemplo n.º 1
0
        public void prim()
        {
            Graphics g = Graphics.FromImage(G.getBMP());

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            List <CArista> T  = new List <CArista>();
            CArista        uv = null;

            U.Add(V[0].getVertice());
            while (!UigualaV())
            {
                uv = buscaAristaCostoMin();
                T.Add(uv);
                U.Add(uv.getVDestino());
            }

            T.Sort(comparaAristas);
            string cad = " Conjunto de Aristas\n\n T : {";

            foreach (CArista a in T)
            {
                a.dibujateAACM(g, G.getBMP(), tp);
                cad += " (" + a.getVOrigen().getId().ToString() + "," + a.getVDestino().getId().ToString() + ") ";
            }
            cad += "}.    ";

            MessageBox.Show(cad, "Árbol Abarcador de Costo Mínimo (Algoritmo de PRIM)", MessageBoxButtons.OK, MessageBoxIcon.Information);

            g.Clear(Color.White);
            G.dibujate(tp, G.getBMP());
        }
Ejemplo n.º 2
0
        public void aplicaArbolAbarcador(int tipo_grafo, bool ramp)
        {
            Graphics g = Graphics.FromImage(G.getBMP());

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            clasificaArcos(ramp);

            foreach (CArista a in arcos_retroceso)
            {
                a.dibujateRP(g, G.getBMP(), tp, 1, G.getTipo());
            }

            foreach (CArista a in arcos_avance)
            {
                a.dibujateRP(g, G.getBMP(), tp, 2, G.getTipo());
            }

            foreach (CArista a in arcos_cruzados)
            {
                a.dibujateRP(g, G.getBMP(), tp, 3, G.getTipo());
            }

            string cad  = "\n\n Arcos de árbol (Azul)\n Arcos de retroceso (Rojo)\n Arcos de Avance (Celeste)\n Arcos Cruzados (Verde)";
            string cad2 = "\n\n Arcos de árbol (Azul)\n Arcos de Retroceso (Rojo)\n";
            string cad3 = "\n\n Arcos de árbol (Azul)\n Arcos de Cruzados (Verde)\n";

            if (tipo_grafo == DIRIGIDO)
            {
                if (arcos_retroceso.Count == 0)
                {
                    MessageBox.Show(" El Grafo " + G.getId().ToString() + " es un GDA.                   " + cad, "Recorrido en profundidad", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(" El Grafo " + G.getId().ToString() + " NO es un GDA ya que tiene arcos de retroceso (Color Rojo).  " + cad, "Recorrido en profundidad", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                if (!ramp)
                {
                    MessageBox.Show(" Resultado para el Grafo " + G.getId().ToString() + cad2, "Recorrido en profundidad (Grafo NO Dirigido)", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(" Resultado para el Grafo " + G.getId().ToString() + ".                   " + cad3, "Recorrido en amplitud", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            g.Clear(Color.White);
            G.dibujate(tp, G.getBMP());
        }
Ejemplo n.º 3
0
 private void coloreadoToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (grafos != null && grafos.Count != 0)
     {
         if (grafo_activo != null && grafo_activo.getNumeroVertices() != 0)
         {
             CColoreado c = new CColoreado(grafo_activo);
             c.coloreoDeGrafo4Colores((TabPage)Pestanas.Controls[Pestanas.SelectedIndex]);
             MessageBox.Show(" Número Cromático : " + c.getNC().ToString() + " colores.  ", "Coloreado", MessageBoxButtons.OK, MessageBoxIcon.Information);
             c.regresaAEstadoOriginal();
             grafo_activo.dibujate((TabPage)Pestanas.Controls[Pestanas.SelectedIndex], grafo_activo.getBMP());
         }
     }
 }
Ejemplo n.º 4
0
        public void kruskal()
        {
            Graphics g = Graphics.FromImage(G.getBMP());

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            int             n  = G.getNumeroVertices();
            CArista         uv = null;
            List <CVertice> cv = null;
            List <CVertice> cu = null;

            foreach (CNodoVertice cnv in V)
            {
                List <CVertice> C = new List <CVertice>();
                C.Add(cnv.getVertice());
                componentes.Add(C);
            }

            while (T.Count <= (n - 1) && Q.Count != 0)
            {
                uv = Q[0];
                Q.RemoveAt(0);
                cv = componenteQueContiene(uv.getVDestino());
                cu = componenteQueContiene(uv.getVOrigen());
                if (!cvIgualcu(cv, cu))
                {
                    T.Add(uv);
                    foreach (CVertice v in cu)
                    {
                        cv.Add(v);
                    }
                    cu.Clear();
                }
            }

            T.Sort(comparaArista);
            string cad = " Conjunto de Aristas\n\n T : {";

            foreach (CArista a in T)
            {
                a.dibujateAACM(g, G.getBMP(), tp);
                cad += " (" + a.getVOrigen().getId().ToString() + "," + a.getVDestino().getId().ToString() + ") ";
            }
            cad += "}.    ";

            MessageBox.Show(cad, "Árbol Abarcador de Costo Mínimo (Algoritmo de KRUSKAL)", MessageBoxButtons.OK, MessageBoxIcon.Information);

            g.Clear(Color.White);
            G.dibujate(tp, G.getBMP());
        }
Ejemplo n.º 5
0
        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());
            }
        }