Example #1
0
 static void LoopTest(Panel testPanel, CageManager testManager)
 {
     OrderGenerator(testPanel);
     AssignElevator(testManager);
     move_elevators(testManager);
     CleanUpQueue();
 }
Example #2
0
        // Methods //
        public void OrderElevator(int floorNumber, CageManager cageManager)
        {
            foreach (FloorButton button in floorButtons)
            {
                if (button.id == floorNumber)
                {
                    button.status = "Active";
                }
            }

            Column myColumn = cageManager.takeColumn(1, floorNumber);

            Console.WriteLine("Floor Ordered. \tProceed to column " + myColumn.id);
        }
Example #3
0
 // Assign each Order to any elevator for they move to destination//
 static void AssignElevator(CageManager myCageManager)
 {
     foreach (Order Order in OrderQueue)
     {
         if (Order.assignment == "Unassigned")
         {
             Column myColumn = myCageManager.takeColumn(Order.pickup, Order.destination);
             Console.WriteLine("Column " + myColumn.id + " is selected.");
             Cage myCage = myCageManager.takeCage(Order.direction, myColumn.id - 1, Order.pickup);
             Order.assignment = "Assigned";
             myCage.picReq.Add(Order);
             Console.WriteLine("Cage " + myCage.id + " receive Order for floor " + myCage.picReq[0].pickup);
             myCage.picReq.OrderBy(o => o.pickup);
         }
     }
 }
Example #4
0
        static void Scenario1(Panel myPanel, CageManager myCageManager)
        {
            myCageManager.colList[1].cages[0].levelActual = 10;
            myCageManager.colList[1].cages[1].levelActual = 5;
            myCageManager.colList[1].cages[2].levelActual = 19;
            myCageManager.colList[1].cages[3].levelActual = 15;
            myCageManager.colList[1].cages[4].levelActual = 8;


            Console.WriteLine("---------Scenario 1------------");
            Console.WriteLine(" Pickup: 7, direction: down");
            Console.WriteLine(" Pickup: 13, direction: up");
            Console.WriteLine(" Pickup: 5, direction: down");
            Console.WriteLine(" Pickup: 2, direction: down");
            Console.WriteLine(" Pickup: 5, direction: down");
            Console.WriteLine(" some one is floor 1 and request destination :17 ");
            Console.WriteLine("---------Scenario 1------------");
            //Order(string status, int pickup, int destination, string direction)
            OrderQueue.Add(new Order("Destination", 0, 7, "down"));
            OrderQueue[0].assignment = "Assigned";
            myCageManager.colList[1].cages[0].destReq.Add(OrderQueue[0]);
            OrderQueue.Add(new Order("Destination", 0, 13, "up"));
            OrderQueue[1].assignment = "Assigned";
            myCageManager.colList[1].cages[1].destReq.Add(OrderQueue[1]);
            OrderQueue.Add(new Order("Destination", 0, 5, "down"));
            OrderQueue[2].assignment = "Assigned";
            myCageManager.colList[1].cages[2].destReq.Add(OrderQueue[2]);
            OrderQueue.Add(new Order("Destination", 0, 2, "down"));
            OrderQueue[3].assignment = "Assigned";
            myCageManager.colList[1].cages[3].destReq.Add(OrderQueue[3]);
            Console.WriteLine(" destination: 1, direction: down");
            OrderQueue.Add(new Order("Destination", 0, 5, "down"));
            OrderQueue[4].assignment = "Assigned";
            myCageManager.colList[1].cages[4].destReq.Add(OrderQueue[4]);
            LoopTest(myPanel, myCageManager);
            OrderQueue.Add(new Order("Pickup", 1, 17, "up"));
            while (OrderQueue.Count > 0)
            {
                LoopTest(myPanel, myCageManager);
            }
            myCageManager.takeCageStatus();
        }
