Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
 private void conteoDeCaminosToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (grafos != null && grafo_activo != null)
     {
         if (grafo_activo.getNumeroVertices() >= 2)
         {
             DConteo dc = new DConteo(grafo_activo.getNumeroVertices());
             if (dc.ShowDialog() == DialogResult.OK)
             {
                 CNodoVertice cnv1 = grafo_activo.getListaAdyacencia()[(dc.na) - 1], cnv2 = grafo_activo.getListaAdyacencia()[(dc.nb) - 1];
                 int          num_cam = grafo_activo.calculaCaminosREntre(cnv1, cnv2, dc.r), ncam = dc.r;
                 if (cnv1.getVertice().getId() != cnv2.getVertice().getId())
                 {
                     MessageBox.Show(" Existen " + num_cam.ToString() + " caminos de longitud " + ncam.ToString() + " entre el vértice " + cnv1.getVertice().getId().ToString() + " al vértice " + cnv2.getVertice().getId().ToString() + "  ", "Conteo de caminos", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
                 else
                 {
                     MessageBox.Show(" Existen " + num_cam.ToString() + " circuitos de longitud " + ncam.ToString() + " para el vértice " + cnv1.getVertice().getId().ToString() + "  ", "Conteo de circuitos", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
         }
         else
         {
             MessageBox.Show(" Deben existir por lo menos 2 vertices en el grafo! ", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Ejemplo n.º 5
0
 public bool hayNodoSinPintar()
 {
     foreach (CNodoVertice cnv in G.getListaAdyacencia())
     {
         if (cnv.getVertice().estaPintado() == false)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 6
0
        //Principal
        public bool sonIsomorficos()
        {
            bool band = false;

            if (!G.getListaAdyacencia().Exists(hayVerticeGradoCero) &&
                !H.getListaAdyacencia().Exists(hayVerticeGradoCero) &&
                mismosNVyNA(G, H) && mismasRelacionesGrafo() &&
                algoritmoMatrices())
            {
                band = true;
            }
            return(band);
        }
Ejemplo n.º 7
0
 public CDijkstra(CGrafo grafo)
 {
     G = grafo;
     n = grafo.getNumeroVertices();
     V = grafo.getListaAdyacencia();
     C = construyeC();
 }
Ejemplo n.º 8
0
 public CDijkstra(CGrafo grafo)
 {
     G = grafo;
     n = grafo.getNumeroVertices();
     V = grafo.getListaAdyacencia();
     C = construyeC();
 }
Ejemplo n.º 9
0
 public CPrim(CGrafo grafo,TabPage t)
 {
     V = grafo.getListaAdyacencia();
     E = grafo.getListaAristas();
     U = new List<CVertice>();
     G = grafo;
     tp = t;
 }
Ejemplo n.º 10
0
 public CPrim(CGrafo grafo, TabPage t)
 {
     V  = grafo.getListaAdyacencia();
     E  = grafo.getListaAristas();
     U  = new List <CVertice>();
     G  = grafo;
     tp = t;
 }
Ejemplo n.º 11
0
 public CFloyd(CGrafo grafo)
 {
     G = grafo;
     n = grafo.getNumeroVertices();
     V = grafo.getListaAdyacencia();
     C = construyeC();
     P = new int[n, n];
     D = new int[n, n];
 }
Ejemplo n.º 12
0
 public CFloyd(CGrafo grafo)
 {
     G = grafo;
     n = grafo.getNumeroVertices();
     V = grafo.getListaAdyacencia();
     C = construyeC();
     P = new int[n, n];
     D = new int[n, n];
 }
Ejemplo n.º 13
0
 public void getGrados(CGrafo gx) //Obtiene los grados (sin repetirse) que tiene el grafo
 {
     foreach (CNodoVertice cnv in gx.getListaAdyacencia())
     {
         if (!existeItem(grados, cnv.getVertice().getVecinos().Count))
         {
             grados.Add(cnv.getVertice().getVecinos().Count);
         }
     }
     grados.Sort();
 }
Ejemplo n.º 14
0
 public CRecorridoP(CGrafo grafo, TabPage tpx)
 {
     arcos_arbol     = new List <CArista>();
     arcos_avance    = new List <CArista>();
     arcos_retroceso = new List <CArista>();
     arcos_cruzados  = new List <CArista>();
     G             = grafo;
     num           = 0;
     descendientes = new int[G.getListaAdyacencia().Count];
     tp            = tpx;
     GR            = new List <CNodoVertice>();
     ids_cf        = new List <List <int> >();
 }
Ejemplo n.º 15
0
 public CRecorridoP(CGrafo grafo,TabPage tpx)
 {
     arcos_arbol = new List<CArista>();
     arcos_avance = new List<CArista>();
     arcos_retroceso = new List<CArista>();
     arcos_cruzados = new List<CArista>();
     G = grafo;
     num = 0;
     descendientes = new int[G.getListaAdyacencia().Count];
     tp = tpx;
     GR = new List<CNodoVertice>();
     ids_cf = new List<List<int>>();
 }
Ejemplo n.º 16
0
        public CKruskal(CGrafo grafo,TabPage tpx)
        {
            G = grafo;
            V = G.getListaAdyacencia();
            E = G.getListaAristas();
            Q = new List<CArista>();
            T = new List<CArista>();
            tp = tpx;
            componentes = new List<List<CVertice>>();

            foreach (CArista a in E)
                Q.Add(a);

            Q.Sort(comparaArista);
        }
Ejemplo n.º 17
0
        public CKruskal(CGrafo grafo, TabPage tpx)
        {
            G           = grafo;
            V           = G.getListaAdyacencia();
            E           = G.getListaAristas();
            Q           = new List <CArista>();
            T           = new List <CArista>();
            tp          = tpx;
            componentes = new List <List <CVertice> >();

            foreach (CArista a in E)
            {
                Q.Add(a);
            }

            Q.Sort(comparaArista);
        }
Ejemplo n.º 18
0
 //Constructor
 public CColoreado(CGrafo grafo)
 {
     colores = new Color[10];
     colores[AZUL]= Color.DeepSkyBlue;
     colores[ROJO]= Color.Red;
     colores[VERDE]= Color.Lime;
     colores[AMARILLO]= Color.Yellow;
     colores[NARANJA]= Color.Orange;
     colores[CAFE]= Color.Peru;
     colores[MORADO]= Color.DarkOrchid;
     colores[ROSA]= Color.HotPink;
     colores[AQUA]= Color.Aqua;
     colores[NEGRO]= Color.Black;
     band = band2=false;
     G = grafo;
     foreach (CNodoVertice cnv in G.getListaAdyacencia())
         cnv.getVertice().setGradoError(cnv.getVertice().getGrado());
 }
Ejemplo n.º 19
0
 //Constructor
 public CColoreado(CGrafo grafo)
 {
     colores           = new Color[10];
     colores[AZUL]     = Color.DeepSkyBlue;
     colores[ROJO]     = Color.Red;
     colores[VERDE]    = Color.Lime;
     colores[AMARILLO] = Color.Yellow;
     colores[NARANJA]  = Color.Orange;
     colores[CAFE]     = Color.Peru;
     colores[MORADO]   = Color.DarkOrchid;
     colores[ROSA]     = Color.HotPink;
     colores[AQUA]     = Color.Aqua;
     colores[NEGRO]    = Color.Black;
     band = band2 = false;
     G    = grafo;
     foreach (CNodoVertice cnv in G.getListaAdyacencia())
     {
         cnv.getVertice().setGradoError(cnv.getVertice().getGrado());
     }
 }
Ejemplo n.º 20
0
 //Obtiene los grados (sin repetirse) que tiene el grafo
 public void getGrados(CGrafo gx)
 {
     foreach (CNodoVertice cnv in gx.getListaAdyacencia())
     {
         if (!existeItem(grados, cnv.getVertice().getVecinos().Count))
         {
             grados.Add(cnv.getVertice().getVecinos().Count);
         }
     }
     grados.Sort();
 }
Ejemplo n.º 21
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;
        }
Ejemplo n.º 22
0
        public void RecorridoEnProfundidad(CNodoVertice cnvid)
        {
            if (cnvid.getVertice().getVisitado() != true)
            {
                int nd = 0;
                RP_R(cnvid, ref nd);
                descendientes[G.getListaAdyacencia().IndexOf(cnvid)] = nd;
            }

            foreach (CNodoVertice cnv in G.getListaAdyacencia())
            {
                if (cnv.getVertice().getId() != cnvid.getVertice().getId())
                {
                    if (cnv.getVertice().getVisitado() != true)
                    {
                        int nd = 0;
                        RP_R(cnv, ref nd);
                        descendientes[G.getListaAdyacencia().IndexOf(cnv)] = nd;
                    }
                }
            }
        }