コード例 #1
0
ファイル: GrafoVisual.cs プロジェクト: emagacus/FlightControl
        List <DijkstraNode> Dijkstra(CiudadNodo origen, CiudadNodo destino)
        {
            List <DijkstraNode> caminos = new List <DijkstraNode>();

            CiudadNodo nodoActual  = origen;
            string     Definitivos = "";
            int        numDef      = 0;


            //Se crea el vector de caminos

            foreach (CiudadNodo c in listaciudades)
            {
                DijkstraNode nodo = new DijkstraNode(c, 1000000000);

                if (c.getName() == origen.getName())
                {
                    nodo.peso        = 0;
                    nodo.procedencia = origen;
                }

                caminos.Add(nodo);
            }


            //*** Se inicia con el origen;

            Definitivos = origen.getName();
            numDef++;

            //***


            while (numDef != listaciudades.Count)
            {
                dijskUpdate(ref nodoActual, ref caminos, ref Definitivos);
                if (Definitivos.Contains(destino.name))
                {
                    break;
                }
                numDef++;
            }



            return(caminos);
        }
コード例 #2
0
ファイル: GrafoVisual.cs プロジェクト: emagacus/FlightControl
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            var mouseEventArgs = e as MouseEventArgs;

            if (NewMarkerEnabled)
            {
                pictureBox1.Image = new Bitmap(pictureBox1.Image);
                g = Graphics.FromImage(pictureBox1.Image);
                g.DrawEllipse(pen1, mouseEventArgs.X, mouseEventArgs.Y, 10, 10);
                NewMarkerEnabled = false;

                List <AristaCiudad> aris = new List <AristaCiudad>();
                CiudadNodo          city = new CiudadNodo(mouseEventArgs.X, mouseEventArgs.Y, name, aris);
                listaciudades.Add(city);

                this.Close();
            }
        }
