Esempio n. 1
0
        private void btnUp_Click(object sender, EventArgs e)
        {
            ElevatorDirectionEnum myDirection = myElevator.currStatus.currentElevatorDirection;
            int    myFloor = myElevator.currStatus.currentElevatorFloor;
            string s       = ((sender as Button).Tag).ToString();

            MessageTxt.Text = "The Up button on " + s + " floor button was pressed";
            myElevator.UpButtonPressed(Convert.ToInt32(s));
        }
Esempio n. 2
0
        int CalculatePriority(ElevatorStatus currentElevatorStatus)
        {
            int currentElevatorPos = currentElevatorStatus.currentElevatorFloor;
            ElevatorDirectionEnum currentElevatorDir = currentElevatorStatus.currentElevatorDirection;
            int Multiplier     = 0;
            int RelativeWeight = HighestFloor - Math.Abs(FloorNumber - currentElevatorPos);  // Weight of difference between elevator's current floor and this floor.
            int direction_hint = FloorNumber - currentElevatorPos;

            /*
             * You can be in one of 4 cases:
             * 1. Elevator is in maintenence mode (so priority is of no use and it is returned as 0)
             * 2. Elevator is currently idle, so it will service your request next  (priority will be medium : say P2)
             * 3. Elevator is currently moving towards your floor.
             *  a. You want to move in same direction as elevator is currently moving. Ideally we should make the elevator stop at your floor. (priority will be highest : say P3)
             *  b. You want to move in opposite direction as elevator is moving.  (priority will be medium : say P2)
             * 4. Elevator is currently moving away from your floor.
             *  a. You want to move in same direction as elevator is currently moving. You request will not be service until we reach case 2 or 3 (priority will be lowest : say P1)
             *  b. You want to move in opposite direction as elevator is moving. You request will not be service until we reach case 2 or 3 (priority will be lowest : say P1)
             */

            if (currentElevatorDir == ElevatorDirectionEnum.Maintenence)
            {
                // Case 1: Elevator is in maintenence mode, prioirty is 0.
                goto ExitPoint;
            }

            if (currentElevatorDir == ElevatorDirectionEnum.Idle)
            {
                // Case 2: Elevator is currently idle. It will service your request next.
                Multiplier = 2;
                goto ExitPoint;
            }

            if (((direction_hint > 0) && (currentElevatorDir == ElevatorDirectionEnum.GoingUp)) ||
                ((direction_hint < 0) && (currentElevatorDir == ElevatorDirectionEnum.GoingDown)))
            {   // This means the Elevator is moving towards your floor:  Case 3
                if (UpButton && (currentElevatorDir == ElevatorDirectionEnum.GoingUp))
                {
                    Multiplier = 3;
                }
                else if (DownButton && (currentElevatorDir == ElevatorDirectionEnum.GoingDown))
                {
                    Multiplier = 3;
                }
                else
                {
                    Multiplier = 2;
                }
            }
            else
            {
                // Elevator is currently moving away from your floor: Case 4
                Multiplier = 1;
            }
ExitPoint:
            return(RelativeWeight * Multiplier);
        }