示例#1
0
 public Dijkstra(string nomPremier, string nomDernier)
 {
     Premier         = new Parti02.Point(nomPremier);
     Dernier         = new Parti02.Point(nomDernier);
     Graphe          = new List <Point>();
     Ouvert          = new List <Point>();
     Ferme           = new List <Point>();
     CheminPlusCourt = new List <Point>();
     ListeO          = new List <string>();
     ListeF          = new List <string>();
     LectureTxt();
     Nombre = Rechercher();
 }
示例#2
0
        public void LectureTxt()
        {
            StreamReader monStreamReader = new StreamReader("graphe1.txt");

            // Lecture du fichier avec un while, évidemment !
            // 1ère ligne : "nombre de noeuds du graphe
            string ligne = monStreamReader.ReadLine();
            int    i     = 0;

            while (ligne[i] != ':')
            {
                i++;
            }
            string strnbnoeuds = "";

            i++; // On dépasse le ":"
            while (ligne[i] == ' ')
            {
                i++;                     // on saute les blancs éventuels
            }
            while (i < ligne.Length)
            {
                strnbnoeuds = strnbnoeuds + ligne[i];
                i++;
            }


            // Ensuite on a ls tructure suivante :
            //  arc : n°noeud départ    n°noeud arrivée  valeur
            //  exemple 4 :
            ligne = monStreamReader.ReadLine();
            while (ligne != null)
            {
                i = 0;
                while (ligne[i] != ':')
                {
                    i++;
                }
                i++; // on passe le :
                while (ligne[i] == ' ')
                {
                    i++;                     // on saute les blancs éventuels
                }
                string N1 = "";
                while (ligne[i] != ' ')
                {
                    N1 = N1 + ligne[i];
                    i++;
                }
                if (!EstPresent(N1))
                {
                    CreerPoint(N1);
                }
                // On saute les blancs éventuels
                while (ligne[i] == ' ')
                {
                    i++;
                }
                string N2 = "";
                while (ligne[i] != ' ')
                {
                    N2 = N2 + ligne[i];
                    i++;
                }
                if (!EstPresent(N2))
                {
                    CreerPoint(N2);
                }
                // On saute les blancs éventuels
                while (ligne[i] == ' ')
                {
                    i++;
                }
                string strVal = "";
                while ((i < ligne.Length) && (ligne[i] != ' '))
                {
                    strVal = strVal + ligne[i];
                    i++;
                }
                int   val = int.Parse(strVal);
                Point n1  = new Parti02.Point("");
                Point n2  = new Parti02.Point("");
                foreach (Point p in Graphe)
                {
                    if (p.Nom == N1)
                    {
                        n1 = p;
                    }
                    else if (p.Nom == N2)
                    {
                        n2 = p;
                    }
                }
                n1.AjouterPoint(n2, val);
                n2.AjouterPoint(n1, val);
                ligne = monStreamReader.ReadLine();
            }
            // Fermeture du StreamReader (obligatoire)
            monStreamReader.Close();
            foreach (Point p in Graphe)
            {
                if (p.Nom == Premier.Nom)
                {
                    Premier = p;
                }
                else if (p.Nom == Dernier.Nom)
                {
                    Dernier = p;
                }
                p.EstCulDeSac();
            }
        }