Example #5
0
 static void Scenario3(Panel myPanel, CageManager myCageManager)
 {
     myCageManager.colList[3].cages[0].levelActual = 58;
     myCageManager.colList[3].cages[1].levelActual = 50;
     myCageManager.colList[3].cages[2].levelActual = 46;
     myCageManager.colList[3].cages[3].levelActual = 1;
     myCageManager.colList[3].cages[4].levelActual = 60;
     Console.WriteLine("---------Scenario 3------------");
     Console.WriteLine(" Pickup: 1, direction: down");
     Console.WriteLine(" Pickup: 63, direction: up");
     Console.WriteLine(" Pickup: 54, direction: up");
     Console.WriteLine(" Pickup: 50, direction: down");
     Console.WriteLine(" Pickup: 1, direction: up");
     Console.WriteLine(" some one is floor 57 and request destination :1 ");
     Console.WriteLine("---------Scenario 3-----------");
     //public Order(string status, int pickup, int destination, string direction)
     OrderQueue.Add(new Order("Destination", 0, 1, "down"));
     OrderQueue[0].assignment = "Assigned";
     myCageManager.colList[3].cages[0].destReq.Add(OrderQueue[0]);
     OrderQueue.Add(new Order("Destination", 0, 63, "up"));
     OrderQueue[1].assignment = "Assigned";
     myCageManager.colList[3].cages[1].destReq.Add(OrderQueue[1]);
     OrderQueue.Add(new Order("Destination", 0, 54, "up"));
     OrderQueue[2].assignment = "Assigned";
     myCageManager.colList[3].cages[2].destReq.Add(OrderQueue[2]);
     OrderQueue.Add(new Order("Destination", 0, 50, "up"));
     OrderQueue[3].assignment = "Assigned";
     myCageManager.colList[3].cages[3].destReq.Add(OrderQueue[3]);
     OrderQueue.Add(new Order("Destination", 0, 1, "up"));
     OrderQueue[4].assignment = "Assigned";
     myCageManager.colList[3].cages[4].destReq.Add(OrderQueue[4]);
     LoopTest(myPanel, myCageManager);
     OrderQueue.Add(new Order("Pickup", 57, 1, "down"));
     while (OrderQueue.Count > 0)
     {
         LoopTest(myPanel, myCageManager);
     }
     myCageManager.takeCageStatus();
 }
Example #6
0
 static void Scenario2(Panel myPanel, CageManager myCageManager)
 {
     myCageManager.colList[2].cages[0].levelActual = 5;
     myCageManager.colList[2].cages[1].levelActual = 1;
     myCageManager.colList[2].cages[2].levelActual = 17;
     myCageManager.colList[2].cages[3].levelActual = 30;
     myCageManager.colList[2].cages[4].levelActual = 40;
     Console.WriteLine("---------Scenario 2------------");
     Console.WriteLine(" Pickup: 21, direction: up");
     Console.WriteLine(" Pickup: 28, direction: up");
     Console.WriteLine(" Pickup: 1, direction: down");
     Console.WriteLine(" Pickup: 24, direction: down");
     Console.WriteLine(" Pickup: 3, direction: down");
     Console.WriteLine(" some one is floor 1 and request destination :33 ");
     Console.WriteLine("---------Scenario 2-----------");
     //public Order(string status, int pickup, int destination, string direction)
     OrderQueue.Add(new Order("Destination", 0, 21, "up"));
     OrderQueue[0].assignment = "Assigned";
     myCageManager.colList[2].cages[0].destReq.Add(OrderQueue[0]);
     OrderQueue.Add(new Order("Destination", 0, 28, "up"));
     OrderQueue[1].assignment = "Assigned";
     myCageManager.colList[2].cages[1].destReq.Add(OrderQueue[1]);
     OrderQueue.Add(new Order("Destination", 0, 1, "down"));
     OrderQueue[2].assignment = "Assigned";
     myCageManager.colList[2].cages[2].destReq.Add(OrderQueue[2]);
     OrderQueue.Add(new Order("Destination", 0, 24, "down"));
     OrderQueue[3].assignment = "Assigned";
     myCageManager.colList[2].cages[3].destReq.Add(OrderQueue[3]);
     OrderQueue.Add(new Order("Destination", 0, 3, "down"));
     OrderQueue[4].assignment = "Assigned";
     myCageManager.colList[2].cages[4].destReq.Add(OrderQueue[4]);
     OrderQueue.Add(new Order("Pickup", 1, 33, "up"));
     while (OrderQueue.Count > 0)
     {
         LoopTest(myPanel, myCageManager);
     }
     myCageManager.takeCageStatus();
 }
