Esempio n. 1
0
        public void CaminoEuler(Grafo g, int idOrigen, int idDestino, List <List <int> > Camino)
        {
            List <int> ListaAuxInt = new List <int>();
            Nodo       origen      = g.Nodos[idOrigen - 1];
            Nodo       destino     = g.Nodos[idDestino - 1];

            foreach (Nodo n in g.Nodos)
            {
                ListaAuxInt.Add(n.ObtenGradoNodo());
            }

            int Pares = 0, Impares = 0;

            for (int i = 0; i < ListaAuxInt.Count; i++)
            {
                if (ListaAuxInt[i] % 2 == 0)
                {
                    Pares++;
                }
                else
                {
                    Impares++;
                }
            }

            if (Pares == ListaAuxInt.Count - 2 && Impares == 2)
            {
                if (origen.ObtenGradoNodo() % 2 != 0 && destino.ObtenGradoNodo() % 2 != 0)
                {
                    List <Nodo> ListaAux1, ListaAux2;
                    ListaAux1 = new List <Nodo>();
                    ListaAux2 = new List <Nodo>();
                    ListaAux1.Add(origen);

                    for (int i = 0; i < origen.ObtenGradoNodo(); i++)
                    {
                        ListaAux2.Add(BuscaNodoInt(g.Nodos, origen.ObtenRelacion(i).Destino));
                        ListaAux1.Add(BuscaNodoInt(g.Nodos, origen.ObtenRelacion(i).Destino));
                        EulerAlgoritmoRec(ListaAux1, ListaAux2, g, Camino);
                        ListaAux1.RemoveAt(ListaAux1.Count - 1);
                        ListaAux2.RemoveAt(ListaAux2.Count - 1);
                    }
                }
                else
                {
                    MessageBox.Show("Seleccione los nodos de grado impar");
                }
            }
            else
            {
                MessageBox.Show("No cumple los requisitos");
            }

            origen  = null;
            destino = null;
        }
Esempio n. 2
0
        public void CircuitoEuler(Grafo g, int idNodo, List <List <int> > circuito)
        {
            Boolean    requisitos = true;
            List <int> arr        = new List <int>();
            Nodo       origen     = BuscaNodoInt(g.Nodos, idNodo);

            foreach (Nodo n in g.Nodos)
            {
                arr.Add(n.ObtenGradoNodo());
            }
            for (int i = 0; i < arr.Count; i++)
            {
                if (arr[i] % 2 != 0)
                {
                    requisitos = false;
                }
            }
            if (requisitos)
            {
                List <Nodo> ListaAux1, ListaAux2;
                ListaAux1 = new List <Nodo>();
                ListaAux2 = new List <Nodo>();
                ListaAux1.Add(origen);

                for (int i = 0; i < origen.ObtenGradoNodo(); i++)
                {
                    ListaAux2.Add(BuscaNodoInt(g.Nodos, origen.ObtenRelacion(i).Destino));
                    ListaAux1.Add(BuscaNodoInt(g.Nodos, origen.ObtenRelacion(i).Destino));
                    FleuryAlgoritmoRec(ListaAux1, ListaAux2, g, circuito);
                    ListaAux1.RemoveAt(ListaAux1.Count - 1);
                    ListaAux2.RemoveAt(ListaAux2.Count - 1);
                }
            }
            else
            {
                MessageBox.Show("Desafortunadamente no  todos los nodos tienen grado par");
            }

            origen = null;
        }
Esempio n. 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);
            }
        }
Esempio n. 4
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);
            }
        }