Exemple #1
0
        public List<OneItem> MainModelling(int k1, int k2)
        {
            int i;
            int CurrentPlace = -1;
            int CurrentCar = 0;
            float OldTime;
            float OldCarTime;
            float ServiceTime;
            float TimeToNext;
            CurrentShop = 0;
            OneItem Item = new OneItem(8);
            Car CarFromQuery = new Car();
            ResetCars();
            ResetShops();
            Plant = new BreadPlant();

            List<OneItem> ModellingResult = new List<OneItem>();

            for (i = 0; i < k1; i++)
            {
                SearchCurrenrEvent(ref CurrentPlace, ref CurrentCar);
            Plant:
                if (CurrentPlace == 0)
                {
                    if (Plant.t <= Cars[CurrentCar].t[0])
                    {

                        if (Plant.Query.Count == 0)
                        {

                            OldTime = Plant.t;
                            Plant.t = Cars[CurrentCar].t[0];
                            ServiceTime = Normal(CurM, CurS);
                            Plant.t += ServiceTime;
                            OldCarTime = Cars[CurrentCar].t[0];
                            Cars[CurrentCar].t[0] += ServiceTime;
                            Cars[CurrentCar].ShopCount = ModellingFullGroupEvent(ArrayP) + 1;
                            Cars[CurrentCar].ShopNumber = CurrentShop;
                            NextShop();
                            if (Cars[CurrentCar].ShopCount == 2)
                            {
                                NextShop();
                            }
                            TimeToNext = Exponent(30);
                            Cars[CurrentCar].t[1] = Cars[CurrentCar].t[0] + TimeToNext;
                            Cars[CurrentCar].t[0] = -1;

                            Item = new OneItem(8);

                            Item.strings[0] = (Cars[CurrentCar].Number + 1).ToString();
                            Item.strings[1] = "хлебозавод";
                            Item.strings[2] = String.Format("{0:0.00}", OldCarTime);
                            Item.strings[3] = String.Format("{0:0.00}", OldTime);
                            Item.strings[4] = String.Format("{0:0.00}", ServiceTime);
                            Item.strings[5] = String.Format("{0:0.00}", Plant.t);
                            Item.strings[6] = String.Format("{0:0.00}", TimeToNext);
                            Item.strings[7] = "Отправлен в магазин №" + (Cars[CurrentCar].ShopNumber + 1).ToString();
                            if (Cars[CurrentCar].ShopCount == 2)
                            {
                                if (Cars[CurrentCar].ShopNumber == Shops.Count - 1)
                                {
                                    Item.strings[7] += " и магазин №1";
                                }
                                else
                                {
                                    Item.strings[7] += " и магазин №" + (Cars[CurrentCar].ShopNumber + 2).ToString();
                                }
                            }
                            ModellingResult.Add(Item);
                        }
                        else
                        {

                            CarFromQuery = Plant.Query[0];
                            Plant.Query.RemoveAt(0);
                            Cars[CarFromQuery.Number].InQuery = false;
                            OldTime = Plant.t;
                            ServiceTime = Normal(CurM, CurS);
                            Plant.t += ServiceTime;
                            OldCarTime = Cars[CarFromQuery.Number].t[0];
                            Cars[CarFromQuery.Number].t[0] = Plant.t + ServiceTime;
                            Cars[CarFromQuery.Number].ShopCount = ModellingFullGroupEvent(ArrayP) + 1;
                            Cars[CarFromQuery.Number].ShopNumber = CurrentShop;
                            NextShop();
                            if (Cars[CarFromQuery.Number].ShopCount == 2)
                            {
                                NextShop();
                            }
                            TimeToNext = Exponent(30);
                            Cars[CarFromQuery.Number].t[1] = Cars[CarFromQuery.Number].t[0] + TimeToNext;
                            Cars[CarFromQuery.Number].t[0] = -1;
                            Item = new OneItem(8);
                            Item.strings[0] = (Cars[CarFromQuery.Number].Number + 1).ToString();
                            Item.strings[1] = "хлебозавод";
                            Item.strings[2] = String.Format("{0:0.00}", OldCarTime);
                            Item.strings[3] = String.Format("{0:0.00}", OldTime);
                            Item.strings[4] = String.Format("{0:0.00}", ServiceTime);
                            Item.strings[5] = String.Format("{0:0.00}", Plant.t);
                            Item.strings[6] = String.Format("{0:0.00}", TimeToNext);
                            Item.strings[7] = "Извлечен из очереди. Отправлен в магазин            №" + (Cars[CarFromQuery.Number].ShopNumber + 1).ToString();
                            if (Cars[CarFromQuery.Number].ShopCount == 2)
                            {
                                if (Cars[CarFromQuery.Number].ShopNumber == Shops.Count - 1)
                                {
                                    Item.strings[7] += " и магазин №1";
                                }
                                else
                                {
                                    Item.strings[7] += " и магазин №" + (Cars[CarFromQuery.Number].ShopNumber + 2).ToString();
                                }

                            }
                            ModellingResult.Add(Item);
                            i++;
                            goto Plant;
                        }
                    }
                    else
                    {
                        Plant.Query.Add(Cars[CurrentCar]);
                        Cars[CurrentCar].InQuery = true;

                        Item = new OneItem(8);

                        Item.strings[0] = (Cars[CurrentCar].Number + 1).ToString();
                        Item.strings[1] = "хлебозавод";
                        Item.strings[2] = String.Format("{0:0.00}", Cars[CurrentCar].t[0]);
                        Item.strings[3] = String.Format("{0:0.00}", Plant.t);
                        Item.strings[4] = String.Format("---");
                        Item.strings[5] = String.Format("---");
                        Item.strings[6] = String.Format("---");
                        Item.strings[7] = "Добавлен в очередь";
                        ModellingResult.Add(Item);
                    }
                }

                else
                {
                Shops:
                    if (Shops[Cars[CurrentCar].ShopNumber].t <= Cars[CurrentCar].t[1])
                    {
                        if (Shops[Cars[CurrentCar].ShopNumber].Query.Count == 0)
                        {

                            OldTime = Shops[Cars[CurrentCar].ShopNumber].t;
                            Shops[Cars[CurrentCar].ShopNumber].t = Cars[CurrentCar].t[1];
                            ServiceTime = Exponent(20);
                            if (ModellingSingleEvent((float)0.1))
                            {
                                ServiceTime *= (float)1.3;
                            }
                            Shops[Cars[CurrentCar].ShopNumber].t += ServiceTime;
                            OldCarTime = Cars[CurrentCar].t[1];
                            Cars[CurrentCar].t[1] += ServiceTime;
                            Cars[CurrentCar].ShopCount--;

                            if (Cars[CurrentCar].ShopCount == 0)
                            {
                                TimeToNext = Exponent(20);
                                Cars[CurrentCar].t[0] = Cars[CurrentCar].t[1] + TimeToNext;
                                Cars[CurrentCar].t[1] = -1;
                            }
                            else
                            {
                                TimeToNext = Exponent(10);
                                Cars[CurrentCar].t[1] += TimeToNext;
                            }

                            Item = new OneItem(8);

                            Item.strings[0] = (Cars[CurrentCar].Number + 1).ToString();
                            Item.strings[1] = "магазин №" + (Cars[CurrentCar].ShopNumber + 1).ToString();
                            Item.strings[2] = String.Format("{0:0.00}", OldCarTime);
                            Item.strings[3] = String.Format("{0:0.00}", OldTime);
                            Item.strings[4] = String.Format("{0:0.00}", ServiceTime);
                            Item.strings[5] = String.Format("{0:0.00}", Shops[Cars[CurrentCar].ShopNumber].t);

                            Item.strings[6] = String.Format("{0:0.00}", TimeToNext);
                            if (Cars[CurrentCar].ShopCount == 1)
                            {
                                if (Cars[CurrentCar].ShopNumber == Shops.Count - 1)
                                {
                                    Item.strings[7] = "Отправлен в магазин №1";
                                }
                                else
                                {
                                    Item.strings[7] = "Отправлен в магазин №" + (Cars[CurrentCar].ShopNumber + 2).ToString();
                                }
                            }
                            else
                            {
                                Item.strings[7] = "Отправлен на хлебозавод";
                            }
                            ModellingResult.Add(Item);

                            Cars[CurrentCar].ShopNumber++;
                            if (Cars[CurrentCar].ShopNumber == Shops.Count)
                            {
                                Cars[CurrentCar].ShopNumber = 0;
                            }
                        }
                        else
                        {

                            CarFromQuery = Shops[Cars[CurrentCar].ShopNumber].Query[0];
                            Shops[Cars[CurrentCar].ShopNumber].Query.RemoveAt(0);
                            Cars[CarFromQuery.Number].InQuery = false;
                            OldTime = Shops[Cars[CurrentCar].ShopNumber].t;
                            ServiceTime = Exponent(20);
                            if (ModellingSingleEvent((float)0.1))
                            {
                                ServiceTime *= (float)1.3;
                            }
                            Shops[Cars[CurrentCar].ShopNumber].t += ServiceTime;
                            OldCarTime = Cars[CarFromQuery.Number].t[1];
                            Cars[CarFromQuery.Number].t[1] += ServiceTime;
                            Cars[CarFromQuery.Number].ShopCount--;

                            if (Cars[CarFromQuery.Number].ShopCount == 0)
                            {
                                TimeToNext = Exponent(20);
                                Cars[CarFromQuery.Number].t[0] = Cars[CarFromQuery.Number].t[1] + TimeToNext;
                                Cars[CarFromQuery.Number].t[1] = -1;

                            }
                            else
                            {
                                TimeToNext = Exponent(10);
                                Cars[CarFromQuery.Number].t[1] += TimeToNext;
                            }

                            Item = new OneItem(8);

                            Item.strings[0] = (Cars[CarFromQuery.Number].Number + 1).ToString();
                            Item.strings[1] = "магазин №" + (Cars[CarFromQuery.Number].ShopNumber + 1).ToString();
                            Item.strings[2] = String.Format("{0:0.00}", OldCarTime);
                            Item.strings[3] = String.Format("{0:0.00}", OldTime);
                            Item.strings[4] = String.Format("{0:0.00}", ServiceTime);
                            Item.strings[5] = String.Format("{0:0.00}", Shops[Cars[CarFromQuery.Number].ShopNumber].t);
                            Item.strings[6] = String.Format("{0:0.00}", TimeToNext);
                            Item.strings[7] = "Извлечение из очереди. ";

                            if (Cars[CarFromQuery.Number].ShopCount == 1)
                            {
                                if (Cars[CarFromQuery.Number].ShopNumber == Shops.Count - 1)
                                {
                                    Item.strings[7] = "Отправлен в магазин №1";
                                }
                                else
                                {
                                    Item.strings[7] += ("Отправлен в магазин №" + (Cars[CarFromQuery.Number].ShopNumber + 2).ToString());
                                }
                            }
                            else
                            {
                                Item.strings[7] += ("Отправлен на хлебозавод");
                            }
                            ModellingResult.Add(Item);
                            Cars[CarFromQuery.Number].ShopNumber++;
                            if (Cars[CarFromQuery.Number].ShopNumber == Shops.Count)
                            {
                                Cars[CarFromQuery.Number].ShopNumber = 0;
                            }
                            i++;
                            goto Shops;
                        }
                    }
                    else
                    {
                        //добавляем в очередь магазина
                        Shops[Cars[CurrentCar].ShopNumber].Query.Add(Cars[CurrentCar]);
                        Cars[CurrentCar].InQuery = true;

                        Item = new OneItem(8);

                        Item.strings[0] = (Cars[CurrentCar].Number + 1).ToString();
                        Item.strings[1] = "магазин №" + (Cars[CurrentCar].ShopNumber + 1).ToString();
                        Item.strings[2] = String.Format("{0:0.00}", Cars[CurrentCar].t[1]);
                        Item.strings[3] = String.Format("{0:0.00}", Shops[Cars[CurrentCar].ShopNumber].t);
                        Item.strings[4] = String.Format("---");
                        Item.strings[5] = String.Format("---");
                        Item.strings[6] = String.Format("---");
                        Item.strings[7] = "Добавлен в очередь";
                        ModellingResult.Add(Item);
                    }
                }
            }

            return ModellingResult;
        }