Example #7
0
        static void Scenario4(Panel myPanel, CageManager myCageManager)
        {
            myCageManager.colList[0].cages[0].levelActual = -4;
            myCageManager.colList[0].cages[1].levelActual = 1;
            myCageManager.colList[0].cages[2].levelActual = -3;
            myCageManager.colList[0].cages[3].levelActual = -6;
            myCageManager.colList[0].cages[4].levelActual = -1;
            Console.WriteLine("---------Scenario 4------------");
            Console.WriteLine(" Pickup: -5, direction: down");
            Console.WriteLine(" Pickup: 1, direction: up");
            Console.WriteLine(" Pickup: -3, direction: down");
            Console.WriteLine("---------Scenario 4-----------");
            myCageManager.colList[0].cages[2].status    = "Loading";
            myCageManager.colList[0].cages[3].status    = "Loading";
            myCageManager.colList[0].cages[4].status    = "Loading";
            myCageManager.colList[0].cages[2].direction = "down";
            myCageManager.colList[0].cages[3].direction = "up";
            myCageManager.colList[0].cages[4].direction = "down";
            //public Order(string status, int pickup, int destination, string direction)
            OrderQueue.Add(new Order("Destination", 0, -5, "down"));
            OrderQueue[0].assignment = "Assigned";
            myCageManager.colList[0].cages[2].destReq.Add(OrderQueue[0]);
            OrderQueue.Add(new Order("Destination", 0, 1, "up"));
            OrderQueue[1].assignment = "Assigned";
            myCageManager.colList[0].cages[3].destReq.Add(OrderQueue[1]);
            OrderQueue.Add(new Order("Destination", 0, -3, "down"));
            OrderQueue[2].assignment = "Assigned";
            myCageManager.colList[0].cages[4].destReq.Add(OrderQueue[2]);
            LoopTest(myPanel, myCageManager);

            while (OrderQueue.Count > 0)
            {
                LoopTest(myPanel, myCageManager);
            }
            myCageManager.takeCageStatus();
        }
Example #8
0
 // Move all elevators towards next destination or pickup
 static void move_elevators(CageManager myCageManager)
 {
     if (Configuration.totalBasements > 0)
     {
         foreach (Cage cage in myCageManager.colList[0].cages)
         {
             if (cage.picReq.Count != 0)
             {
                 if (cage.levelActual != cage.picReq[0].pickup && cage.levelActual > cage.picReq[0].pickup)
                 {
                     cage.move_down();
                 }
                 else if (cage.levelActual != cage.picReq[0].pickup && cage.levelActual < cage.picReq[0].pickup)
                 {
                     cage.move_up();
                 }
                 else if (cage.levelActual == cage.picReq[0].pickup)
                 {
                     cage.open_door();
                     cage.picReq[0].status = "Destination";
                     cage.CleanUpOrders();
                 }
             }
             if (cage.picReq.Count == 0 && cage.destReq.Count != 0)
             {
                 if (cage.levelActual != cage.destReq[0].destination && cage.levelActual > cage.destReq[0].destination)
                 {
                     cage.move_down();
                 }
                 if (cage.levelActual != cage.destReq[0].destination && cage.levelActual < cage.destReq[0].destination)
                 {
                     cage.move_up();
                 }
                 else if (cage.levelActual == cage.destReq[0].destination)
                 {
                     cage.open_door();
                     cage.destReq[0].status = "Finished";
                     cage.CleanUpOrders();
                 }
             }
         }
         for (int x = 1; x < myCageManager.colList.Count; x++)
         {
             foreach (Cage cage in myCageManager.colList[x].cages)
             {
                 if (cage.picReq.Count != 0)
                 {
                     if (cage.levelActual != cage.picReq[0].pickup && cage.levelActual > cage.picReq[0].pickup)
                     {
                         cage.move_down();
                     }
                     else if (cage.levelActual != cage.picReq[0].pickup && cage.levelActual < cage.picReq[0].pickup)
                     {
                         cage.move_up();
                     }
                     else if (cage.levelActual == cage.picReq[0].pickup)
                     {
                         cage.open_door();
                         cage.picReq[0].status = "Destination";
                         cage.CleanUpOrders();
                     }
                 }
                 if (cage.picReq.Count == 0 && cage.destReq.Count != 0)
                 {
                     if (cage.levelActual != cage.destReq[0].destination && cage.levelActual > cage.destReq[0].destination)
                     {
                         cage.move_down();
                     }
                     if (cage.levelActual != cage.destReq[0].destination && cage.levelActual < cage.destReq[0].destination)
                     {
                         cage.move_up();
                     }
                     else if (cage.levelActual == cage.destReq[0].destination)
                     {
                         cage.open_door();
                         cage.destReq[0].status = "Finished";
                         cage.CleanUpOrders();
                     }
                 }
             }
         }
     }
     else
     {
         foreach (Column column in myCageManager.colList)
         {
             foreach (Cage cage in column.cages)
             {
                 if (cage.picReq.Count != 0)
                 {
                     if (cage.levelActual != cage.picReq[0].pickup && cage.levelActual > cage.picReq[0].pickup)
                     {
                         cage.move_down();
                     }
                     else if (cage.levelActual != cage.picReq[0].pickup && cage.levelActual < cage.picReq[0].pickup)
                     {
                         cage.move_up();
                     }
                     else if (cage.levelActual == cage.picReq[0].pickup)
                     {
                         cage.open_door();
                         cage.picReq[0].status = "Destination";
                         cage.CleanUpOrders();
                     }
                 }
                 if (cage.picReq.Count == 0 && cage.destReq.Count != 0)
                 {
                     if (cage.levelActual != cage.destReq[0].destination && cage.levelActual > cage.destReq[0].destination)
                     {
                         cage.move_down();
                     }
                     if (cage.levelActual != cage.destReq[0].destination && cage.levelActual < cage.destReq[0].destination)
                     {
                         cage.move_up();
                     }
                     else if (cage.levelActual == cage.destReq[0].destination)
                     {
                         cage.open_door();
                         cage.destReq[0].status = "Finished";
                         cage.CleanUpOrders();
                     }
                 }
             }
         }
     }
 }