コード例 #3
0
ファイル: GrafoVisual.cs プロジェクト: emagacus/FlightControl
        //



        //*****   DIJKSTRA


        //        ****          ***        ***        *   *     *****    *****     *****      *****        //
        //        *   *          *          *         *  *      *   *      *       *   *      *   *        //
        //        *    *         *          *         * *       *   *      *       *   *      *   *        //
        //        *     *        *          *         **        *          *       *****      *****        //
        //        *     *        *          *         **        *****      *       *  *       *   *        //
        //        *    *         *      *   *         * *           *      *       *   *      *   *        //
        //        *   *          *       *  *         *  *      *   *      *       *    *     *   *        //
        //        ****          ***       ***         *   *     *****      *       *    *     *   *        //



        CiudadNodo dijskUpdate(ref CiudadNodo nodoactual, ref List <DijkstraNode> caminos, ref string Definitivos)
        {
            DijkstraNode nuevo = new DijkstraNode();



            foreach (DijkstraNode d in caminos)
            {
                if (d.IdNodo.name == nodoactual.name)
                {
                    nuevo.peso = d.peso; break;
                }
            }

            if (checkBoxCosto.Checked)
            {
                foreach (AristaCiudad a in nodoactual.Aristas)
                {
                    foreach (DijkstraNode d in caminos)
                    {
                        if (a.getDest() == d.IdNodo.name)
                        {
                            if ((a.getCosto() + nuevo.peso) < d.peso)
                            {
                                d.peso        = a.getCosto() + nuevo.peso;
                                d.AristaPeso  = a.getCosto();
                                d.procedencia = nodoactual;
                            }
                        }
                    }
                } //fin foreach arista
            }
            else  ////***Tiempo

            {
                foreach (AristaCiudad a in nodoactual.Aristas)
                {
                    foreach (DijkstraNode d in caminos)
                    {
                        if (a.getDest() == d.IdNodo.name)
                        {
                            if ((a.getTiempo() + nuevo.peso) < d.peso)
                            {
                                d.peso        = a.getTiempo() + nuevo.peso;
                                d.AristaPeso  = a.getTiempo();
                                d.procedencia = nodoactual;
                            }
                        }
                    }
                }//fin foreach arista
            }



            caminos.Sort((x, y) => x.peso.CompareTo(y.peso));
            foreach (DijkstraNode d in caminos)
            {
                if (!Definitivos.Contains(d.IdNodo.name))
                {
                    nodoactual = d.IdNodo; break;
                }
            }
            Definitivos = Definitivos + nodoactual.name;



            ///***

            return(nodoactual);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: emagacus/FlightControl
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Principal());

            ListaVuelos listaVuelos = new ListaVuelos();
            ListaCiudades listaciudades = new ListaCiudades();

            try
            {   // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader("infoVuelos.txt"))
                {
                    // Read the stream to a string, and write the string to the console.

                    while (!sr.EndOfStream)
                    {

                        String line = sr.ReadLine();
                        string[] datavuelo = line.Split('|');
                        Console.WriteLine(datavuelo[5]);
                        DateTime date = DateTime.Parse(datavuelo[5]);
                        Vuelo vuelo = new Vuelo(int.Parse(datavuelo[0]),datavuelo[1], datavuelo[2], int.Parse(datavuelo[4]), int.Parse(datavuelo[3]),date);
                        listaVuelos.Add(vuelo);

                    }

                }
            }
            catch (Exception e)
            {

                Console.WriteLine("The file Info vueloes could not be read:");
                Console.WriteLine(e.Message);
                return;
            }

            //Leyendo usuarios

            try {
                using (StreamReader ifile = new StreamReader("usuarios.txt"))
                {

                    while(!ifile.EndOfStream)
                    {
                        string uline = ifile.ReadLine();
                        string[] du = uline.Split('|');
                        int indexV = int.Parse(du[0]);
                       //indice es igual a al primer campo de du
                        Usuario user = new Usuario(du[1], du[2], du[4], int.Parse(du[3]));

                        listaVuelos[indexV].userlist.Add(user);
                        listaVuelos[indexV].setAsientoTomado(int.Parse(du[3]));
                    }

                }
            }
            catch(Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);

            }

            //Leyendo Ciudades

            try
            {
                using (StreamReader ifile = new StreamReader("Ciudades.txt"))
                {

                    while (!ifile.EndOfStream)
                    {
                        string cline = ifile.ReadLine();
                        string[] cu = cline.Split('|');
                        List<AristaCiudad> aristas = new List<AristaCiudad>();

                        CiudadNodo city = new CiudadNodo(float.Parse(cu[0]), float.Parse(cu[1]), cu[2],aristas);

                        listaciudades.Add(city);

                    }

                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);

            }

            //Leyendo Aristas

            try
            {
                using (StreamReader ifile = new StreamReader("Aristas.txt"))
                {

                    while (!ifile.EndOfStream)
                    {
                        string aline = ifile.ReadLine();
                        string[] au = aline.Split('|');
                        AristaCiudad arista = new AristaCiudad(float.Parse(au[1]), float.Parse(au[2]),au[0], au[3], int.Parse(au[4]),int.Parse(au[5]));
                        int ind = listaciudades.getcityIndex(au[0]);
                        listaciudades[ind].Aristas.Add(arista);

                    }

                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);

            }

            Principal ventanaPrincipal = new Principal(ref listaVuelos,ref listaciudades);

            ventanaPrincipal.ShowDialog();
            //codigo para escribir
            //string lines = "First line.\r\nSecond line.\r\nThird line.";

            StreamWriter file = new StreamWriter("infoVuelos.txt");
            StreamWriter file2 = new StreamWriter("usuarios.txt");

            int vindex=0;

            foreach (Vuelo v in listaVuelos)
            {
                file.WriteLine(v.ToString('|'));

                foreach(Usuario u in v.userlist)
                {

                    file2.WriteLine(vindex.ToString()+'|'+u.ToString());
                }

                vindex++;
            }
            file.Close();
            file2.Close();

            StreamWriter filecity = new StreamWriter("Ciudades.txt");
            StreamWriter fileari = new StreamWriter("Aristas.txt");
            foreach(CiudadNodo c in listaciudades)
            {
                filecity.WriteLine(c.X.ToString() + '|' + c.Y.ToString() + '|' + c.getName());

                foreach (AristaCiudad a in c.Aristas)
                {
                    fileari.WriteLine(c.getName() + '|' + a.ToString());
                }
            }

            filecity.Close();
            fileari.Close();

            Console.WriteLine("fin del programa");
        }
