Exemplo n.º 1
0
        public Grafo(ListaVuelos listaV)
        {
            this.listaV = listaV;
            List <string> listaN = new List <string>();

            for (int i = 0; i < listaV.Count; i++)
            {
                if (!listaN.Contains(listaV[i].getO()))
                {
                    listaN.Add(listaV[i].getO());
                }
                if (!listaN.Contains(listaV[i].getD()))
                {
                    listaN.Add(listaV[i].getD());
                }
            }
            for (int i = 0; i < listaN.Count; i++)
            {
                ListaAristas listaA = new ListaAristas();
                for (int j = 0; j < listaV.Count; j++)
                {
                    if (listaV[j].getD() == listaN[i])
                    {
                        Arista arista = new Arista(listaV[j].d, listaV[j].costo);
                        listaA.Add(arista);
                    }
                }

                Nodo n = new Nodo(listaN[i], listaA);
                this.Add(n);
            }
        }
Exemplo n.º 2
0
        public void insertarVertice(char vertice)
        {
            bool existe = false;

            for (int i = 0; i < this.Count; i++)
            {
                if (this[i].getOrigen() == vertice)
                {
                    existe = true;
                    break;
                }
                foreach (Arista a in this[i].listaA)
                {
                    if (a.getDestino() == vertice)
                    {
                        existe = true;
                    }
                }

                if (!existe)
                {
                    ListaAristas la   = new ListaAristas();
                    Vertice      newV = new Vertice(vertice, la);
                    this.Add(newV);
                }
            }
        }
Exemplo n.º 3
0
        public Grafo(List <Universal> listavuelos)
        {
            this.listavuelos = listavuelos;
            listaVertices    = new List <char>();

            for (int i = 0; i < listavuelos.Count; i++)
            {
                if (!listaVertices.Contains(listavuelos[i].getOrigen()))
                {
                    listaVertices.Add(listavuelos[i].getOrigen());
                }
                if (!listaVertices.Contains(listavuelos[i].getDestino()))
                {
                    listaVertices.Add(listavuelos[i].getDestino());
                }
            }
            for (int c = 0; c < listaVertices.Count; c++)
            {
                ListaAristas listaAristas = new ListaAristas();

                for (int k = 0; k < listavuelos.Count; k++)
                {
                    if (listaVertices[c] == listavuelos[k].getOrigen())
                    {
                        Arista a = new Arista(listavuelos[k].getCosto(), listavuelos[k].getTiempo(), listavuelos[k].getOrigen(), listavuelos[k].getDestino());
                        listaAristas.Add(a);
                    }
                }
                Vertice v = new Vertice(listaVertices[c], listaAristas);
                this.Add(v);
            }
        }
Exemplo n.º 4
0
 public Vertice(char o, ListaAristas listaA)
 {
     this.origen = o;
     this.listaA = new ListaAristas();
     this.listaA = listaA;
     x           = 0;
     y           = 0;
 }