Example #9
0
        static void Main(string[] args)
        {
            Console.Title = "Rockets_Controllers_elevtors  Author : Said Bourakkadi";

            bool           useDemoConfig = true;
            ConsoleKeyInfo letters;

            do
            {
                Console.WriteLine("Actual configuration? [y/n]");

                while (Console.KeyAvailable == false)
                {
                    Thread.Sleep(100); // Loop until valid input is entered.
                }

                letters = Console.ReadKey(true);
                if (letters.Key != ConsoleKey.Y && letters.Key != ConsoleKey.N)
                {
                    Console.WriteLine("You pressed the '{0}' key.  make a valid selection.", letters.Key);
                }
                else if (letters.Key == ConsoleKey.N)
                {
                    continue;
                }
            } while (letters.Key != ConsoleKey.Y);

            // ================================CONFIGURATION====================== //
            if (useDemoConfig)
            {
                Configuration.batteryOn      = true;
                Configuration.totalColumns   = 4;
                Configuration.cagesPerColumn = 5;
                Configuration.totalFloors    = 60;
                Configuration.totalBasements = 6;

                // CONFIRM SETUP //
                Console.WriteLine("\n=======================");
                Console.WriteLine("\n|     CONFIGURATION    |");
                Console.WriteLine("\n=======================");
                Console.WriteLine($"\n{"Categories",-17} {"Value",15}\n");
                Console.WriteLine($"{"Battery",-17} {"On",15}");
                Console.WriteLine($"{"Total Columns",-17} {Configuration.totalColumns,15}");
                Console.WriteLine($"{"Cages Per Column",-17} {Configuration.cagesPerColumn,15}");
                Console.WriteLine($"{"Total Floors",-17} {Configuration.totalFloors,15}");
                Console.WriteLine($"{"Total Basements",-17} {Configuration.totalBasements,15}");
            }

            // INSTANTIATE FLOORS //
            Configuration.GenerateFloors();

            // INSTANTIATE CAGEMANAGER //
            CageManager myCageManager = new CageManager();

            // INSTANTIATE PANEL //
            Panel myPanel = new Panel();

            while (Configuration.batteryOn)
            {
                int selection = Configuration.GetIntInput("\nSelect a scenario\n([1,2,3,4]\t to EXIT [0])\n", 0);
                if (selection == 1)
                {
                    Scenario1(myPanel, myCageManager);
                }
                else if (selection == 2)
                {
                    Scenario2(myPanel, myCageManager);
                }
                else if (selection == 3)
                {
                    Scenario3(myPanel, myCageManager);
                }
                else if (selection == 4)
                {
                    Scenario4(myPanel, myCageManager);
                }
                else if (selection == 0)
                {
                    Configuration.batteryOn = false;
                }
                else
                {
                    Console.WriteLine(selection + " is not a valid selection. Make a valid selection.");
                }
            }
        }