コード例 #5
0
 public DijkstraNode(CiudadNodo IdNodo, float peso)
 {
     AristaPeso = 0;
     this.IdNodo = IdNodo;
     this.peso = peso;
 }
コード例 #6
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Principal());



            ListaVuelos   listaVuelos   = new ListaVuelos();
            ListaCiudades listaciudades = new ListaCiudades();


            try
            {   // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader("infoVuelos.txt"))
                {
                    // Read the stream to a string, and write the string to the console.

                    while (!sr.EndOfStream)
                    {
                        String   line      = sr.ReadLine();
                        string[] datavuelo = line.Split('|');
                        Console.WriteLine(datavuelo[5]);
                        DateTime date  = DateTime.Parse(datavuelo[5]);
                        Vuelo    vuelo = new Vuelo(int.Parse(datavuelo[0]), datavuelo[1], datavuelo[2], int.Parse(datavuelo[4]), int.Parse(datavuelo[3]), date);
                        listaVuelos.Add(vuelo);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file Info vueloes could not be read:");
                Console.WriteLine(e.Message);
                return;
            }

            //Leyendo usuarios

            try {
                using (StreamReader ifile = new StreamReader("usuarios.txt"))
                {
                    while (!ifile.EndOfStream)
                    {
                        string   uline  = ifile.ReadLine();
                        string[] du     = uline.Split('|');
                        int      indexV = int.Parse(du[0]);
                        //indice es igual a al primer campo de du
                        Usuario user = new Usuario(du[1], du[2], du[4], int.Parse(du[3]));

                        listaVuelos[indexV].userlist.Add(user);
                        listaVuelos[indexV].setAsientoTomado(int.Parse(du[3]));
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }


            //Leyendo Ciudades


            try
            {
                using (StreamReader ifile = new StreamReader("Ciudades.txt"))
                {
                    while (!ifile.EndOfStream)
                    {
                        string              cline   = ifile.ReadLine();
                        string[]            cu      = cline.Split('|');
                        List <AristaCiudad> aristas = new List <AristaCiudad>();

                        CiudadNodo city = new CiudadNodo(float.Parse(cu[0]), float.Parse(cu[1]), cu[2], aristas);

                        listaciudades.Add(city);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            //Leyendo Aristas



            try
            {
                using (StreamReader ifile = new StreamReader("Aristas.txt"))
                {
                    while (!ifile.EndOfStream)
                    {
                        string       aline  = ifile.ReadLine();
                        string[]     au     = aline.Split('|');
                        AristaCiudad arista = new AristaCiudad(float.Parse(au[1]), float.Parse(au[2]), au[0], au[3], int.Parse(au[4]), int.Parse(au[5]));
                        int          ind    = listaciudades.getcityIndex(au[0]);
                        listaciudades[ind].Aristas.Add(arista);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }



            Principal ventanaPrincipal = new Principal(ref listaVuelos, ref listaciudades);

            ventanaPrincipal.ShowDialog();
            //codigo para escribir
            //string lines = "First line.\r\nSecond line.\r\nThird line.";

            StreamWriter file  = new StreamWriter("infoVuelos.txt");
            StreamWriter file2 = new StreamWriter("usuarios.txt");

            int vindex = 0;

            foreach (Vuelo v in listaVuelos)
            {
                file.WriteLine(v.ToString('|'));

                foreach (Usuario u in v.userlist)
                {
                    file2.WriteLine(vindex.ToString() + '|' + u.ToString());
                }

                vindex++;
            }
            file.Close();
            file2.Close();


            StreamWriter filecity = new StreamWriter("Ciudades.txt");
            StreamWriter fileari  = new StreamWriter("Aristas.txt");

            foreach (CiudadNodo c in listaciudades)
            {
                filecity.WriteLine(c.X.ToString() + '|' + c.Y.ToString() + '|' + c.getName());

                foreach (AristaCiudad a in c.Aristas)
                {
                    fileari.WriteLine(c.getName() + '|' + a.ToString());
                }
            }

            filecity.Close();
            fileari.Close();


            Console.WriteLine("fin del programa");
        }
コード例 #7
0
 public DijkstraNode(CiudadNodo IdNodo, float peso)
 {
     AristaPeso  = 0;
     this.IdNodo = IdNodo;
     this.peso   = peso;
 }
コード例 #8
0
ファイル: GrafoVisual.cs プロジェクト: emagacus/FlightControl
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            var mouseEventArgs = e as MouseEventArgs;

            if (NewMarkerEnabled)
            {
                pictureBox1.Image = new Bitmap(pictureBox1.Image);
                g = Graphics.FromImage(pictureBox1.Image);
                g.DrawEllipse(pen1, mouseEventArgs.X, mouseEventArgs.Y, 10, 10);
                NewMarkerEnabled = false;

                List<AristaCiudad> aris = new List<AristaCiudad>();
                CiudadNodo city = new CiudadNodo(mouseEventArgs.X, mouseEventArgs.Y, name,aris);
                listaciudades.Add(city);

                this.Close();

            }
        }
コード例 #9
0
ファイル: GrafoVisual.cs プロジェクト: emagacus/FlightControl
        //
        //*****   DIJKSTRA
        //        ****          ***        ***        *   *     *****    *****     *****      *****        //
        //        *   *          *          *         *  *      *   *      *       *   *      *   *        //
        //        *    *         *          *         * *       *   *      *       *   *      *   *        //
        //        *     *        *          *         **        *          *       *****      *****        //
        //        *     *        *          *         **        *****      *       *  *       *   *        //
        //        *    *         *      *   *         * *           *      *       *   *      *   *        //
        //        *   *          *       *  *         *  *      *   *      *       *    *     *   *        //
        //        ****          ***       ***         *   *     *****      *       *    *     *   *        //
        CiudadNodo dijskUpdate(ref CiudadNodo nodoactual, ref List<DijkstraNode> caminos, ref string Definitivos)
        {
            DijkstraNode nuevo = new DijkstraNode();

            foreach (DijkstraNode d in caminos) { if (d.IdNodo.name == nodoactual.name) { nuevo.peso = d.peso; break; } }

            if(checkBoxCosto.Checked)
            {

            foreach (AristaCiudad a in nodoactual.Aristas)
            {

                foreach (DijkstraNode d in caminos)
                {
                    if (a.getDest() == d.IdNodo.name)
                    {

                        if ((a.getCosto() + nuevo.peso) < d.peso)
                        {

                            d.peso = a.getCosto() + nuevo.peso;
                                d.AristaPeso = a.getCosto();
                            d.procedencia = nodoactual;

                        }
                    }
                }

            }//fin foreach arista

            }
            else  ////***Tiempo

            {

                foreach (AristaCiudad a in nodoactual.Aristas)
                {

                    foreach (DijkstraNode d in caminos)
                    {
                        if (a.getDest() == d.IdNodo.name)
                        {

                            if ((a.getTiempo() + nuevo.peso) < d.peso)
                            {

                                d.peso = a.getTiempo() + nuevo.peso;
                                d.AristaPeso = a.getTiempo();
                                d.procedencia = nodoactual;

                            }
                        }
                    }

                }//fin foreach arista

            }

            caminos.Sort((x, y) => x.peso.CompareTo(y.peso));
            foreach (DijkstraNode d in caminos) { if (!Definitivos.Contains(d.IdNodo.name)) { nodoactual = d.IdNodo; break; } }
            Definitivos = Definitivos + nodoactual.name;

            ///***

            return nodoactual;
        }
コード例 #10
0
ファイル: GrafoVisual.cs プロジェクト: emagacus/FlightControl
        List<DijkstraNode> Dijkstra(CiudadNodo origen)
        {
            List<DijkstraNode> caminos = new List<DijkstraNode>();
            CiudadNodo nodoActual=origen;
            string Definitivos = "";
            int numDef=0;

            //Se crea el vector de caminos

            foreach (CiudadNodo c in listaciudades)
            {

                DijkstraNode nodo = new DijkstraNode(c, 1000000000);

                if (c.getName()==origen.getName())
                {
                    nodo.peso = 0;
                    nodo.procedencia = origen;
                }

                    caminos.Add(nodo);
            }

            //*** Se inicia con el origen;

             Definitivos = origen.getName();
             numDef++;

            //***

            while(numDef != listaciudades.Count)
            {

                dijskUpdate(ref nodoActual, ref caminos, ref Definitivos);
                numDef++;

            }

            return caminos;
        }