Пример #1
0
        private void Revenir_a_plateforme_livraison()
        {
            // le départ est l'endroit ou est resté le chariot
            Emplacement depart   = (Emplacement)chemin[chemin.Count() - 1];
            string      position = depart.GetX() + "." + depart.GetY();
            // colorer le bon bouton
            Button btn = (Button)this.Controls.Find(position, true)[0];

            btn.BackColor = Color.Blue;
            Program.entrepot.cell[depart.GetY(), depart.GetX()] = 0;
            // 2.trouver l'emplacement d'arrivée
            Emplacement arrivee = new Emplacement();

            // si le colis est au nord, alors le chariot doit se placer sur la case en dessus soit -1 dans la matrice
            arrivee.SetX(0);
            int    c = 0;
            double cout = 500, coutmin = 500;

            for (int k = 0; k < Program.entrepot.Get_largeur_entrepot(); k++)
            {
                if (Program.entrepot.cell[k, 0] != 2)
                {
                    arrivee.SetY(k);
                    nul    = new Graph(arrivee, depart);
                    chemin = nul.RechercheSolutionAEtoile();
                    if (chemin.Count > 0)
                    {
                        cout = chemin[chemin.Count() - 1].GetGCost();
                    }
                    if (cout < coutmin)
                    {
                        coutmin = cout;
                        c       = k;
                    }
                }
            }
            arrivee.SetY(c);

            // on fait appel à la fonction pour nous trouver
            nul    = new Graph(arrivee, depart);
            chemin = nul.RechercheSolutionAEtoile();
            // colorer le chemin de retour
            Deplacement_chariots();
            Program.entrepot.cell[c, 0] = 2;
            Nv_colis_BTN.Visible        = true;
            // on met le bouton du début en blanc
            btn.BackColor = Color.White;

            UnableChariots();
        }
Пример #2
0
 public override void CalculeHCost(Emplacement final)
 {
     // distance de Manhattan
     if (this.y == final.y)
     {
         this.HCost = HCost + (Math.Abs(x - final.x) + Math.Abs(y - final.y));
     }
     else if (this.x == final.x)
     {
         this.HCost = HCost + (Math.Abs(x - final.x) + Math.Abs(y - final.y)) + 9;
     }
     else
     {
         this.HCost = HCost + (Math.Abs(x - final.x) + Math.Abs(y - final.y)) + 6; //Le chariot se reoriente et il fait un virage
     }
 }
