示例#1
0
 private void algoritmoFuerzaBrutaToolStripMenuItem_Click(object sender, EventArgs e)
 {
     grafo2 = VentanaIsomorfismo.grafo;
     if (grafo2.Nodos.Count > 0)
     {
         if ((grafo.ObtenNumeroRelaciones() == grafo2.ObtenNumeroRelaciones()) && (grafo.Nodos.Count == grafo2.Nodos.Count))
         {
             bool Respuesta = Algoritmos.FuerzaBruta(grafo.GeneraMatrizAdyacencia(), grafo2.GeneraMatrizAdyacencia(), grafo.Nodos.Count);
             if (Respuesta)
             {
                 MessageBox.Show("Los grafos son isomorficos entre si según el algoritmo de fuerza bruta");
             }
             else
             {
                 MessageBox.Show("Los grafos no son isomorficos entre si según el algoritmo de fuerza bruta");
             }
         }
         else
         {
             MessageBox.Show("El número de relaciones o el número de nodos de los 2 grafos no son iguales");
         }
     }
     else
     {
         MessageBox.Show("El grafo no ha sido cargado");
     }
 }
示例#2
0
        public void EulerAlgoritmoRec(List <Nodo> ListaAux1, List <Nodo> ListaAux2, Grafo grafo, List <List <int> > camino)
        {
            Nodo    n         = ListaAux1[ListaAux1.Count - 1];
            Boolean Utilizado = false;

            if (ListaAux2.Count < grafo.ObtenNumeroRelaciones() / 2)
            {
                for (int i = 0; i < n.ObtenGradoNodo(); i++)
                {
                    Nodo aux = BuscaNodoInt(grafo.Nodos, n.ObtenRelacion(i).Destino);

                    for (int j = 0; j < ListaAux2.Count; j++)
                    {
                        if ((ListaAux1[j].Equals(aux) && ListaAux2[j].Equals(n)) || (ListaAux1[j].Equals(n) && ListaAux2[j].Equals(aux)))
                        {
                            Utilizado = true;
                            break;
                        }
                    }

                    if (!Utilizado)
                    {
                        ListaAux2.Add(aux);
                        ListaAux1.Add(aux);
                        EulerAlgoritmoRec(ListaAux1, ListaAux2, grafo, camino);
                        ListaAux1.RemoveAt(ListaAux1.Count - 1);
                        ListaAux2.RemoveAt(ListaAux2.Count - 1);
                    }
                    else
                    {
                        Utilizado = false;
                    }
                }
            }
            else
            {
                List <Nodo> serie = new List <Nodo>();
                for (int i = 0; i < ListaAux1.Count; i++)
                {
                    serie.Add(ListaAux1[i]);
                }
                List <int> Aux = new List <int>();
                for (int i = 0; i < ListaAux1.Count; i++)
                {
                    Aux.Add(ListaAux1[i].Identificador);
                }
                camino.Add(Aux);
            }
        }
示例#3
0
        public void FleuryAlgoritmoRec(List <Nodo> ListaAux1, List <Nodo> ListaAux2, Grafo g, List <List <int> > circuito)
        {
            Nodo    nd    = ListaAux1[ListaAux1.Count - 1];
            Boolean usado = false;

            if (ListaAux2.Count < g.ObtenNumeroRelaciones() / 2)
            {
                for (int i = 0; i < nd.ObtenGradoNodo(); i++)
                {
                    Nodo aux = BuscaNodoInt(g.Nodos, nd.ObtenRelacion(i).Destino);

                    for (int j = 0; j < ListaAux2.Count; j++)
                    {
                        if ((ListaAux1[j].Equals(aux) && ListaAux2[j].Equals(nd)) || (ListaAux1[j].Equals(nd) && ListaAux2[j].Equals(aux)))
                        {
                            usado = true;
                            break;
                        }
                    }

                    if (!usado)
                    {
                        ListaAux2.Add(aux);
                        ListaAux1.Add(aux);
                        FleuryAlgoritmoRec(ListaAux1, ListaAux2, g, circuito);
                        ListaAux1.RemoveAt(ListaAux1.Count - 1);
                        ListaAux2.RemoveAt(ListaAux2.Count - 1);
                    }
                    else
                    {
                        usado = false;
                    }
                }
            }
            else
            {
                List <Nodo> serie = new List <Nodo>();
                for (int i = 0; i < ListaAux1.Count; i++)
                {
                    serie.Add(ListaAux1[i]);
                }
                List <int> Aux = new List <int>();
                for (int i = 0; i < ListaAux1.Count; i++)
                {
                    Aux.Add(ListaAux1[i].Identificador);
                }
                circuito.Add(Aux);
            }
        }
