private Floor ChooseElevator(Floor start, ElevatorStatus elevatorStatus) { List <ElevatorNumFloor> diffFloors = new List <ElevatorNumFloor>(); building.floors.ForEach(x => { if (x.elevators.Count > 0) { foreach (Elevator elevator in x.elevators) { if (elevator.Status != ElevatorStatus.LONGSTOP && (elevatorStatus == elevator.Status || elevator.Status == ElevatorStatus.STOP)) { diffFloors.Add(new ElevatorNumFloor() { FloorNum = x.FloorNum, FloorDiff = Math.Abs(x.FloorNum - start.FloorNum) }); } } } } ); var minDiff = diffFloors?.Min(x => x.FloorDiff); return(building.floors.Where(f => f.FloorNum == diffFloors.First(x => x.FloorDiff == minDiff).FloorNum).FirstOrDefault()); }
public Elevator(Building Mybuilding, int HorizontalPosition, Floor StartingFloor) { this.myBuilding = Mybuilding; this.currentFloor = StartingFloor; this.listOfFloorsToVisit = new List<Floor>(); this.elevatorDirection = Direction.None; this.elevatorStatus = ElevatorStatus.Idle; this.maximumPeopleInside = 2; this.listOfPeopleInside = new List<Passenger>(); this.IsFull = false; this.elevatorPosition = new Point(HorizontalPosition, currentFloor.GetFloorLevelInPixels()); currentFrameNumber = 0; elevatorFrames = new Bitmap[] { Properties.Resources.LiftDoors_Open, Properties.Resources.LiftDoors_4, Properties.Resources.LiftDoors_3, Properties.Resources.LiftDoors_2, Properties.Resources.LiftDoors_1, Properties.Resources.LiftDoors_Closed }; this.elevatorAnimationDelay = 8; this.elevatorTimer = new System.Timers.Timer(5000); //set timer to 5 seconds this.elevatorTimer.Elapsed += new ElapsedEventHandler(this.Elevator_ElevatorTimerElapsed); this.PassengerEnteredTheElevator += new EventHandler(this.Elevator_PassengerEnteredTheElevator); //Add new elevator to floor's list currentFloor.AddRemoveElevatorToTheListOfElevatorsWaitingHere(this, true); }
public Elevator getElevatorToUserFloor(int userFloor, ElevatorStatus elevatorStatus) { //User input floor validation List <ValidationResult> destRes = new Floor(userFloor).ValidateFloor().ToList <ValidationResult>(); if (destRes.Count > 0) { destRes.ForEach(r => Console.WriteLine(r.ErrorMessage)); return(null); } Floor presentFloor = building.floors.Find(x => x.FloorNum == userFloor); //Calc Which lift serve quickly for user request Floor nearestEleFloor = ChooseElevator(presentFloor, elevatorStatus); Elevator ele = nearestEleFloor.elevators.FirstOrDefault(); nearestEleFloor.elevators.Remove(ele); ele.Status = GetMoveDirection(ele, nearestEleFloor.FloorNum, userFloor); Thread.Sleep(Math.Abs(nearestEleFloor.FloorNum - userFloor) * 1000); presentFloor.elevators.Add(ele); return(ele); }
private void Stop(sbyte floor) { Status = ElevatorStatus.STOPPED; CurrentFloor = floor; floorReady[floor] = false; Console.WriteLine("Stopped at floor {0}", floor); }
public Elevator(Building myBuilding, int horizontalPosition, Floor startingFloor, Mediator mediator) : base(mediator) { _myBuilding = myBuilding; _currentFloor = startingFloor; _listOfFloorsToVisit = new List <Floor>(); _elevatorDirection = Direction.stop; _elevatorStatus = ElevatorStatus.Idle; _maximumPeopleInside = 2; _listOfPeopleInside = new List <Passenger>(); _isFull = false; _elevatorPosition = new Point(horizontalPosition, _currentFloor.GetFloorLevelInPixels()); _currentFrameNumber = 0; _elevatorFrames = new[] { Properties.Resources.LiftDoors_Open, Properties.Resources.LiftDoors_4, Properties.Resources.LiftDoors_3, Properties.Resources.LiftDoors_2, Properties.Resources.LiftDoors_1, Properties.Resources.LiftDoors_Closed }; _elevatorAnimationDelay = 8; _elevatorTimer = new System.Timers.Timer(6000); //set timer to 6 seconds _elevatorTimer.Elapsed += Elevator_ElevatorTimerElapsed; PassengerEnteredTheElevator += Elevator_PassengerEnteredTheElevator; //Add new elevator to floor's list _currentFloor.AddRemoveElevatorToTheListOfElevatorsWaitingHere(this, true); }
private void SetElevatorStatus(ElevatorStatus status) { lock (_locker) //To avoid e.g. setting and getting status at the same time { this._elevatorStatus = status; } }
bool CheckElevatorAndPassenger(uint floor, IElevator e) { ElevatorStatus status = e.CurrentStatus; return((status.CurrentDirection == Direction.No) && (status.CurrentFloor == floor)); }
//----------------- Methods for logic -----------------// /* ******* LOGIC TO MOVE ELEVATOR ******* */ public void moveElevator(int requestedFloor) { while (this.floorRequestList.Count > 0) { if (this.status == ElevatorStatus.IDLE) { if (this.floor < requestedFloor) { this.status = ElevatorStatus.UP; } else if (this.floor > requestedFloor) { this.status = ElevatorStatus.DOWN; } else { this.openDoors(); this.deleteFloorFromList(requestedFloor); this.manageButtonStatusOff(requestedFloor); } } if (this.status == ElevatorStatus.UP) { this.moveUp(); } else if (this.status == ElevatorStatus.DOWN) { this.moveDown(); } } }
private void Stop(int floor) { _elevatorStatus = ElevatorStatus.STOP; CurrentFloor = floor; Console.WriteLine("Waiting....................."); Thread.Sleep(1000); }
public static string ConvertElevatorStatusToString(ElevatorStatus status) { switch (status) { case ElevatorStatus.Waiting: return("Waiting"); case ElevatorStatus.Opening: return("Opening"); case ElevatorStatus.Opened: return("Opened"); case ElevatorStatus.Closing: return("Closing"); case ElevatorStatus.Closed: return("Closed"); case ElevatorStatus.MovingUp: return("Moving Up"); case ElevatorStatus.MovingDown: return("Moving Down"); case ElevatorStatus.Arrived: return("Arrived"); default: break; } return(""); }
public Elevator(int currentFloor, int allFloors) { elevatorStatus = ElevatorStatus.Stopped; Semaphore = new Semaphore(1, 1); CurrentFloor = currentFloor; AllFloors = allFloors; }
public Elevator(Building Mybuilding, int HorizontalPosition, Floor StartingFloor) { this.myBuilding = Mybuilding; this.currentFloor = StartingFloor; this.listOfFloorsToVisit = new List <Floor>(); this.elevatorDirection = Direction.None; this.elevatorStatus = ElevatorStatus.Idle; this.maximumPeopleInside = 2; this.listOfPeopleInside = new List <Passenger>(); this.IsFull = false; this.elevatorPosition = new Point(HorizontalPosition, currentFloor.GetFloorLevelInPixels()); currentFrameNumber = 0; elevatorFrames = new Bitmap[] { Properties.Resources.LiftDoors_Open, Properties.Resources.LiftDoors_4, Properties.Resources.LiftDoors_3, Properties.Resources.LiftDoors_2, Properties.Resources.LiftDoors_1, Properties.Resources.LiftDoors_Closed }; this.elevatorAnimationDelay = 8; this.elevatorTimer = new System.Timers.Timer(5000); //set timer to 5 seconds this.elevatorTimer.Elapsed += new ElapsedEventHandler(this.Elevator_ElevatorTimerElapsed); this.PassengerEnteredTheElevator += new EventHandler(this.Elevator_PassengerEnteredTheElevator); //Add new elevator to floor's list currentFloor.AddRemoveElevatorToTheListOfElevatorsWaitingHere(this, true); }
private void Stop(int floor) { Status = ElevatorStatus.STOPPED; currentFloor = floor; floorReady[floor] = false; Console.WriteLine("Stopped at {0} floor", floor); }
private void Stop(int floor) { _status = ElevatorStatus.STOPPED; _currentLevel = floor; _floorReady[floor] = false; Console.WriteLine("Stopped at floor {0}", floor); }
private void Decend() { while (_downwardstops.Any()) { _elevator.Direction = Direction.Downward; Thread.Sleep(TIME_TO_REACH_NEXT_FLOOR); _currentFloorNumber--; if (_downwardstops.Any(x => x == _currentFloorNumber)) { Stop(); } NotifyFloorDeparture(); _downwardstops.Remove(_downwardstops.First()); } if (_upwardstops.Any()) { Ascend(); } else { _status = ElevatorStatus.WaitingForInput; } }
private void Ascend() { while (_upwardstops.Any()) { _elevator.Direction = Direction.Upward; //assume that we reach next floor in 1000ms, //this can be replaced by another event notifier that can raise an event when a floor is reached Thread.Sleep(TIME_TO_REACH_NEXT_FLOOR); _currentFloorNumber++; if (_upwardstops.Any(x => x == _currentFloorNumber)) { Stop(); } NotifyFloorDeparture(); _upwardstops.Remove(_upwardstops.First()); } if (_downwardstops.Any()) { Decend(); } else { _status = ElevatorStatus.WaitingForInput; } }
/// <summary> /// Elevator stops at this floor /// </summary> /// <param name="floor"></param> private void Stop(int floor) { Status = ElevatorStatus.STOPPED; currentFloor = floor; floorReady[floor + numberOfBasements] = false; Console.WriteLine("Elevator" + elevatorNumber + " opening the door at floor{0}", floor); }
public IEnumerator RoutineSendStatusUpdateRequest(ElevatorStatus newStatus, float delayTime) { yield return(new WaitForSeconds(delayTime)); UpdateElevatorStatusRequest request = new UpdateElevatorStatusRequest(newStatus); onElevatorStatusUpdateCallback?.Invoke(request); }
private void SetElevatorStatus(ElevatorStatus Status) { lock (locker) //To avoid e.g. setting and getting status at the same time { this.elevatorStatus = Status; logWriter.Log($"Elevator ({Id}) is ({this.GetElevatorStatus()})"); } }
private void UpdateElevatorControlSystem(ElevatorStatus elevatorStatus) { switch (elevatorStatus.FloorNo) { case 0: IsChecked0 = false; break; case 1: IsChecked1 = false; break; case 2: IsChecked2 = false; break; case 3: IsChecked3 = false; break; case 4: IsChecked4 = false; break; case 5: IsChecked5 = false; break; case 6: IsChecked6 = false; break; case 7: IsChecked7 = false; break; case 8: IsChecked8 = false; break; case 9: IsChecked9 = false; break; case 10: IsChecked10 = false; break; case 11: IsChecked11 = false; break; case 12: IsChecked12 = false; break; } ; }
private void InitializeElevatorService() { this._elevatorService.Operate(EnumElevatorDirection.Idle); ElevatorStatus elevatorMessage = new ElevatorStatus(); elevatorMessage.FloorNo = this._elevatorService.CurrentFloor; elevatorMessage.Message = this._elevatorService.Status; elevatorMessage.Direction = this._elevatorService.Direction; PublishElevatorMessage(elevatorMessage); }
private void ElevatorStatusUpdate() { if (elevatorCurrentFloor.FloorIndex < WhatFloorToVisitNext().FloorIndex) { this.statusOfElevator = ElevatorStatus.GoingUp; } else { this.statusOfElevator = ElevatorStatus.GoingDown; } }
public Elevator(string uid, int maxFloor) { this.UID = uid; _maxFloor = maxFloor; _currentFloor = 1; _currentStatus = ElevatorStatus.Idle; _observers = new List <IElevatorObserver>(); _destinationFloors = new SortedSet <int>(); _floorsPassed = 0; _tripsMade = 0; }
private void Move() { _status = ElevatorStatus.InFlight; if (_elevator.Direction == Direction.Downward) { Decend(); } else { Ascend(); } }
// Activates or deactivates emergency status public void ToggleEmergency() { // Determine wether to activate or disable Emergency status if (Status == ElevatorStatus.EMERGENCY) { Status = ElevatorStatus.IDLE; return; } else { Status = ElevatorStatus.EMERGENCY; return; } }
// Move up and move down functionality public void MoveUp() { // Short circuit if trying to go up on the top floor by reversing status (direction in this case) if (_floorLocation + 1 > TopFloor) { Status = ElevatorStatus.DESCENDING; return; } // Increment the current floor _floorLocation++; // Set elevator to ascending status Status = ElevatorStatus.ASCENDING; }
public void MoveDown() { // Short circuit if trying to go down past lowest floor by reversing status (direction in this case) if (_floorLocation - 1 < BottomFloor) { Status = ElevatorStatus.ASCENDING; return; } // Decrement the current floor _floorLocation--; // Set elevator to desscending status Status = ElevatorStatus.DESCENDING; }
// Constructor public Elevator(string id, int totalWeightCapacity, int totalPersonCapacity, int topFloor, int bottomFloor, bool isFull) { Id = id; TotalWeightCapacity = totalPersonCapacity; TotalPersonCapacity = totalPersonCapacity; IsFull = isFull; // Set top and lowest floor TopFloor = topFloor; BottomFloor = bottomFloor; // Set direction as IDLE for after instanciating Status = ElevatorStatus.IDLE; // Default 0 weight and capacity Weight = 0.0; Capacity = 0; }
private void Ascend(int floor) { for (int i = _currentLevel + 1; i <= _upperLevel; i++) { if (_floorReady[i]) { Stop(floor); break; } Console.WriteLine("Going Up - Floor {0}", i); } _status = ElevatorStatus.STOPPED; Console.WriteLine("Waiting.."); }
/* ******* LOGIC TO CLOSE DOORS ******* */ public void closeDoors() { this.checkWeight(); this.checkObstruction(); if (this.weightSensorStatus == SensorStatus.OFF && this.obstructionSensorStatus == SensorStatus.OFF) { //Security logic System.Console.WriteLine(" Closing doors..."); System.Console.WriteLine(" Elevator doors are closed"); Door currentDoor = this.floorDoorsList.FirstOrDefault(door => door.id == this.floor); //filter floor door by ID and set status to OPENED if (currentDoor != null) { currentDoor.status = DoorStatus.CLOSED; } this.elevatorDoor.status = DoorStatus.CLOSED; } }
/* ******* LOGIC TO OPEN DOORS ******* */ public void openDoors() { System.Console.WriteLine(" Elevator is stopped at floor " + this.floor); System.Console.WriteLine(" Opening doors..."); System.Console.WriteLine(" Elevator doors are opened"); this.elevatorDoor.status = DoorStatus.OPENED; Door currentDoor = this.floorDoorsList.FirstOrDefault(door => door.id == this.floor); //filter floor door by ID and set status to OPENED if (currentDoor != null) { currentDoor.status = DoorStatus.OPENED; } Thread.Sleep(1000); //How many time the door remains opened in MILLISECONDS - I use 1 second so the scenarios test will run faster this.closeDoors(); }
private void SetElevatorStatus(ElevatorStatus Status) { lock (locker) //To avoid e.g. setting and getting status at the same time { this.elevatorStatus = Status; } }