Пример #3
0
        private void Deplacement_chariots()
        {
            if (chemin.Count() > 0)
            {
                Final_LBL.Text = "Une solution a été trouvée";
                double cout = ((Emplacement)chemin[chemin.Count - 1]).GetGCost();
                Final_LBL.Text += " avec un cout de " + cout + " secondes";
            }
            else
            {
                Final_LBL.Text = "Pas de solution";
            }

            for (int k = 0; k < chemin.Count() - 1; k++)
            {
                if (k != chemin.Count() - 1)
                {
                    System.Threading.Thread.Sleep((int)chemin[k].GetArcCost(chemin[k + 1]) * 100);

                    // todo : ne pas supprimer le premier avec k
                    //On clean la position de depart
                    Emplacement ptsDepart   = (Emplacement)chemin[k];
                    string      positionDep = ptsDepart.GetX().ToString() + "." + ptsDepart.GetY().ToString();
                    Button      btn_3       = (Button)this.Controls.Find(positionDep, true)[0];
                    btn_3.Image     = null;
                    btn_3.BackColor = Color.Gold;
                    btn_3.Text      = null;
                    btn_3.Refresh();

                    //On colore la position d'arrivee
                    Emplacement ptsArrivee  = (Emplacement)chemin[k + 1];
                    string      positionArr = ptsArrivee.GetX().ToString() + "." + ptsArrivee.GetY().ToString();
                    Button      btn_4       = (Button)this.Controls.Find(positionArr, true)[0];
                    btn_4.Image = Image.FromFile("../../Images/" + ptsArrivee.Get_orientation() + ".png");
                    btn_4.Text  = Chariot_choisi.Get_cle_chariot().ToString();
                    btn_4.Refresh();
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Cette fonction survient après le clic de l'utilisateur sur le bouton "Valider". L'utilisateur vient de choisir les caractéristiques de son colis.
        /// Suite à cette validation, on vérifie l'emplacement du colis pour voir si cet emplacement est bien valide : que le colis est bien sur une étagère.
        /// Si les informations saisies ne sont pas valides comme : un emplacement hors des cases noires ou une hauteur supérieure à 10m, on informe l'utilisateur
        /// dans une message box de son erreur. Les paramètres du colis proposés par défaut donne bien sur une étagère.
        /// Si l'emplacement est correct, on calcule l'emplacement de fin du chariot en fonction des caractèristique du colis.
        /// Elle prend les paramètres habituels des gestionnnaires d'évènement et n'a pas de sortie.
        /// </summary>
        /// <entree>
        ///     <param name="sender"> informations sur le bouton cliqué </param>
        ///     <param name="e"> informations sur l'evenement </param>
        /// </entree>
        /// <sortie> aucune </sortie>
        private void Valider_BTN_Click(object sender, EventArgs e)
        {
            if (Est_un_colis(int.Parse(Colis_TB.Text), int.Parse(Colis_Localisation_TB.Text)) && int.Parse(Colis_Hauteur_TB.Text) < 11)
            {
                //1.l'emplacement du début
                Emplacement depart   = new Emplacement(Chariot_choisi._x, Chariot_choisi._y, Chariot_choisi._orientation, int.Parse(Colis_Hauteur_TB.Text));
                string      position = Chariot_choisi._x + "." + Chariot_choisi._y;
                Program.entrepot.cell[Chariot_choisi._y, Chariot_choisi._x] = 0;
                // colorer le bon bouton
                Button btn = (Button)this.Controls.Find(position, true)[0];
                btn.BackColor = Color.Blue;

                // quand la personne a choisi les caractéristiques de son colis
                string orientation = "";
                try { orientation = Orientation_LIST.SelectedItem.ToString(); }
                catch { orientation = "Nord"; }
                tab_colis[nb_colis] = new Colis(int.Parse(Colis_TB.Text), int.Parse(Colis_Localisation_TB.Text), int.Parse(Colis_Hauteur_TB.Text), orientation);

                // colorer le colis
                string position_2 = int.Parse(Colis_TB.Text) + "." + int.Parse(Colis_Localisation_TB.Text);
                Button btn_2      = (Button)this.Controls.Find(position_2, true)[0];
                btn_2.BackColor = Color.Green;
                if (orientation == "Nord")
                {
                    btn_2.Text = "N";
                }
                else
                {
                    btn_2.Text = "S";
                }
                btn_2.Refresh();

                // 2.trouver l'emplacement d'arrivée
                // en fonction de l'orientation du colis, l'emplacement n'est pas le même
                Emplacement arrivee = new Emplacement();

                // si le colis est au nord, alors le chariot doit se placer sur la case en dessus soit -1 dans la matrice
                if (tab_colis[nb_colis]._orientation == "Nord")
                {
                    arrivee.SetY(tab_colis[nb_colis]._y - 1);
                }
                else
                {
                    arrivee.SetY(tab_colis[nb_colis]._y + 1);
                }
                // la position en x ne change pas
                arrivee.SetX(tab_colis[nb_colis]._x);

                // on fait appel à la fonction pour nous trouver
                nul    = new Graph(arrivee, depart);
                chemin = nul.RechercheSolutionAEtoile();

                // on enleve les controles lors du remplissage du colis
                Valider_BTN.Visible           = false;
                Orientation_LBL.Visible       = false;
                Orientation_LIST.Visible      = false;
                Colis_hauteur_LBL.Visible     = false;
                Colis_Hauteur_TB.Visible      = false;
                Colis_Localisation_TB.Visible = false;
                Colis_Position_LBL.Visible    = false;
                Colis_Position_y_LBL.Visible  = false;
                Colis_TB.Visible    = false;
                Details_BTN.Visible = true;

                Consigne_LBL.Text = "Etape 5 : Evaluer le chemin";
                Final_LBL.Visible = true;
                // si le chemin est null, c'est qu'il n'y a pas de solution pour que le colis puise être pris par le chariot
                if (chemin.Count == 0)
                {
                    Final_LBL.Text       = "Pas de solution possible pour ce chemin";
                    Final_LBL.Visible    = true;
                    Nv_colis_BTN.Visible = true;
                }
                else
                {
                    Deplacement_chariots();
                    //  le bouton du début est en bleu foncé alors que le chariot est en bleu clair
                    btn.BackColor = Color.Blue;
                    double cout = ((Emplacement)chemin[chemin.Count - 1]).GetGCost();
                }
                // s'il n'y a pas de solution, on n'affiche pas le calcul du retour à la plateforme.
                if (chemin.Count > 0)
                {
                    Depot_BTN.Visible = true;
                }

                UnableChariots();
            }
            else
            {
                // si l'utilisateur a mal choisi l'emplacement de son colis
                string       message = "La position du colis ne correspond pas à la disposition de l'entrepot : il doit être sur une étagère et à une hauteur inférieure ou égal à 10.";
                string       caption = "Error Detected in Input";
                DialogResult result  = MessageBox.Show(message, caption);
            }
        }
Пример #5
0
        public Affichage(int nb_chariots, int longueur, int largeur)
        {
            InitializeComponent();

            Emplacement initialisation = new Emplacement(0, 0, "Nord", 0);

            nul = new Graph(initialisation, initialisation);
            // la liste des chariots
            Program.tab_chariot = new Chariot[nb_chariots];
            //   Program.tab_chariot[0].Remise_a_zero();
            tab_colis = new Colis[nb_chariots];

            Program.entrepot   = new Entrepot(longueur, largeur);
            Consigne_LBL.Text += "\n Etape 1 : Placer les chariots";
            // la liste des chariots
            Program.tab_chariot = new Chariot[nb_chariots];

            int ButtonWidth  = 20;
            int ButtonHeight = 20;
            int Distance     = 0;
            int start_x      = 0;
            int start_y      = 0;

            //for (int i = 0; i < entrepot.cell.GetLength(1); i++)

            for (int i = 0; i < Program.entrepot.cell.GetLength(0); i++)
            {
                for (int j = 0; j < Program.entrepot.cell.GetLength(1); j++)
                {
                    if (Program.entrepot.cell[j, i] == -1)
                    {
                        // Position du controle
                        Button tmpButton = new Button();
                        tmpButton.Top    = start_x + (j * ButtonHeight + Distance);
                        tmpButton.Left   = start_y + (i * ButtonWidth + Distance);
                        tmpButton.Width  = ButtonWidth;
                        tmpButton.Height = ButtonHeight;
                        tmpButton.Name   = i.ToString() + "." + j.ToString();

                        //Apparence du controle
                        tmpButton.BackColor = Color.Black;
                        tmpButton.FlatStyle = FlatStyle.Flat;
                        tmpButton.Enabled   = false;

                        //Evenements associés au controle
                        tmpButton.Click += new EventHandler(tmpButton_Click);

                        //Ecriture du controle
                        this.Controls.Add(tmpButton);
                    }
                    else
                    {
                        // Position du controle
                        Button tmpButton = new Button();
                        tmpButton.Top    = start_x + (j * ButtonHeight + Distance);
                        tmpButton.Left   = start_y + (i * ButtonWidth + Distance);
                        tmpButton.Width  = ButtonWidth;
                        tmpButton.Height = ButtonHeight;
                        tmpButton.Name   = i.ToString() + "." + j.ToString();

                        //Apparence du controle
                        tmpButton.BackColor = Color.White;
                        tmpButton.FlatStyle = FlatStyle.Flat;

                        //Evenements associés au controle
                        tmpButton.Click += new EventHandler(tmpButton_Click);

                        //Ecriture du controle
                        this.Controls.Add(tmpButton);
                    }
                }
            }

            // on créer les possibilités pour placer un colis
            Choisir_colonne();
            Choisir_ligne();
        }
Пример #6
0
        private void Deplacement_chariot(int k)
        {
            //1. on calcule leur trajet
            // la position de départ : leur position actuelle
            Emplacement ptsDepart = new Emplacement(Program.tab_chariot[k]._x, Program.tab_chariot[k]._y, Program.tab_chariot[k]._orientation, Program.tab_chariot[k]._hauteur);

            // la position de fin : calculé via le colis
            // quand la personne a choisi les caractéristiques de son colis
            Emplacement arrivee = new Emplacement();

            // si le colis est au nord, alors le chariot doit se placer sur la case en dessus soit -1 dans la matrice
            if (Program.tab_chariot[k].chercher_un_colis)
            {
                #region Si  le chariot a pris son colis et doit revenir à  la plateforme
                // le chariot doit revenir à sa plateforme
                arrivee.SetX(0);
                int    c = 0;
                double cout = 600, coutmin = 500;
                for (int kk = 0; kk < Program.entrepot.Get_largeur_entrepot(); kk++)
                {
                    if (Program.entrepot.cell[kk, 0] != 2)
                    {
                        arrivee.SetY(kk);
                        nul    = new Graph(arrivee, ptsDepart);
                        chemin = nul.RechercheSolutionAEtoile();
                        if (chemin.Count > 0)
                        {
                            cout = chemin[chemin.Count() - 1].GetGCost();
                        }
                        if (cout < coutmin)
                        {
                            coutmin = cout;
                            c       = kk;
                        }
                    }
                }
                arrivee.SetY(c);
                #endregion
            }
            else
            {
                if (tab_colis[k]._orientation == "Nord")
                {
                    arrivee.SetY(tab_colis[k]._y - 1);
                }
                else
                {
                    arrivee.SetY(tab_colis[k]._y + 1);
                }
                // la position en x ne change pas
                arrivee.SetX(tab_colis[k]._x);
            }

            Graph trouver = new Graph(arrivee, ptsDepart);
            chemin = trouver.RechercheSolutionAEtoile();

            // CHOIX 1 : quand le chariot est à l'emplacement final pour prendre le colis
            if (Program.tab_chariot[k]._x == tab_colis[k]._x && (Program.tab_chariot[k]._y - 1 == tab_colis[k]._y || Program.tab_chariot[k]._y + 1 == tab_colis[k]._y) && !Program.tab_chariot[k].chercher_un_colis)
            {
                #region Prendre le colis
                // on est arrivé au bout du chemin 1
                Program.tab_chariot[k].chercher_un_colis = true;
                Program.tab_chariot[k].depot             = true;
                Program.tab_chariot[k].depot_temps       = 0;

                string positionArr = tab_colis[k]._x + "." + tab_colis[k]._y;
                Button btn_7       = (Button)this.Controls.Find(positionArr, true)[0];
                //   btn_4.Image = Image.FromFile("../../Images/" + arrivee.Get_orientation() + ".png");
                btn_7.BackColor = Color.Purple;
                btn_7.Text      = "X";
                btn_7.Refresh();

                // pour le chariot qui récupère le colis
                string position = Program.tab_chariot[k]._x + "." + Program.tab_chariot[k]._y;
                Button btn_6    = (Button)this.Controls.Find(position, true)[0];
                //   btn_4.Image = Image.FromFile("../../Images/" + arrivee.Get_orientation() + ".png");
                btn_6.BackColor = Color.Yellow;
                btn_6.Text      = "*";
                btn_6.Refresh();
                #endregion
            }
            // CHOIX 2 : quand le chariot est revenu à la livraison
            else if (Program.tab_chariot[k].chercher_un_colis && Program.tab_chariot[k]._x == 0)
            {
                // le chariot a donc pris son colis et est revenu sur la plateforme de livraison
                Program.tab_chariot[k].enLivraison = true;
                // pour le chariot qui récupère le colis
                string position = Program.tab_chariot[k]._x + "." + Program.tab_chariot[k]._y;
                Button btn_5    = (Button)this.Controls.Find(position, true)[0];
                btn_5.BackColor = Color.Orange;
                btn_5.Text      = "§";
                btn_5.Refresh();
            }
            // CHOIX 3 : quand il se déplace classiquement
            else if (chemin.Count > 1)
            {
                #region Deplacement d'un chariot vers une autre case
                //On clean la position de depart
                string positionDep = ptsDepart.GetX().ToString() + "." + ptsDepart.GetY().ToString();
                Button btn_3       = (Button)this.Controls.Find(positionDep, true)[0];
                btn_3.BackColor = Color.White;
                btn_3.Text      = "";
                btn_3.Refresh();

                //On colore la position d'arrivee
                string positionArr = ((Emplacement)chemin[1]).GetX().ToString() + "." + ((Emplacement)chemin[1]).GetY().ToString();
                Button btn_4       = (Button)this.Controls.Find(positionArr, true)[0];

                // si la nouvelle case necessite un changement de direction
                if (ptsDepart.GetArcCost((Emplacement)chemin[1]) == 4 && Program.tab_chariot[k].rotation_temps != 0)
                {
                    Program.tab_chariot[k].rotation       = true;
                    Program.tab_chariot[k].rotation_temps = 0;
                    btn_3.BackColor = Color.Pink;
                    btn_3.Text      = Program.tab_chariot[k].Get_cle_chariot().ToString();
                    btn_3.Refresh();
                    Program.tab_chariot[k]._orientation = ((Emplacement)chemin[1]).Get_orientation();
                }
                else
                {
                    if (Program.tab_chariot[k].chercher_un_colis)
                    {
                        btn_4.BackColor = Color.Blue;
                    }
                    else
                    {
                        btn_4.BackColor = Color.Red;
                    }
                    btn_4.Text = Program.tab_chariot[k].Get_cle_chariot().ToString();
                    btn_4.Refresh();

                    // on enregistre les changements
                    Program.entrepot.cell[Program.tab_chariot[k]._y, Program.tab_chariot[k]._x] = 0;
                    Program.tab_chariot[k]._x           = ((Emplacement)chemin[1]).GetX();
                    Program.tab_chariot[k]._y           = ((Emplacement)chemin[1]).GetY();
                    Program.tab_chariot[k]._orientation = ((Emplacement)chemin[1]).Get_orientation();
                    Program.tab_chariot[k]._hauteur     = 0;
                    Program.entrepot.cell[((Emplacement)chemin[1]).GetY(), ((Emplacement)chemin[1]).GetX()] = 2;
                }
                #endregion
            }
        }
Пример #7
0
        public Question_3(int nb_chariots, int longueur, int largeur)
        {
            InitializeComponent();
            repartition = new int[nb_chariots][];
            Emplacement initialisation = new Emplacement(0, 0, "Nord", 0);

            // il faut donner une valeur par défaut à nul car sinon VS nous dit
            // qu'il ne prendra aucune valeur car il n'est pas instancié au début
            nul = new Graph(initialisation, initialisation);
            // la liste des chariots
            Program.tab_chariot = new Chariot[nb_chariots];
            tab_colis           = new Colis[nb_chariots];

            Program.entrepot  = new Entrepot(longueur, largeur);
            Consigne_LBL.Text = " Etape 1 : Cliquer sur le chariot prioritaire";
            // la liste des chariots
            Program.tab_chariot = new Chariot[nb_chariots];

            int ButtonWidth  = 20;
            int ButtonHeight = 20;
            int Distance     = 0;
            int start_x      = 0;
            int start_y      = 0;

            for (int i = 0; i < Program.entrepot.cell.GetLength(0); i++)
            {
                for (int j = 0; j < Program.entrepot.cell.GetLength(1); j++)
                {
                    if (Program.entrepot.cell[j, i] == -1)
                    {
                        // Position du controle
                        Button tmpButton = new Button();
                        tmpButton.Top    = start_x + (j * ButtonHeight + Distance);
                        tmpButton.Left   = start_y + (i * ButtonWidth + Distance);
                        tmpButton.Width  = ButtonWidth;
                        tmpButton.Height = ButtonHeight;
                        tmpButton.Name   = i.ToString() + "." + j.ToString();

                        //Apparence du controle
                        tmpButton.BackColor = Color.Black;
                        tmpButton.FlatStyle = FlatStyle.Flat;
                        tmpButton.Enabled   = true;

                        //Evenements associés au controle
                        tmpButton.Click += new EventHandler(tmpButton_Click);

                        //Ecriture du controle
                        this.Controls.Add(tmpButton);
                    }
                    else
                    {
                        // Position du controle
                        Button tmpButton = new Button();
                        tmpButton.Top    = start_x + (j * ButtonHeight + Distance);
                        tmpButton.Left   = start_y + (i * ButtonWidth + Distance);
                        tmpButton.Width  = ButtonWidth;
                        tmpButton.Height = ButtonHeight;
                        tmpButton.Name   = i.ToString() + "." + j.ToString();

                        //Apparence du controle
                        tmpButton.BackColor = Color.White;
                        tmpButton.FlatStyle = FlatStyle.Flat;
                        tmpButton.Enabled   = true;
                        //Evenements associés au controle
                        tmpButton.Click += new EventHandler(tmpButton_Click);
                        //Ecriture du controle
                        this.Controls.Add(tmpButton);
                    }
                }
            }
            // tous les chariots doivent être placés sur la colonne 1
            Random rdn = new Random();

            // les chariots ne doivent pas se supperposer
            for (int j = 0; j < Program.tab_chariot.Length; j++)
            {
                Program.tab_chariot[j] = new Chariot(0, j, "Est", 0);
                // un chariot est prêt à l'emploi donc orienté à l'est dès le début
                string positionDep = Program.tab_chariot[j]._x.ToString() + "." + Program.tab_chariot[j]._y.ToString();
                Button btn         = (Button)this.Controls.Find(positionDep, true)[0];
                btn.Text      = "" + Program.tab_chariot[j].Get_cle_chariot();
                btn.BackColor = Color.Silver;
                btn.Enabled   = true;
                btn.Refresh();
                // on met le nouveau chariot dans le tableau
                Program.entrepot.cell[j, 0] = 2;
            }

            // on remplit tous les colis à aller chercher
            for (int k = 0; k < tab_colis.Length; k++)
            {
                tab_colis[k] = Faire_colis(rdn, k);
                string position = tab_colis[k]._x + "." + tab_colis[k]._y;
                Button btn      = (Button)this.Controls.Find(position, true)[0];
                btn.BackColor = Color.Green;
                btn.Enabled   = true;
                // dans l'orientation : on prend la premiere lettre de l'orientation du colis donc N pour Nord et S pour Sud
                // on prend donc la premiere lettre donc la lettre à l'indice 0 sur une durée de 1 lettre
                btn.Text = tab_colis[k]._orientation.Substring(0, 1);
                btn.Refresh();
            }
        }
Пример #8
0
 public override bool EndState(Emplacement final)
 {
     return(this.x == final.x && this.y == final.y);
 }
Пример #9
0
        //Methodes
        public override bool IsEqual(GenericNode N2)
        {
            Emplacement E1 = (Emplacement)(N2);

            return(E1.x == this.x && E1.y == this.y && E1.orientation == this.orientation);
        }
 public override void CalculeHCost(Emplacement final)
 {
 }
 public override bool EndState(Emplacement final)
 {
     return(this.x == final.GetX() && this.y == final.GetY());
 }
Пример #12
0
 //Constructeur de Graph a partir du tableau de l'entrepot
 public Graph(Emplacement xF, Emplacement d)
 {
     depart      = d;
     destination = xF;
 }
Пример #13
0
 // a cause de la duplication de la classe Emplacement : redéfinition : validé par encadrant
 public abstract void CalculeHCost(Emplacement final);
Пример #14
0
 // a cause de la duplication de la classe Emplacement : redéfinition : validé par encadrant
 public abstract bool EndState(Emplacement final);