示例#4
0
        public bool AlgoritmoManualBotello(Grafo grafo1, Grafo grafo2)
        {
            SaveFileDialog VentanaGuardar  = new SaveFileDialog();
            string         CadenaAEscribir = "";
            string         Ruta            = "";
            int            SumaColumna     = 0;

            int[,] MatrizU = grafo1.GeneraMatrizAdyacencia();
            int[,] MatrizV = grafo2.GeneraMatrizAdyacencia();
            List <int> ArregloGradosSalidaColumna;

            VentanaGuardar.Filter = "Texto (*.txt)|*.txt";
            MessageBox.Show("Por favor selecciona donde guardar el resultado");
            if (VentanaGuardar.ShowDialog() == DialogResult.OK)
            {
                Ruta = VentanaGuardar.FileName;
            }

            if ((grafo1.Nodos.Count == grafo2.Nodos.Count) && (grafo1.ObtenNumeroRelaciones() == grafo2.ObtenNumeroRelaciones())) // Si tenemos el mismo número de relaciones y nodos
            {
                for (int i = 0; i < grafo1.Nodos.Count - 1; i++)
                {
                    ArregloGradosSalidaColumna = new List <int>();
                    SumaColumna = grafo1.ObtenGradoEntradaNodo(grafo1.Nodos[i]);
                    for (int j = 0; j < grafo1.Nodos.Count; j++)
                    {
                        if (MatrizU[j, i] == 1)
                        {
                            int NumAuxGrados = 0;
                            for (int z = 0; z < grafo1.Nodos.Count; z++)
                            {
                                NumAuxGrados += MatrizU[z, j];
                            }
                            ArregloGradosSalidaColumna.Add(NumAuxGrados);
                        }
                    }
                    int ColSim = BuscaColumnaSimilar(SumaColumna, i + 1, MatrizV, grafo2, ArregloGradosSalidaColumna);
                    if (ColSim != 0)
                    {
                        CadenaAEscribir += "Comparando con la columna: " + (i + 1) + " de la matriz 1 \n" + "Columna Similar encontrada: " + (ColSim + 1) + " en la matriz 2 " + "\n";
                        intercambiaColumnna(i, ColSim, MatrizV, grafo1.Nodos.Count);
                        intercambiaRenglon(i, ColSim, MatrizV, grafo1.Nodos.Count);
                        CadenaAEscribir += "\nNueva Matriz: \n" + FormateaMatrizaCadena(MatrizV) + "\n";
                        if (ComparaMatrices(MatrizU, MatrizV, grafo1.Nodos.Count))
                        {
                            CadenaAEscribir += "\n\nLos grafos son isomorfos";
                            using (StreamWriter Escritor = new StreamWriter(Ruta))
                            {
                                Escritor.WriteLine(CadenaAEscribir);
                            }
                            return(true);
                        }
                    }
                    else
                    {
                        CadenaAEscribir += "No se encontaron coincidencias con la columna: " + (i + 1) + " de la matriz 1\n";
                    }
                }
            }
            else
            {
                MessageBox.Show("Los grafos no tienen el mismo número de nodos o el mismo número de relaciones!!!!");
            }
            CadenaAEscribir += "\n Los grafos no son isomorfos";
            using (StreamWriter Escritor = new StreamWriter(Ruta))
            {
                Escritor.WriteLine(CadenaAEscribir);
            }
            return(false);
        }