Exemple #1
0
        // here is the request from people that want to go up to a floor X
        public Elevator AssignElevator(int RequestedFloor)
        {
            Thread.Sleep(200);
            Console.WriteLine("Requested floor : " + RequestedFloor);
            Thread.Sleep(200);
            Console.WriteLine("Call Button Light On");


            Column column = battery.Find_best_column(RequestedFloor);

            user_direction = "up";
            var      FloorNumber = 1;
            Elevator elevator    = column.Find_Assign_elevator(RequestedFloor, FloorNumber, user_direction);

            elevator.Send_request(FloorNumber, column.column_no);

            elevator.Send_request(RequestedFloor, column.column_no);



            return(elevator);
        }
        public static void Main(string[] args)
        {
            //// Initialization
            BatteryController controller = new BatteryController(66, 4, 5);
            //// Columns Variables
            var ColumnOne   = controller.battery.columnsList[0];
            var ColumnTwo   = controller.battery.columnsList[1];
            var ColumnThree = controller.battery.columnsList[2];
            var ColumnFour  = controller.battery.columnsList[3];

            //

            while (true)
            {
                Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                Console.WriteLine("");
                Console.WriteLine("             ---Senarios Testing--- ");
                Console.WriteLine("");
                Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                Console.WriteLine("");
                Console.WriteLine("Want you test a scenario? y/n (yes/No)");
                string continueTesting = Console.ReadLine();
                while (continueTesting != "y" && continueTesting != "n")
                {
                    Console.WriteLine("Please choose y for Yes or n for No.");
                    continueTesting = Console.ReadLine();
                }

                if (continueTesting == "n")
                {
                    Console.WriteLine("You choose to leave the test!");
                    Console.WriteLine("The test is done.");
                    Console.WriteLine("Thank you!");
                    break;
                }
                Console.WriteLine("");
                Console.WriteLine("Please choose a scenario: 1, 2, 3 or 4");
                string scenario = Console.ReadLine();
                while (scenario != "1" && scenario != "2" && scenario != "3" && scenario != "4")
                {
                    Console.WriteLine("Please choose a scenario: 1, 2, 3 or 4");
                    scenario = Console.ReadLine();
                }
                //--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                if (scenario == "1")
                {
                    Console.WriteLine("");
                    Console.WriteLine("---Testing scenario 1 ");
                    Console.WriteLine("");
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");


                    // // Scenario 1:
                    // // With second column (or column B) serving floors from 2 to 20,
                    // // with elevator B1 at 20th floor going to 5th, B2 at 3rd floor going to 15th,
                    // // B3 at 13th floor going to 1st, B4 at 15th floor going to 2nd,
                    // // and B5 at 6th floor going to 1st, someone is at 1st floor and
                    // // requests the 20th floor, elevator B5 is expected to be sent


                    //Elevator # 1
                    // with elevator B1 at 20th floor going to 5th
                    ColumnTwo.elevatorsList[0].ElevCurrentFloor = 20;
                    ColumnTwo.elevatorsList[0].elevDirection    = "Up";
                    ColumnTwo.elevatorsList[0].status           = "Moving";
                    ColumnTwo.elevatorsList[0].elevFloorsList.Add(5);

                    //Elevator # 2
                    // B2 at 3rd floor going to 15th,
                    ColumnTwo.elevatorsList[1].ElevCurrentFloor = 3;
                    ColumnTwo.elevatorsList[1].elevDirection    = "Up";
                    ColumnTwo.elevatorsList[1].status           = "Moving";
                    ColumnTwo.elevatorsList[1].elevFloorsList.Add(15);

                    //Elevator # 3
                    // B3 at 13th floor going to 1st,
                    ColumnTwo.elevatorsList[2].ElevCurrentFloor = 13;
                    ColumnTwo.elevatorsList[2].elevDirection    = "Down";
                    ColumnTwo.elevatorsList[2].status           = "Moving";
                    ColumnTwo.elevatorsList[2].elevFloorsList.Add(1);

                    //Elevator # 4
                    // B4 at 15th floor going to 2nd
                    ColumnTwo.elevatorsList[3].ElevCurrentFloor = 15;
                    ColumnTwo.elevatorsList[3].elevDirection    = "Down";
                    ColumnTwo.elevatorsList[3].status           = "Moving";
                    ColumnTwo.elevatorsList[3].elevFloorsList.Add(2);

                    //Elevator # 5
                    // B5 at 6th floor going to 1st
                    ColumnTwo.elevatorsList[4].ElevCurrentFloor = 6;
                    ColumnTwo.elevatorsList[4].elevDirection    = "Down";
                    ColumnTwo.elevatorsList[4].status           = "Moving";
                    ColumnTwo.elevatorsList[4].elevFloorsList.Add(1);

                    //  someone is at 1st floor and
                    //  requests the 20th floor, elevator B5 is expected to be sent


                    //Request:
                    controller.AssignElevator_ToFloors(20);

                    Console.WriteLine("");
                    Console.WriteLine("---Test scenario 1 : Ok++");
                    Console.WriteLine("");
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");


                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                }
                else if (scenario == "2")
                {
                    Console.WriteLine("");
                    Console.WriteLine("---Testing scenario 2 ");
                    Console.WriteLine("");
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

                    // // Scenario # 2:
                    // //With third column (or column C) serving floors from 21 to 40,
                    // // with elevator C1 at 1st floor going to 21th, C2 at 23st floor going to 28th,
                    // //C3 at 33rd floor going to 1st, C4 at 40th floor going to 24th,
                    // //and C5 at 39nd floor going to 1st, someone is at 1st floor
                    // //and requests the 36th floor, elevator C1 is expected to be sent

                    //Elevator # 1
                    // C1 at 1st floor going to 21th
                    ColumnThree.elevatorsList[0].ElevCurrentFloor = 1;
                    ColumnThree.elevatorsList[0].elevDirection    = "Up";
                    ColumnThree.elevatorsList[0].status           = "Stopped";
                    ColumnThree.elevatorsList[0].elevFloorsList.Add(21);

                    //Elevator # 2
                    // C2 at 23st floor going to 28th,
                    ColumnThree.elevatorsList[1].ElevCurrentFloor = 23;
                    ColumnThree.elevatorsList[1].elevDirection    = "Up";
                    ColumnThree.elevatorsList[1].status           = "Moving";
                    ColumnThree.elevatorsList[1].elevFloorsList.Add(28);

                    //Elevator # 3
                    //  C3 at 33rd floor going to 1st,
                    ColumnThree.elevatorsList[2].ElevCurrentFloor = 33;
                    ColumnThree.elevatorsList[2].elevDirection    = "Down";
                    ColumnThree.elevatorsList[2].status           = "Moving";
                    ColumnThree.elevatorsList[2].elevFloorsList.Add(1);

                    //Elevator # 4
                    // C4 at 40th floor going to 24th,
                    ColumnThree.elevatorsList[3].ElevCurrentFloor = 40;
                    ColumnThree.elevatorsList[3].elevDirection    = "Down";
                    ColumnThree.elevatorsList[3].status           = "Moving";
                    ColumnThree.elevatorsList[3].elevFloorsList.Add(24);

                    //Elevator # 5
                    // and C5 at 39nd floor going to 1st
                    ColumnThree.elevatorsList[4].ElevCurrentFloor = 39;
                    ColumnThree.elevatorsList[4].elevDirection    = "Down";
                    ColumnThree.elevatorsList[4].status           = "Moving";
                    ColumnThree.elevatorsList[4].elevFloorsList.Add(1);

                    //someone is at 1st floor
                    // and requests the 36th floor, elevator C1 is expected to be sent

                    // Request
                    controller.AssignElevator_ToFloors(36);

                    Console.WriteLine("");
                    Console.WriteLine("---Test scenario 2 : Ok++");
                    Console.WriteLine("");
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");



                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                }
                else if (scenario == "3")
                {
                    Console.WriteLine("");
                    Console.WriteLine("---Testing scenario 3 ");
                    Console.WriteLine("");
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");


                    // //Scénario 3:


                    // //With fourth column (or column D) serving floors from 41 to 60,
                    // //with elevator D1 at 58th floor going to 1st, D2 at 50th floor going to 60th,
                    // //D3 at 46th floor going to 58th, D4 at 1st floor going to 54th,
                    // //and D5 at 60th floor going to 1st, someone is at 54th floor and requests the 1st floor,
                    //  //elevator D1 is expected to pick him up

                    //Elevator # 1
                    //D1 at floor 58
                    ColumnFour.elevatorsList[0].ElevCurrentFloor = 58;
                    ColumnFour.elevatorsList[0].elevDirection    = "Down";
                    ColumnFour.elevatorsList[0].status           = "Moving";
                    ColumnFour.elevatorsList[0].elevFloorsList.Add(1);

                    //Elvator # 2
                    //D2 at 50th floor
                    ColumnFour.elevatorsList[1].ElevCurrentFloor = 50;
                    ColumnFour.elevatorsList[1].elevDirection    = "Up";
                    ColumnFour.elevatorsList[1].status           = "Moving";
                    ColumnFour.elevatorsList[1].elevFloorsList.Add(60);

                    //Elevator # 3
                    //D3 at 46th
                    ColumnFour.elevatorsList[2].ElevCurrentFloor = 46;
                    ColumnFour.elevatorsList[2].elevDirection    = "Up";
                    ColumnFour.elevatorsList[2].status           = "Moving";
                    ColumnFour.elevatorsList[2].elevFloorsList.Add(58);

                    //Elevator # 4
                    //D4 at 1st floor going to 54th
                    ColumnFour.elevatorsList[3].ElevCurrentFloor = 1;
                    ColumnFour.elevatorsList[3].elevDirection    = "Up";
                    ColumnFour.elevatorsList[3].status           = "Moving";
                    ColumnFour.elevatorsList[3].elevFloorsList.Add(54);

                    //Elevator # 5
                    //D5 at 60th floor going to 1st
                    ColumnFour.elevatorsList[4].ElevCurrentFloor = 60;
                    ColumnFour.elevatorsList[4].elevDirection    = "Down";
                    ColumnFour.elevatorsList[4].status           = "Moving";
                    ColumnFour.elevatorsList[4].elevFloorsList.Add(1);


                    // someone is at 54th floor and requests the 1st floor,
                    // elevator D1 is expected to pick him up

                    //Request
                    Elevator elevator = controller.RequestElevator_ToGround(54, 1);

                    Console.WriteLine("");
                    Console.WriteLine("---Test scenario 3 : Ok++");
                    Console.WriteLine("");
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");



                    //--------------------------------------------------------------------------------------------------
                }
                else if (scenario == "4")
                {
                    Console.WriteLine("");
                    Console.WriteLine("---Testing scenario 4 ");
                    Console.WriteLine("");
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

                    // Scenario 4:
                    // With first column (or Column A) serving the basements B1 to B6,
                    // with elevator A1 idle at B4, A2 idle at 1st floor, A3 at B3 and going to B5,
                    // A4 at B6 and going to 1st floor, and A5 at B1 going to B6,
                    // someone is at B3 and requests the 1st floor.
                    // Elevator A4 is expected to be sent.

                    // For the test:
                    // B6 = -6, B5 = -5 ... , B1 = -1 and 0 the first floor.

                    //Elevator # 1
                    //A1 idle at B4 = -4
                    ColumnOne.elevatorsList[0].ElevCurrentFloor = -4;
                    ColumnOne.elevatorsList[0].elevDirection    = " ";
                    ColumnOne.elevatorsList[0].status           = "Idle";
                    ColumnOne.elevatorsList[0].elevFloorsList.Add(-4);

                    //Elevator # 2
                    //A2 idle at 1st floor,
                    ColumnOne.elevatorsList[1].ElevCurrentFloor = 0;
                    ColumnOne.elevatorsList[1].elevDirection    = " ";
                    ColumnOne.elevatorsList[1].status           = "Idle";
                    ColumnOne.elevatorsList[1].elevFloorsList.Add(0);

                    //Elevator # 3
                    //A3 at B3 = -3 and going to B5 = -5,
                    ColumnOne.elevatorsList[2].ElevCurrentFloor = -3;
                    ColumnOne.elevatorsList[2].elevDirection    = "Up";
                    ColumnOne.elevatorsList[2].status           = "Moving";
                    ColumnOne.elevatorsList[2].elevFloorsList.Add(-5);

                    //Elevator # 4
                    //A4 at B6 = -6 and going to 1st floor
                    ColumnOne.elevatorsList[3].ElevCurrentFloor = -6;
                    ColumnOne.elevatorsList[3].elevDirection    = "Up";
                    ColumnOne.elevatorsList[3].status           = "Moving";
                    ColumnOne.elevatorsList[3].elevFloorsList.Add(0);

                    //Elevator # 5
                    //and A5 at B1 = -1 going to B6 = -6,
                    ColumnOne.elevatorsList[3].ElevCurrentFloor = -1;
                    ColumnOne.elevatorsList[3].elevDirection    = "Down";
                    ColumnOne.elevatorsList[3].status           = "Moving";
                    ColumnOne.elevatorsList[3].elevFloorsList.Add(-5);


                    // someone is at B3 = -3 and requests the 1st floor.
                    // Elevator A4 is expected to be sent.

                    Elevator elevator = controller.RequestElevator_upToGround(-3, 0);

                    //controller.AssignElevator_ToBasements(1);

                    Console.WriteLine("");
                    Console.WriteLine("---Test scenario 1 : Ending");
                    Console.WriteLine("");
                    Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                }
            }
        }
