コード例 #1
0
        public override double GetArcCost(GenericNode N2)
        {
            //Permet d'obtenir le cout de l'arc entre 2 noeuds
            BoatNode N2bis      = (BoatNode)N2;
            double   valGCostN2 = time_estimation(x, y, N2bis.x, N2bis.y); //On calcule le cout

            return(valGCostN2);
        }
コード例 #2
0
        public override bool IsEqual(GenericNode N2)
        {
            BoatNode N2bis = (BoatNode)N2;

            return(x == N2bis.x && y == N2bis.y);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: motheguy/navigationIA
        private async void button1_Click(object sender, EventArgs e)
        {
            //Quand l'utilisateur appuie sur le bouton démarrer, le code se lance
            var watch = System.Diagnostics.Stopwatch.StartNew();

            //On récupère les valeurs saisies
            Xi = (int)numericUpDownXi.Value;
            Yi = (int)numericUpDownYi.Value;

            Xf = (int)numericUpDownXf.Value;
            Yf = (int)numericUpDownYf.Value;
            if (radioButtonB.Checked)
            {
                cas = radioButtonB.Text[0];
            }
            else if (radioButtonC.Checked)
            {
                cas = radioButtonC.Text[0];
            }
            else
            {
                cas = radioButtonA.Text[0]; // si = a ou non défini
            }
            textBoxResult.Text = "Type de vent choisi : " + cas + "";
            await Task.Delay(20);

            SearchTree g = new SearchTree();

            //On crée le point de départ
            BoatNode N0 = new BoatNode(Xi, Yi);

            //On crée le point d'arrivée
            BoatNode Nf = new BoatNode(Xf, Yf);

            //On lance la recherche du meilleur chemin
            List <GenericNode> solution = new List <GenericNode>(); //initialisation pour pouvoir refaire des calculs dans le programme

            solution = g.RechercheSolutionAEtoile(N0);

            if (solution.Count == 0)//il n'y a pas de solution
            {
                textBoxResult.Text = "Pas de solution";
            }
            else
            {
                textBoxResult.Text = "Une solution a été trouvée";
                // Petite animation
                Pen penWhite = new Pen(Color.White);
                for (int i = 0; i < solution.Count - 2; i++)
                {
                    Bitmap   bg  = pictureBoxOcean.Image as Bitmap;
                    Graphics gph = Graphics.FromImage(bg);
                    gph.DrawLine(penWhite, new Point((int)((BoatNode)solution[i]).x, pictureBoxOcean.Height - (int)((BoatNode)solution[i]).y), new Point((int)((BoatNode)solution[i + 1]).x, pictureBoxOcean.Height - (int)((BoatNode)solution[i + 1]).y));
                    pictureBoxOcean.Image = bg;
                    await Task.Delay(200);
                }
                int somme = g.CountInOpenList() + g.CountInClosedList();
                textBoxNbSolution.Text = solution.Count().ToString();
                textBoxSomme.Text      = somme.ToString() + "\nO:" + g.CountInOpenList().ToString() + "\nF:" + g.CountInClosedList().ToString();
                double time = 0;

                for (int i = 0; i < solution.Count - 1; i++)
                {
                    BoatNode nodeIni     = (BoatNode)solution[i];
                    BoatNode nodeArrival = (BoatNode)solution[i + 1];
                    time += nodeIni.time_estimation(nodeIni.x, nodeIni.y, nodeArrival.x, nodeArrival.y);
                }

                textBoxTime.Text = Math.Round(time, 2, MidpointRounding.ToEven).ToString() + "h";
            }
        }