Пример #1
0
 ElementoDijkstra BuscaElementoDijkstra(List <ElementoDijkstra> VD, Ady a)
 {
     foreach (ElementoDijkstra ed in VD)
     {
         if (ed.GetDes() == a.getNodo())
         {
             return(ed);
         }
     }
     return(null);
 }
Пример #2
0
        public void agregarArista(Vuelo v)
        {
            bool ori = false, des = false;

            foreach (Nodo n in listaNodos)
            {
                if (n.getCiudad() == v.getOrigen())
                {
                    ori = true;
                }
                if (n.getCiudad() == v.getDestino())
                {
                    des = true;
                }
            }

            if (!ori)
            {
                Nodo o = new Nodo(v.getOrigen());
                listaNodos.Add(o);
            }
            if (!des)
            {
                Nodo d = new Nodo(v.getDestino());
                listaNodos.Add(d);
            }


            foreach (Nodo n in listaNodos)
            {
                if (n.getCiudad() == v.getOrigen())
                {
                    foreach (Nodo nAux in listaNodos)
                    {
                        if (nAux.getCiudad() == v.getDestino())
                        {
                            Ady a = new Ady(nAux, v.getCosto(), v.getTiempo());
                            n.getListaAdy().Add(a);
                        }
                    }
                }
            }
        }
Пример #3
0
        /*
         * public void insertaAdy(Nodo n, int c)
         * {
         *  Ady adyacente = new Ady(n, c);
         *  listaAdy.Add(adyacente);
         * }
         */

        public void insertaAdy(Ady a)
        {
            this.listaAdy.Add(a);
        }
Пример #4
0
        public Grafo(ListaVuelos lv)
        {
            listaNodos = new List <Nodo>();

            bool existeN = false;

            foreach (Vuelo v in lv)
            {
                existeN = false;

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



            existeN = false;
            foreach (Vuelo v in lv)
            {
                existeN = false;
                foreach (Nodo nAux in listaNodos)
                {
                    if (nAux.getCiudad() == v.getDestino())
                    {
                        existeN = true;
                        break;
                    }
                }
                if (!existeN)
                {
                    Nodo n = new Nodo(v.getDestino());
                    listaNodos.Add(n);
                }
            }



            //crea lista ady de cada nodo
            foreach (Nodo n in listaNodos)
            {
                //Console.WriteLine(n.getCiudad());
                foreach (Vuelo v in lv)
                {
                    if (v.getOrigen() == n.getCiudad())
                    {
                        foreach (Nodo nRef in listaNodos)
                        {
                            if (nRef.getCiudad() == v.getDestino())
                            {
                                Ady nuevoadyacente = new Ady(nRef, v.getCosto(), v.getTiempo());
                                n.insertaAdy(nuevoadyacente);
                            }
                        } //ref lista nodos
                    }     //if
                }         //foreach vuelos
            }             //foreach nodos
        }