Exemple #3
0
            public static void Main(string[] args)
            {
                ElevatorController controller = new ElevatorController(66, 4, 5, "stop");


                // Test

                // Column A

                controller.battery.column_list[0].eleList[0].currentFloor = 3;
                controller.battery.column_list[0].eleList[0].Direction    = "stop";
                controller.battery.column_list[0].eleList[0].status       = "idle";
                controller.battery.column_list[0].eleList[0].floorList.Add(3);


                controller.battery.column_list[0].eleList[1].currentFloor = 7;
                controller.battery.column_list[0].eleList[1].Direction    = "stop";
                controller.battery.column_list[0].eleList[1].status       = "idle";
                controller.battery.column_list[0].eleList[1].floorList.Add(7);


                controller.battery.column_list[0].eleList[2].currentFloor = 4;
                controller.battery.column_list[0].eleList[2].Direction    = "down";
                controller.battery.column_list[0].eleList[2].status       = "moving";
                controller.battery.column_list[0].eleList[2].floorList.Add(2);


                controller.battery.column_list[0].eleList[3].currentFloor = 1;
                controller.battery.column_list[0].eleList[3].Direction    = "up";
                controller.battery.column_list[0].eleList[3].status       = "moving";
                controller.battery.column_list[0].eleList[3].floorList.Add(7);


                controller.battery.column_list[0].eleList[4].currentFloor = 6;
                controller.battery.column_list[0].eleList[4].Direction    = "down";
                controller.battery.column_list[0].eleList[4].status       = "moving";
                controller.battery.column_list[0].eleList[4].floorList.Add(1);

                // controller.assignElevator(1);
                Elevator elevator = controller.RequestElevator(4, 7);

                // Column B

                // controller.battery.column_list[1].eleList[0].currentFloor = 25;
                // controller.battery.column_list[1].eleList[0].Direction = "down";
                // controller.battery.column_list[1].eleList[0].status = "moving";
                // controller.battery.column_list[1].eleList[0].floorList.Add(12);

                // controller.battery.column_list[1].eleList[1].currentFloor = 10;
                // controller.battery.column_list[1].eleList[1].Direction = "up";
                // controller.battery.column_list[1].eleList[1].status = "moving";
                // controller.battery.column_list[1].eleList[1].floorList.Add(13);

                // controller.battery.column_list[1].eleList[2].currentFloor = 20;
                // controller.battery.column_list[1].eleList[2].Direction = "down";
                // controller.battery.column_list[1].eleList[2].status = "moving";
                // controller.battery.column_list[1].eleList[2].floorList.Add(7);

                // controller.battery.column_list[1].eleList[3].currentFloor = 22;
                // controller.battery.column_list[1].eleList[3].Direction = "down";
                // controller.battery.column_list[1].eleList[3].status = "moving";
                // controller.battery.column_list[1].eleList[3].floorList.Add(9);


                // controller.battery.column_list[1].eleList[4].currentFloor = 13;
                // controller.battery.column_list[1].eleList[4].Direction = "down";
                // controller.battery.column_list[1].eleList[4].status = "moving";
                // controller.battery.column_list[1].eleList[4].floorList.Add(7);

                // controller.assignElevator(27);
                // //Elevator elevator = controller.RequestElevator(7, 27);

                // Column C

                // controller.battery.column_list[2].eleList[0].currentFloor = 7;
                // controller.battery.column_list[2].eleList[0].Direction = "up";
                // controller.battery.column_list[2].eleList[0].status = "moving";
                // controller.battery.column_list[2].eleList[0].floorList.Add(28);

                // controller.battery.column_list[2].eleList[1].currentFloor = 30;
                // controller.battery.column_list[2].eleList[1].Direction = "up";
                // controller.battery.column_list[2].eleList[1].status = "moving";
                // controller.battery.column_list[2].eleList[1].floorList.Add(35);

                // controller.battery.column_list[2].eleList[2].currentFloor = 47;
                // controller.battery.column_list[2].eleList[2].Direction = "down";
                // controller.battery.column_list[2].eleList[2].status = "moving";
                // controller.battery.column_list[2].eleList[2].floorList.Add(31);

                // controller.battery.column_list[2].eleList[3].currentFloor = 46;
                // controller.battery.column_list[2].eleList[3].Direction = "down";
                // controller.battery.column_list[2].eleList[3].status = "moving";
                // controller.battery.column_list[2].eleList[3].floorList.Add(7);

                // controller.battery.column_list[2].eleList[4].currentFloor = 47;
                // controller.battery.column_list[2].eleList[4].Direction = "down";
                // controller.battery.column_list[2].eleList[4].status = "moving";
                // controller.battery.column_list[2].eleList[4].floorList.Add(31);

                // controller.assignElevator(43);
                // // Elevator elevator = controller.RequestElevator(7, 43);


                // Column D

                // controller.battery.column_list[3].eleList[0].currentFloor = 64;
                // controller.battery.column_list[3].eleList[0].Direction = "down";
                // controller.battery.column_list[3].eleList[0].status = "moving";
                // controller.battery.column_list[3].eleList[0].floorList.Add(7);


                // controller.battery.column_list[3].eleList[1].currentFloor = 57;
                // controller.battery.column_list[3].eleList[1].Direction = "up";
                // controller.battery.column_list[3].eleList[1].status = "moving";
                // controller.battery.column_list[3].eleList[1].floorList.Add(66);


                // controller.battery.column_list[3].eleList[2].currentFloor = 53;
                // controller.battery.column_list[3].eleList[2].Direction = "up";
                // controller.battery.column_list[3].eleList[2].status = "moving";
                // controller.battery.column_list[3].eleList[2].floorList.Add(64);


                // controller.battery.column_list[3].eleList[3].currentFloor = 7;
                // controller.battery.column_list[3].eleList[3].Direction = "up";
                // controller.battery.column_list[3].eleList[3].status = "moving";
                // controller.battery.column_list[3].eleList[3].floorList.Add(60);


                // controller.battery.column_list[3].eleList[4].currentFloor = 66;
                // controller.battery.column_list[3].eleList[4].Direction = "down";
                // controller.battery.column_list[3].eleList[4].status = "moving";
                // controller.battery.column_list[3].eleList[4].floorList.Add(7);

                // // controller.assignElevator(54);
                // Elevator elevator = controller.RequestElevator(54, 7);
            }