Esempio n. 1
0
        public FormPasajeros(ListaVuelos lv)
        {
            this.lv = lv;

            ListaPasajeros lpC = new ListaPasajeros();

            this.lpC = lpC;

            foreach (ClassVuelo v in lv)
            {
                foreach (ClassPasajero pas in v.getListaPasajeros())
                {
                    this.lpC.Add(pas);
                }
            }



            InitializeComponent();
            actualizaListaCompleta();


            groupBoxOrdenar.Controls.OfType <RadioButton>().ToList().ForEach((radiobutton) =>
            {
                radiobutton.AutoCheck = false;
                radiobutton.Checked   = false;
                radiobutton.AutoCheck = true;
            });
        }
Esempio n. 2
0
        public FormGrafo(Grafo g, int bandera, ListaVuelos lv)
        {
            this.g  = g;
            this.lv = lv;

            this.bandera = bandera;


            InitializeComponent();



            DibujarAdyacencias(1, g);
            DibujarNodos(1, g);


            RefrescarListaCiudades();



            if (bandera == 1)
            {
                textbox = "AGREGA CIUDAD ORIGEN";
            }
            if (bandera == 2)
            {
                textbox = "AGREGA CIUDAD DESTINO";
            }
            textBoxCaso.Text = textbox;
        }
Esempio n. 3
0
        public ListaVuelos busquedaCoincidencias(string dato, int opc)
        {
            ListaVuelos lvF = new ListaVuelos();

            switch (opc)
            {
            case 1:    //Buscar por ruta
            {
                for (int i = 0; i < this.Count; i++)
                {
                    int j;
                    for (j = 0; j < dato.Length; j++)
                    {
                        if (this[i].getRuta()[j] != dato[j])
                        {
                            break;
                        }
                    }
                    if (j == dato.Length)
                    {
                        lvF.Add(this[i]);
                    }
                }

                break;
            }

            case 2:    //buscar por origen
            {
                for (int i = 0; i < this.Count; i++)
                {
                    if (this[i].getOrigen() == dato)
                    {
                        lvF.Add(this[i]);
                    }
                }

                break;
            }

            case 3:    //buscar por destino
            {
                for (int i = 0; i < this.Count; i++)
                {
                    if (this[i].getDestino() == dato)
                    {
                        lvF.Add(this[i]);
                    }
                }

                break;
            }
            }
            return(lvF);
        }
Esempio n. 4
0
        ////////////////////////////
        public FormMainVuelos(ListaVuelos lv, Grafo g)
        {
            this.g  = g;
            this.lv = lv;

            InitializeComponent();


            for (int i = 0; i < lv.Count; i++)                     //SE AGREGAN LOS ELEMENTOS A LAS LISTVIEW DISENIADOR
            {
                listBoxVuelos.Items.Add(lv[i]);                    //DADO QUE LOS ELEMENTOS ALMACENADOS EN LA LISTA SON DE TIPO OBJECT
            }                                                      //SE TIENE QUE HACER EL METODO Override ToString (en la clase vuelo)
        }
Esempio n. 5
0
        public ListaVuelos quicksortCosto(ListaVuelos lista, int primero, int ultimo)
        {
            int    i, j, central;
            double pivote;

            central = (primero + ultimo) / 2;
            pivote  = lista[central].getCosto();
            i       = primero;
            j       = ultimo;
            do
            {
                while (lista[i].getCosto() < pivote)
                {
                    i++;
                }
                while (lista[j].getCosto() > pivote)
                {
                    j--;
                }
                if (i <= j)
                {
                    ClassVuelo temp;
                    temp     = lista[i];
                    lista[i] = lista[j];
                    lista[j] = temp;
                    i++;
                    j--;
                }
            } while (i <= j);

            if (primero < j)
            {
                quicksortCosto(lista, primero, j);
            }
            if (i < ultimo)
            {
                quicksortCosto(lista, i, ultimo);
            }



            return(lista);
        }