Exemplo n.º 5
0
        private void prim()
        {
            listBoxRecorrido.Items.Clear();

            Font       letra            = new Font("Arial", 10);
            SolidBrush color            = new SolidBrush(Color.Black);
            Color      newColor         = Color.FromArgb(75, Color.Red);
            Pen        lapiz            = new Pen(newColor, 8);
            int        ponderacionTotal = 0;
            int        indice;

            indice = comboOrigenes.SelectedIndex;
            Console.WriteLine("Seleccionado=" + graph[indice].getOrigen());
            Vertice        origen    = graph[indice];
            Vertice        aux       = origen;
            List <Vertice> aceptados = new List <Vertice>();
            List <char>    visitados = new List <char>();

            // ordenarAdyacencia(graph);
            if (origen.getListaAristas().Count > 0)
            {
                Arista menor = origen.getListaAristas()[0];

                List <Arista>  ArcosUsados = new List <Arista>();
                List <string>  conjuntos   = new List <string>();
                List <Vertice> ListPrim    = new List <Vertice>();

                int  cont = 0;
                int  cont2 = 1;
                bool band1, band2, band4;
                int  cont3 = 0;

                do
                {
                    band1 = band2 = true;
                    ListaAristas la = new ListaAristas(); //no estoy pasando lista aristas en blanco?
                    foreach (Arista a in aux.getListaAristas())
                    {
                        if (!ArcosUsados.Contains(a))
                        {
                            Vertice NV = new Vertice(aux.getOrigen(), la);
                            NV.getListaAristas().Add(a);//agregado extra
                            NV.setX(aux.getX());
                            NV.setY(aux.getY());
                            NV.getListaAristas().Add(a);
                            ListPrim.Add(NV);
                        }
                    }

                    foreach (Vertice n in ListPrim)
                    {
                        if (menor.getCosto() >= n.getListaAristas()[0].getCosto() || ArcosUsados.Contains(menor))
                        {
                            menor = n.getListaAristas()[0];
                            aux   = n;
                        }
                    }

                    foreach (String a in conjuntos)
                    {
                        if (Convert.ToString(aux.getOrigen()) == a)
                        {
                            band1 = false;
                        }
                        if (Convert.ToString(menor.getDestino()) == a) //checar aqui
                        {
                            band2 = false;
                        }
                    }

                    if (band1 == true || band2 == true)
                    {
                        Vertice NV = aux;
                        aceptados.Add(NV);
                        visitados.Add(NV.getOrigen());
                        if (band1 == true)
                        {
                            conjuntos.Add(Convert.ToString(aux.getOrigen()));
                        }
                        if (band2 == true)
                        {
                            conjuntos.Add(Convert.ToString(aux.getListaAristas()[0].getDestino()));
                        }
                        ArcosUsados.Add(menor);
                    }

                    if (band1 == false && band2 == false)
                    {
                        ArcosUsados.Add(menor);
                    }
                    ListPrim.Remove(aux);
                    Console.WriteLine("Menor= " + menor.getDestino());
                    //aux = menor; //aqui es el pedo
                    foreach (Vertice v in graph)
                    {
                        if (v.getOrigen() == menor.getOrigen())
                        {
                            foreach (Vertice v2 in graph)
                            {
                                if (v2.getOrigen() == v.getListaAristas()[0].getDestino())
                                {
                                    Console.WriteLine("Aux antes = " + aux.getOrigen());
                                    aux = v2;
                                    Console.WriteLine("Aux despues= " + aux.getOrigen());
                                }
                            }
                        }
                    }
                    cont++;
                }while (ArcosUsados.Count < graph.Count());
            }
            Console.WriteLine("LISTA DE ACEPTADOS");
            foreach (Vertice a in aceptados)
            {
                Console.WriteLine(a.getOrigen());
            }

            listBoxRecorrido.Items.Clear();
            for (int i = 0; i < graph.Count - 1; i++)
            {
                for (int j = 0; j < graph[i].getListaAristas().Count; j++)
                {
                    for (int k = 0; k < aceptados.Count; k++)
                    {
                        if (graph[i].getOrigen() == aceptados[k].getOrigen() && graph[i].getListaAristas()[j].getDestino() == aceptados[k].getListaAristas()[0].getDestino())
                        {
                            panelGrafo.CreateGraphics().DrawLine(lapiz, graph[i].getX(), graph[i].getY(), graph[i].getListaAristas()[j].getX(), graph[i].getListaAristas()[j].getY());

                            listBoxRecorrido.Items.Add(graph[i].getOrigen().ToString() + graph[i].getListaAristas()[j].getDestino().ToString());
                        }
                    }
                }
            }
            letras();
            letreroARM.Text    = "Peso total con Prim: " + ponderacionTotal;
            letreroARM.Visible = Enabled;
        }//fin
Exemplo n.º 6
0
 public Nodo(string o, ListaAristas aristList)
 {
     origen       = o;
     listaAristas = new ListaAristas();
     listaAristas = aristList;
 }