public override double GetArcCost(GenericNode N2) // Ajouter timesestimation: Fonction permettant d’estimer un temps élémentaire de déplacement entre deux points
        {
            NodeBateau NT = (NodeBateau)(N2);
            int        x2 = NT._x;
            int        y2 = NT._y;

            double distance = Math.Sqrt((_x - x2) * (_x - x2) + (_y - y2) * (_y - y2));

            if (distance > 10)
            {
                return(1000000);
            }
            double windspeed     = get_wind_speed((_x + x2) / 2.0, (_y + y2) / 2.0);
            double winddirection = get_wind_direction((_x + x2) / 2.0, (_y + y2) / 2.0);
            double boatspeed;
            double boatdirection = Math.Atan2(y2 - _y, x2 - _x) * 180 / Math.PI;

            // On ramène entre 0 et 360
            if (boatdirection < 0)
            {
                boatdirection = boatdirection + 360;
            }
            // calcul de la différence angulaire
            double alpha = Math.Abs(boatdirection - winddirection);

            // On se ramène à une différence entre 0 et 180 :
            if (alpha > 180)
            {
                alpha = 360 - alpha;
            }
            if (alpha <= 45)
            {
                /* (0.6 + 0.3α / 45) v_v */
                boatspeed = (0.6 + 0.3 * alpha / 45) * windspeed;
            }
            else if (alpha <= 90)
            {
                /*v_b=(0.9-0.2(α-45)/45) v_v */
                boatspeed = (0.9 - 0.2 * (alpha - 45) / 45) * windspeed;
            }
            else if (alpha < 150)
            {
                /* v_b=0.7(1-(α-90)/60) v_v */
                boatspeed = 0.7 * (1 - (alpha - 90) / 60) * windspeed;
            }
            else
            {
                return(1000000);
            }
            // estimation du temps de navigation entre p1 et p2
            return(distance / boatspeed);
        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            NodeBateau.cas = 'b';
            SearchTree g  = new SearchTree();
            NodeBateau N0 = new NodeBateau(100, 200);

            NodeBateau._xf = 200;
            NodeBateau._yf = 100;
            List <GenericNode> Lres = g.RechercheSolutionAEtoile(N0);

            if (Lres.Count == 0)
            {
                labelsolution.Text = "Pas de solution";
            }
            else
            {
                labelsolution.Text = "Une solution a été trouvée";
            }
            int      i        = 0;
            Pen      penwhite = new Pen(Color.White); // d’autres couleurs sont disponibles
            Graphics g1       = pictureBox1.CreateGraphics();

            foreach (GenericNode N in Lres)
            {
                listBox1.Items.Add(N);
                listBox1.Items.Add("G : " + N.GetGCost().ToString());
                if (i < Lres.Count - 1)
                {
                    NodeBateau NT = (NodeBateau)(N);

                    int x1 = NT.Get_x();
                    int y1 = NT.Get_y();

                    NodeBateau NT2 = (NodeBateau)(Lres[i + 1]);

                    int x2 = NT2.Get_x();
                    int y2 = NT2.Get_y();

                    g1.DrawLine(penwhite, new Point((int)x1, pictureBox1.Height - (int)y1),
                                new Point((int)x2, pictureBox1.Height - (int)y2));

                    i++;
                }
            }
            labelcountopen.Text   = "Nb noeuds des ouverts : " + g.CountInOpenList().ToString();
            labelcountclosed.Text = "Nb noeuds des fermés : " + g.CountInClosedList().ToString();
            g.GetSearchTree(treeView1);
        }
        public override bool IsEqual(GenericNode N2) // Cette fonction renvoie un booleen : permet de verifier si deux noeuds sont égaux
        {
            NodeBateau NT = (NodeBateau)(N2);        // Permet la conversion N2 qui est un Genericcode en NodeBateau

            return(NT._x == _x && NT._y == _y);      // Verifier si les x et y sont égaux, ça retourne true ou false
        }
Beispiel #4
0
        public override bool IsEqual(GenericNode N2) // Permet de verifier si deux noeuds sont égaux. ???
        {
            NodeBateau NT = (NodeBateau)(N2);        // Permet la conversion N2 qui est un Genericcode en NodeBateau, il force la conversion

            return(NT._x == _x && NT._y == _y);      // Verifier si les x et y sont égaux, ça retourne true ou false ce test d'égalité
        }
Beispiel #5
0
        private void CasBButton_Click_1(object sender, EventArgs e) // Cas B
        {
            NodeBateau.cas = 'b';
            pictureBox1.Refresh();                    // Actualise la picturebox
            SearchTree g  = new SearchTree();
            NodeBateau N0 = new NodeBateau(100, 200); //Entre en entrée les coordonnées(x et y) du noeud initial du bateau pour le Cas B

            NodeBateau._xf = 200;                     // Entre en entrée les coordonnées en abcscisse du noeud final que le bateau doit atteindre pour le Cas B
            NodeBateau._yf = 100;                     // Entre en entrée les coordonnées en abcscisse du noeud que le bateau doit atteindre pour le Cas B

            //Intialisation du chronomètre
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            Thread.Sleep(10);

            List <GenericNode> Lres = g.RechercheSolutionAEtoile(N0);



            if (Lres.Count == 0)
            {
                labelsolution.Text = "Pas de solution";
            }
            else
            {
                labelsolution.Text = "Une solution a été trouvée";

                // Affichage du chronomètre
                stopWatch.Stop();
                TimeSpan ts          = stopWatch.Elapsed;
                string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                     ts.Hours, ts.Minutes, ts.Seconds,
                                                     ts.Milliseconds / 10);
                ChronoBox.Text = elapsedTime;

                int      i        = 0;
                Pen      penwhite = new Pen(Color.White); ////Affichage du segment entre deux points
                Graphics g1       = pictureBox1.CreateGraphics();

                PasBox.Text = NodeBateau.pas.ToString(); // Affichage du nombre de pas

                foreach (GenericNode N in Lres)
                {
                    listBox1.Items.Add(N);


                    if (i < Lres.Count - 1)
                    {
                        NodeBateau NT = (NodeBateau)(N);

                        int x1 = NT.Get_x();
                        int y1 = NT.Get_y();

                        NodeBateau NT2 = (NodeBateau)(Lres[i + 1]);

                        int x2 = NT2.Get_x();
                        int y2 = NT2.Get_y();

                        g1.DrawLine(penwhite, new Point((int)x1, pictureBox1.Height - (int)y1),
                                    new Point((int)x2, pictureBox1.Height - (int)y2));

                        i++;
                    }
                }
                textTempsParcours.Text = Lres[Lres.Count - 1].GetGCost().ToString();// Affichage de G : le temps entre le nœud initial et le nœud final
                labelcountopen.Text    = "Nb noeuds des ouverts : " + g.CountInOpenList().ToString();
                labelcountclosed.Text  = "Nb noeuds des fermés : " + g.CountInClosedList().ToString();
                g.GetSearchTree(treeView1);
            }
        }