Esempio n. 6
0
        public Grafo(ListaVuelos lv)
        {
            this.lv = lv;
            ///crear Nodos

            bool existe;

            listaNodos = new List <Nodo>();
            foreach (ClassVuelo v in lv)
            {
                existe = false;

                foreach (Nodo nAux in listaNodos)
                {
                    if (v.getOrigen() == nAux.getCiudad().getNom().ToString())
                    {
                        existe = true;
                        break;
                    }
                }
                if (!existe)
                {
                    Nodo n = new Nodo(v.getOrigen());
                    listaNodos.Add(n);
                }
                existe = false;

                foreach (Nodo nAux2 in listaNodos)
                {
                    if (v.getDestino() == nAux2.getCiudad().getNom().ToString())
                    {
                        existe = true;
                        break;
                    }
                }
                if (!existe)
                {
                    Nodo n = new Nodo(v.getDestino());
                    listaNodos.Add(n);
                }
            }

            //crea adyacencias
            foreach (Nodo n in listaNodos)
            {
                foreach (ClassVuelo v in lv)
                {
                    if (n.getCiudad().getNom().ToString() == v.getOrigen())
                    {
                        foreach (Nodo nAux in listaNodos)
                        {
                            if (nAux.getCiudad().getNom().ToString() == v.getDestino())
                            {
                                Ady a = new Ady(nAux);
                                n.setAdy(a);
                                a.setPonderacionCosto(v.getCosto());
                                a.setPonderacionTiempo(v.getTiempo());
                            }
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        private void buttonTiemposPrim_Click(object sender, EventArgs e)
        {
            panel1.Refresh();
            listBoxRutasOptimas.Items.Clear();
            listBoxTOTAL.Items.Clear();
            listBoxCostos.Items.Clear();
            ////////////////////////////
            //Comprobar que el grafo sea conexo


            //Crear un grafo igual al oficial PARA TRABJAR CON EL Y PODERLO MODIFICAR
            Grafo grafoDirigidoP = new Grafo(lv);


            ListaAristas ARM        = new ListaAristas(); //ARM
            ListaVuelos  listaPrim  = new ListaVuelos();  //Lista de vuelos igual  ARM para grafo
            ListaAristas candidatos = new ListaAristas();

            foreach (Nodo n in grafoDirigidoP.getListaNodos())
            {
                foreach (Ady a in n.getListaAdyacencia())
                {
                    Arista arist = new Arista(n, a.getNodo(), a.getPonderacionCosto(), a.getPonderacionTiempo());
                    candidatos.Add(arist);
                }
            }
            candidatos.quicksortTiempo(candidatos, 0, candidatos.Count - 1);

            //INICILAIZA LISTA DE NODOS
            List <Nodo> S = new List <Nodo>();

            ////Seleccionar un origen y agregarlo s

            foreach (Nodo n in grafoDirigidoP.getListaNodos())
            {
                if (n.getCiudad().getNom() == (string)listBoxSeleccionaCiudad.SelectedItem)
                {
                    S.Add(n);
                    break;
                }
            }



            //Algoritmo
            while (ARM.Count < grafoDirigidoP.getListaNodos().Count() - 1)
            {
                Arista ar = candidatos.seleccionFactibel(candidatos, S);

                ARM.Add(ar);
                if (S.Contains(ar.getNodoOrigen()))
                {
                    S.Add(ar.getNodoDestinon());
                }
                else
                {
                    S.Add(ar.getNodoOrigen());
                }
            }

            //llenar lista de vuelos priam en base a las lista optenida de aristas del ARM para construir grafo(ARM)

            foreach (Arista a in ARM)
            {
                ClassVuelo v = new ClassVuelo(a.getNodoOrigen().getCiudad().getNom(), a.getNodoDestinon().getCiudad().getNom(), a.getPonderacionCosto(), a.getPonderacionTimepo());
                listaPrim.Add(v);
            }

            Grafo ARMG = new Grafo(listaPrim);

            //establecer coordeadas
            foreach (Nodo n in ARMG.getListaNodos())
            {
                foreach (Nodo n2 in g.getListaNodos())
                {
                    if (n.getCiudad().getNom() == n2.getCiudad().getNom())
                    {
                        n.getCiudad().setX(n2.getCiudad().getX());
                        n.getCiudad().setY(n2.getCiudad().getY());
                    }
                }
            }

            //LLENAR LISTAS DE TIEMPO Y TOTAL
            int suma = 0;

            foreach (ClassVuelo vs in listaPrim)
            {
                listBoxRutasOptimas.Items.Add(vs.getRuta());
            }
            foreach (ClassVuelo vs in listaPrim)
            {
                listBoxCostos.Items.Add(vs.getTiempo() + " Min");
                suma += vs.getTiempo();
            }

            listBoxTOTAL.Items.Add(suma + " Min");


            //DIBUJAR ADYACENCIAS Y NODOS

            DibujarAdyacencias(2, ARMG);
            // DibujarNodos(2, ARM);

            DibujarAdyacencias(1, g);
            DibujarNodos(1, g);
        }
Esempio n. 8
0
        private void buttonCostosKruskal_Click(object sender, EventArgs e)
        {
            panel1.Refresh();
            listBoxRutasOptimas.Items.Clear();
            listBoxTOTAL.Items.Clear();
            listBoxCostos.Items.Clear();
            buttonTiemposPrim.Enabled = false;
            listBoxSeleccionaCiudad.ClearSelected();

            ListaVuelos listaKruskal = new ListaVuelos();

            //Crear un grafo igual al anterior
            Grafo grafoDirigido = new Grafo(lv);

            grafoDirigido = g;

            //Conbertir el grafo en NO dirigido (NO NESESARIO)

            //Crear lista de Prioridad(Aristas)
            ListaAristas candidatos = new ListaAristas();


            foreach (Nodo n in grafoDirigido.getListaNodos())
            {
                foreach (Ady nA in n.getListaAdyacencia())
                {
                    Arista arista = new Arista(n, nA.getNodo(), nA.getPonderacionCosto(), nA.getPonderacionTiempo());
                    candidatos.Add(arista);
                }
            }


            //Ordenar candidatos de menor a mayor
            ListaAristas CandidatosOrdenados = new ListaAristas();

            CandidatosOrdenados = candidatos.quicksortCosto(candidatos, 0, candidatos.Count() - 1);



            //CREAR COMPONENTES CONEXSOS
            List <List <string> > CC = new List <List <string> >();

            for (int w = 0; w < g.getListaNodos().Count(); w++)
            {
                List <string> P = new List <string>();
                CC.Add(P);

                CC[w].Add(g.getListaNodos()[w].getCiudad().getNom());
            }



            //ALGROTIMO KRUSKAL

            for (int z = 0; z < CandidatosOrdenados.Count(); z++)
            {
                Arista V = CandidatosOrdenados[z];

                while (CC.Count() > 1)
                {
                    //BUSCA EN QUE CADENA SE ENCUENTRA EL ORIGEN
                    int i;
                    int j;

                    for (i = 0; i < CC.Count(); i++)
                    {
                        for (j = 0; j < CC[i].Count(); j++)
                        {
                            if (V.getNodoOrigen().getCiudad().getNom() == CC[i][j])
                            {
                                u1 = i;
                                goto End1;
                            }
                        }
                    }
End1:

                    //BUSCA EN QUE CADENA SE ENCUENTRA EL DESTINO
                    int q = 0;
                    int j2;

                    while (q < CC.Count())
                    {
                        for (j2 = 0; j2 < CC[q].Count(); j2++)
                        {
                            if (V.getNodoDestinon().getCiudad().getNom() == CC[q][j2])
                            {
                                u2 = q;

                                goto End;
                            }
                        }
                        q++;
                    }
End:



                    if (u1 != u2)
                    {
                        for (int o = 0; o < CC[u2].Count(); o++)
                        {
                            CC[u1].Add(CC[u2][o]);
                        }

                        CC.Remove(CC[u2]);

                        ClassVuelo vue = new ClassVuelo(V.getNodoOrigen().getCiudad().getNom(), V.getNodoDestinon().getCiudad().getNom(), V.getPonderacionCosto(), V.getPonderacionTimepo());
                        listaKruskal.Add(vue);
                    }



                    break;
                }
            }
            Grafo ARM = new Grafo(listaKruskal);

            //ESTALECERLE LAS CORDENADAS AL ARM
            for (int a = 0; a < g.getListaNodos().Count(); a++)
            {
                for (int k = 0; k < ARM.getListaNodos().Count(); k++)
                {
                    if (ARM.getListaNodos()[k].getCiudad().getNom() == g.getListaNodos()[a].getCiudad().getNom())
                    {
                        ARM.getListaNodos()[k].getCiudad().setX(g.getListaNodos()[a].getCiudad().getX());
                        ARM.getListaNodos()[k].getCiudad().setY(g.getListaNodos()[a].getCiudad().getY());
                    }
                }
            }


            int suma = 0;

            foreach (ClassVuelo vs in listaKruskal)
            {
                listBoxRutasOptimas.Items.Add(vs.getRuta());
            }
            foreach (ClassVuelo vs in listaKruskal)
            {
                listBoxCostos.Items.Add("$ " + vs.getCosto());
                suma += vs.getCosto();
            }

            listBoxTOTAL.Items.Add("$ " + suma);



            DibujarAdyacencias(2, ARM);
            // DibujarNodos(2, ARM);

            DibujarAdyacencias(1, g);
            DibujarNodos(1, g);
        }