Exemple #1
0
        public override List <GenericNode> GetListSucc()
        {
            List <GenericNode> lsucc = new List <GenericNode>();

            for (int i = 0; i < FormDijkstra.nbnodes; i++)
            {
                if (FormDijkstra.matrice[numero, i] != -1)
                {
                    Node2 newnode2 = new Node2();
                    newnode2.numero = i;
                    lsucc.Add(newnode2);
                }
            }
            return(lsucc);
        }
Exemple #2
0
 public FormArbre(Controller c, ListBox precedentResult, SearchTree g, Node2 N0, double[,] matrice)
 {
     InitializeComponent();
     noeudInitial = FormDijkstra.numinitial;
     noeudFinal   = FormDijkstra.numfinal;
     FormDijkstra.numfinal--;
     textBoxInitialNode.Text = noeudInitial + "";
     textBoxFinalNode.Text   = "" + noeudFinal;
     this.Controller         = c;
     foreach (var l in precedentResult.Items)
     {
         listBox1.Items.Add(l);
     }
     listBox1 = precedentResult;
     this.g   = g;
     g.GetSearchTree(treeView1, true);
 }
        public FormDijkstra(Controller c)
        {
            Controller = c;
            InitializeComponent();

            pictureBox1.Image    = Image.FromFile("Images/Partie2_Dijkstra.PNG");
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
            try
            {
                StreamReader monStreamReader = new StreamReader("dijkstra.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++;
                }
                nbnodes = Convert.ToInt32(strnbnoeuds);

                Random rand      = new Random();
                int    startNode = rand.Next(0, nbnodes / 2);
                int    endNode   = rand.Next((nbnodes / 2) + 2, nbnodes);
                textBoxStartNode.Text = startNode + "";
                textBoxEndNode.Text   = endNode + "";


                matrice = new double[nbnodes, nbnodes];
                for (i = 0; i < nbnodes; i++)
                {
                    for (int j = 0; j < nbnodes; j++)
                    {
                        matrice[i, j] = -1;
                    }
                }

                // 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 strN1 = "";
                    while (ligne[i] != ' ')
                    {
                        strN1 = strN1 + ligne[i];
                        i++;
                    }
                    int N1 = Convert.ToInt32(strN1);

                    // On saute les blancs éventuels
                    while (ligne[i] == ' ')
                    {
                        i++;
                    }
                    string strN2 = "";
                    while (ligne[i] != ' ')
                    {
                        strN2 = strN2 + ligne[i];
                        i++;
                    }
                    int N2 = Convert.ToInt32(strN2);

                    // On saute les blancs éventuels
                    while (ligne[i] == ' ')
                    {
                        i++;
                    }
                    string strVal = "";
                    while ((i < ligne.Length) && (ligne[i] != ' '))
                    {
                        strVal = strVal + ligne[i];
                        i++;
                    }
                    double val = Convert.ToDouble(strVal);

                    matrice[N1, N2] = val;
                    matrice[N2, N1] = val;
                    listBoxgraphe.Items.Add(Convert.ToString(N1)
                                            + "--->" + Convert.ToString(N2)
                                            + "   : " + Convert.ToString(matrice[N1, N2]));

                    ligne = monStreamReader.ReadLine();
                }
                // Fermeture du StreamReader (obligatoire)
                monStreamReader.Close();
                numinitial = Convert.ToInt32(textBoxStartNode.Text);
                numfinal   = Convert.ToInt32(textBoxEndNode.Text);
                g          = new SearchTree();
                Node2 N0 = new Node2();
                N0.numero             = numinitial;
                textBoxFermes.Text    = "";
                textBoxOuverts.Text   = "" + numinitial;
                textBoxRepFerme.Text  = "";
                textBoxRepOuvert.Text = "" + numinitial;
                N = g.InitialiserSolution(N0);
            }
            catch (Exception exp)
            {
                MessageBox.Show("Erreur lors du chargement du fichier 'dijkstra.txt'.\n Erreur :" + exp.Message);
            }
        }
Exemple #4
0
        public override double GetArcCost(GenericNode N2)
        {
            Node2 N2bis = (Node2)N2;

            return(FormDijkstra.matrice[numero, N2bis.numero]);
        }
Exemple #5
0
        // Méthodes abstrates, donc à surcharger obligatoirement avec override dans une classe fille
        public override bool IsEqual(GenericNode N2)
        {
            Node2 N2bis = (Node2)N2;

            return(numero == N2bis.numero);
        }