Exemple #2
0
        public List <OneItem> MainModelling(int k1, int k2)
        {
            int   i;
            int   CurrentPlace = -1;
            int   CurrentCar   = 0;
            float OldTime;
            float OldCarTime;
            float ServiceTime;
            float TimeToNext;

            CurrentShop = 0;
            OneItem Item         = new OneItem(8);
            Car     CarFromQuery = new Car();

            ResetCars();
            ResetShops();
            Plant = new BreadPlant();

            List <OneItem> ModellingResult = new List <OneItem>();

            for (i = 0; i < k1; i++)
            {
                SearchCurrenrEvent(ref CurrentPlace, ref CurrentCar);
Plant:
                if (CurrentPlace == 0)
                {
                    if (Plant.t <= Cars[CurrentCar].t[0])
                    {
                        if (Plant.Query.Count == 0)
                        {
                            OldTime                     = Plant.t;
                            Plant.t                     = Cars[CurrentCar].t[0];
                            ServiceTime                 = Normal(CurM, CurS);
                            Plant.t                    += ServiceTime;
                            OldCarTime                  = Cars[CurrentCar].t[0];
                            Cars[CurrentCar].t[0]      += ServiceTime;
                            Cars[CurrentCar].ShopCount  = ModellingFullGroupEvent(ArrayP) + 1;
                            Cars[CurrentCar].ShopNumber = CurrentShop;
                            NextShop();
                            if (Cars[CurrentCar].ShopCount == 2)
                            {
                                NextShop();
                            }
                            TimeToNext            = Exponent(30);
                            Cars[CurrentCar].t[1] = Cars[CurrentCar].t[0] + TimeToNext;
                            Cars[CurrentCar].t[0] = -1;

                            Item = new OneItem(8);

                            Item.strings[0] = (Cars[CurrentCar].Number + 1).ToString();
                            Item.strings[1] = "хлебозавод";
                            Item.strings[2] = String.Format("{0:0.00}", OldCarTime);
                            Item.strings[3] = String.Format("{0:0.00}", OldTime);
                            Item.strings[4] = String.Format("{0:0.00}", ServiceTime);
                            Item.strings[5] = String.Format("{0:0.00}", Plant.t);
                            Item.strings[6] = String.Format("{0:0.00}", TimeToNext);
                            Item.strings[7] = "Отправлен в магазин №" + (Cars[CurrentCar].ShopNumber + 1).ToString();
                            if (Cars[CurrentCar].ShopCount == 2)
                            {
                                if (Cars[CurrentCar].ShopNumber == Shops.Count - 1)
                                {
                                    Item.strings[7] += " и магазин №1";
                                }
                                else
                                {
                                    Item.strings[7] += " и магазин №" + (Cars[CurrentCar].ShopNumber + 2).ToString();
                                }
                            }
                            ModellingResult.Add(Item);
                        }
                        else
                        {
                            CarFromQuery = Plant.Query[0];
                            Plant.Query.RemoveAt(0);
                            Cars[CarFromQuery.Number].InQuery = false;
                            OldTime     = Plant.t;
                            ServiceTime = Normal(CurM, CurS);
                            Plant.t    += ServiceTime;
                            OldCarTime  = Cars[CarFromQuery.Number].t[0];
                            Cars[CarFromQuery.Number].t[0]       = Plant.t + ServiceTime;
                            Cars[CarFromQuery.Number].ShopCount  = ModellingFullGroupEvent(ArrayP) + 1;
                            Cars[CarFromQuery.Number].ShopNumber = CurrentShop;
                            NextShop();
                            if (Cars[CarFromQuery.Number].ShopCount == 2)
                            {
                                NextShop();
                            }
                            TimeToNext = Exponent(30);
                            Cars[CarFromQuery.Number].t[1] = Cars[CarFromQuery.Number].t[0] + TimeToNext;
                            Cars[CarFromQuery.Number].t[0] = -1;
                            Item            = new OneItem(8);
                            Item.strings[0] = (Cars[CarFromQuery.Number].Number + 1).ToString();
                            Item.strings[1] = "хлебозавод";
                            Item.strings[2] = String.Format("{0:0.00}", OldCarTime);
                            Item.strings[3] = String.Format("{0:0.00}", OldTime);
                            Item.strings[4] = String.Format("{0:0.00}", ServiceTime);
                            Item.strings[5] = String.Format("{0:0.00}", Plant.t);
                            Item.strings[6] = String.Format("{0:0.00}", TimeToNext);
                            Item.strings[7] = "Извлечен из очереди. Отправлен в магазин            №" + (Cars[CarFromQuery.Number].ShopNumber + 1).ToString();
                            if (Cars[CarFromQuery.Number].ShopCount == 2)
                            {
                                if (Cars[CarFromQuery.Number].ShopNumber == Shops.Count - 1)
                                {
                                    Item.strings[7] += " и магазин №1";
                                }
                                else
                                {
                                    Item.strings[7] += " и магазин №" + (Cars[CarFromQuery.Number].ShopNumber + 2).ToString();
                                }
                            }
                            ModellingResult.Add(Item);
                            i++;
                            goto Plant;
                        }
                    }
                    else
                    {
                        Plant.Query.Add(Cars[CurrentCar]);
                        Cars[CurrentCar].InQuery = true;

                        Item = new OneItem(8);

                        Item.strings[0] = (Cars[CurrentCar].Number + 1).ToString();
                        Item.strings[1] = "хлебозавод";
                        Item.strings[2] = String.Format("{0:0.00}", Cars[CurrentCar].t[0]);
                        Item.strings[3] = String.Format("{0:0.00}", Plant.t);
                        Item.strings[4] = String.Format("---");
                        Item.strings[5] = String.Format("---");
                        Item.strings[6] = String.Format("---");
                        Item.strings[7] = "Добавлен в очередь";
                        ModellingResult.Add(Item);
                    }
                }

                else
                {
Shops:
                    if (Shops[Cars[CurrentCar].ShopNumber].t <= Cars[CurrentCar].t[1])
                    {
                        if (Shops[Cars[CurrentCar].ShopNumber].Query.Count == 0)
                        {
                            OldTime = Shops[Cars[CurrentCar].ShopNumber].t;
                            Shops[Cars[CurrentCar].ShopNumber].t = Cars[CurrentCar].t[1];
                            ServiceTime = Exponent(20);
                            if (ModellingSingleEvent((float)0.1))
                            {
                                ServiceTime *= (float)1.3;
                            }
                            Shops[Cars[CurrentCar].ShopNumber].t += ServiceTime;
                            OldCarTime             = Cars[CurrentCar].t[1];
                            Cars[CurrentCar].t[1] += ServiceTime;
                            Cars[CurrentCar].ShopCount--;

                            if (Cars[CurrentCar].ShopCount == 0)
                            {
                                TimeToNext            = Exponent(20);
                                Cars[CurrentCar].t[0] = Cars[CurrentCar].t[1] + TimeToNext;
                                Cars[CurrentCar].t[1] = -1;
                            }
                            else
                            {
                                TimeToNext             = Exponent(10);
                                Cars[CurrentCar].t[1] += TimeToNext;
                            }

                            Item = new OneItem(8);

                            Item.strings[0] = (Cars[CurrentCar].Number + 1).ToString();
                            Item.strings[1] = "магазин №" + (Cars[CurrentCar].ShopNumber + 1).ToString();
                            Item.strings[2] = String.Format("{0:0.00}", OldCarTime);
                            Item.strings[3] = String.Format("{0:0.00}", OldTime);
                            Item.strings[4] = String.Format("{0:0.00}", ServiceTime);
                            Item.strings[5] = String.Format("{0:0.00}", Shops[Cars[CurrentCar].ShopNumber].t);

                            Item.strings[6] = String.Format("{0:0.00}", TimeToNext);
                            if (Cars[CurrentCar].ShopCount == 1)
                            {
                                if (Cars[CurrentCar].ShopNumber == Shops.Count - 1)
                                {
                                    Item.strings[7] = "Отправлен в магазин №1";
                                }
                                else
                                {
                                    Item.strings[7] = "Отправлен в магазин №" + (Cars[CurrentCar].ShopNumber + 2).ToString();
                                }
                            }
                            else
                            {
                                Item.strings[7] = "Отправлен на хлебозавод";
                            }
                            ModellingResult.Add(Item);

                            Cars[CurrentCar].ShopNumber++;
                            if (Cars[CurrentCar].ShopNumber == Shops.Count)
                            {
                                Cars[CurrentCar].ShopNumber = 0;
                            }
                        }
                        else
                        {
                            CarFromQuery = Shops[Cars[CurrentCar].ShopNumber].Query[0];
                            Shops[Cars[CurrentCar].ShopNumber].Query.RemoveAt(0);
                            Cars[CarFromQuery.Number].InQuery = false;
                            OldTime     = Shops[Cars[CurrentCar].ShopNumber].t;
                            ServiceTime = Exponent(20);
                            if (ModellingSingleEvent((float)0.1))
                            {
                                ServiceTime *= (float)1.3;
                            }
                            Shops[Cars[CurrentCar].ShopNumber].t += ServiceTime;
                            OldCarTime = Cars[CarFromQuery.Number].t[1];
                            Cars[CarFromQuery.Number].t[1] += ServiceTime;
                            Cars[CarFromQuery.Number].ShopCount--;

                            if (Cars[CarFromQuery.Number].ShopCount == 0)
                            {
                                TimeToNext = Exponent(20);
                                Cars[CarFromQuery.Number].t[0] = Cars[CarFromQuery.Number].t[1] + TimeToNext;
                                Cars[CarFromQuery.Number].t[1] = -1;
                            }
                            else
                            {
                                TimeToNext = Exponent(10);
                                Cars[CarFromQuery.Number].t[1] += TimeToNext;
                            }

                            Item = new OneItem(8);

                            Item.strings[0] = (Cars[CarFromQuery.Number].Number + 1).ToString();
                            Item.strings[1] = "магазин №" + (Cars[CarFromQuery.Number].ShopNumber + 1).ToString();
                            Item.strings[2] = String.Format("{0:0.00}", OldCarTime);
                            Item.strings[3] = String.Format("{0:0.00}", OldTime);
                            Item.strings[4] = String.Format("{0:0.00}", ServiceTime);
                            Item.strings[5] = String.Format("{0:0.00}", Shops[Cars[CarFromQuery.Number].ShopNumber].t);
                            Item.strings[6] = String.Format("{0:0.00}", TimeToNext);
                            Item.strings[7] = "Извлечение из очереди. ";

                            if (Cars[CarFromQuery.Number].ShopCount == 1)
                            {
                                if (Cars[CarFromQuery.Number].ShopNumber == Shops.Count - 1)
                                {
                                    Item.strings[7] = "Отправлен в магазин №1";
                                }
                                else
                                {
                                    Item.strings[7] += ("Отправлен в магазин №" + (Cars[CarFromQuery.Number].ShopNumber + 2).ToString());
                                }
                            }
                            else
                            {
                                Item.strings[7] += ("Отправлен на хлебозавод");
                            }
                            ModellingResult.Add(Item);
                            Cars[CarFromQuery.Number].ShopNumber++;
                            if (Cars[CarFromQuery.Number].ShopNumber == Shops.Count)
                            {
                                Cars[CarFromQuery.Number].ShopNumber = 0;
                            }
                            i++;
                            goto Shops;
                        }
                    }
                    else
                    {
                        //добавляем в очередь магазина
                        Shops[Cars[CurrentCar].ShopNumber].Query.Add(Cars[CurrentCar]);
                        Cars[CurrentCar].InQuery = true;

                        Item = new OneItem(8);

                        Item.strings[0] = (Cars[CurrentCar].Number + 1).ToString();
                        Item.strings[1] = "магазин №" + (Cars[CurrentCar].ShopNumber + 1).ToString();
                        Item.strings[2] = String.Format("{0:0.00}", Cars[CurrentCar].t[1]);
                        Item.strings[3] = String.Format("{0:0.00}", Shops[Cars[CurrentCar].ShopNumber].t);
                        Item.strings[4] = String.Format("---");
                        Item.strings[5] = String.Format("---");
                        Item.strings[6] = String.Format("---");
                        Item.strings[7] = "Добавлен в очередь";
                        ModellingResult.Add(Item);
                    }
                }
            }

            return(ModellingResult);
        }