Exemple #1
0
        public Kruscal(Grafo g, ListaVuelos lv, char opc)
        {
            //Console.Write("\nKruscal ");
            int    u1, u2;
            String v1 = "", v2 = "";
            Vuelo  aux;

            foreach (Vuelo v in lv)
            {
                c.Add(v);
            }

            if (opc == 'c')
            {
                c.quickSort(0, c.Count - 1, 3);
                //Console.Write("costo ->");
            }
            else
            {
                c.quickSort(0, c.Count - 1, 4);
                //Console.Write("tiempo ->");
            }
            inicializaCC(g);


            while (c.Count > 0)
            {
                aux = seleciona(c);
                v1  = v1 + aux.getOrigen();
                v2  = v2 + aux.getDestino();

                u1 = busca(aux.getOrigen());
                u2 = busca(aux.getDestino());

                if (u1 != u2)
                {
                    combina(u1, u2);
                    arm.Add(aux);
                    ct = ct + aux.getCosto();
                    tt = tt + aux.getTiempo();

                    //Console.Write(aux.getOrigen().ToString()+aux.getDestino().ToString()+"-> ");
                }
            }
            gk = new Grafo(arm);
        }
Exemple #2
0
        Vuelo Selecciona(char opc, List <Nodo> nodos)
        {
            ListaVuelos candidatos = new ListaVuelos();
            Vuelo       aux;
            bool        stop = true;

            candidatos.Clear();

            foreach (Nodo n in nodos)
            {
                foreach (Vuelo v in vuelos)
                {
                    if (v.getOrigen() == n.getCiudad() || v.getDestino() == n.getCiudad())
                    {
                        candidatos.Add(v);
                    }
                }
            }

            if (candidatos.Count > 0)
            {
                if (opc == 'c')
                {
                    candidatos.quickSort(0, candidatos.Count - 1, 3);
                }
                else
                {
                    candidatos.quickSort(0, candidatos.Count - 1, 4);
                }


                aux = candidatos[0];
                this.vuelos.Remove(candidatos[0]);

                if (!Ciudades.Contains(new Nodo(aux.getOrigen())))
                {
                    Ciudades.Add(new Nodo(aux.getOrigen()));
                }

                if (!Ciudades.Contains(new Nodo(aux.getDestino())))
                {
                    Ciudades.Add(new Nodo(aux.getDestino()));
                }

                do
                {
                    stop = true;
                    foreach (Nodo n2 in Ciudades)
                    {
                        foreach (Nodo n in Ciudades)
                        {
                            foreach (Vuelo v in this.vuelos)
                            {
                                if (v.getOrigen() == n2.getCiudad() && v.getDestino() == n.getCiudad())
                                {
                                    vuelos.Remove(v);
                                    stop = false;
                                    break;
                                }
                            }
                        }
                    }
                } while (!stop);

                //Console.Write(aux.getOrigen().ToString() + aux.getDestino().ToString() + "-> ");
                tt = tt + aux.getTiempo();
                ct = ct + aux.getCosto();
                return(aux);
            }
            return(null);
        }
 private void radioButtonOOrigen_CheckedChanged(object sender, EventArgs e)
 {
     lv.quickSort(0, lv.Count - 1, 1);
     actializarListBoxt(this.lv);
 }