1.3 is just a example from the textbook. That part is not necessary Project Desc
ID: 3839517 • Letter: 1
Question
1.3 is just a example from the textbook. That part is not necessary
Project Description
The goal of this project is to design and develop C++ code and algorithms to control a bank of elevators, which services many floors and transports people “efficiently ", that is, as per the given specifications. A second goal is to effectively employ object oriented design, through appropriate use of classes, data structures and Standard Template Libraries (STLs).
Class Design and STLs
• Person class with ID, arrival floor, destination floor and assigned elevator. An example ID for a person maybe P1A3D5, for person 1, arrival floor 3 and destination floor 5. This will make it easier to generate and track test input and output.
• Elevator class with direction, number of people and list of stops.
Think of the STL containers you will be utilizing. For example, a list allows for easy insertion and removal of elements, a vector can change size, and you can push and pop elements at the end of it, a deque allows for fast insertion and deletion of elements at both ends.
Input Data
•The input data consists of the arrivals on each floor, at time steps t = 1. 2… T Stop. At each time step, the program reads in each arriving person, for each floor, and processes this data. For example, for n = 10 floors, and at time step t = 1, the arrivals maybe P1A1D4 and P2A1D5 on floor 1, P1A3D1 and Pf2A3D7 on floor 3, and 0 on the remaining floors.
Problem Specifications
• The elevator bank has m elevators and services n floors. As an example, you may choose m = 3 and n = 10.
• Each elevator can stop at every floor.
• The direction of an elevator has three states up, down and standing. Each elevator can carry up to a max of N max persons.
• The program loops through discrete time steps t = 1; 2…T stop, where T stop is an input parameter.
• At each time step, either 0, 1 or 2 persons arrive at a floor. This information can be read from an input data file, as described in 1.3.
•An elevator takes k time step to move up or down by k floors, if it doesn't stop. For example, to move from floor 4 to floor 5 requires one time step. And to move from floor 7 to floor 3 requires 4 time steps.
• When an elevator stops at a floor, for either passenger pick up or drop off, it does so for one time step.
•When a person arrives on a floor, they are assigned the “nearest "elevator. Here nearest is defined in the number of time steps. For example, let us say a person arrives on floor 5, and wants to go up. Elevator E1 on floor 2, moving in the up direction, with no stops, is 3 time steps away. Elevator E2 on floor 6, moving in the down direction and headed for floor 3 is 6 time steps away. Therefore, the person is assigned elevator E1.
• Each arriving person has an arrival floor, destination floor and the assigned elevator as its data members.
• When a person is assigned an elevator, their arrival floor and destination floor go in the queue or the list of the elevator stops.
• Each elevator contains a list of stops, which gets updated at each time step.
• An elevator moving up (down) continues to move up (down), until it exhausts all the stops in its list.
Program Output
Generate appropriate output for a given input test data, which displays the information, that is, people getting on and off each floor, for each time step, for say 10 consecutive time steps.
Explanation / Answer
class elevator{
private:
//The Lift box the elevator controls
liftbox box;
//The total number of levels
const int LEVEL;
//The request for various floors
set<int> req;
//Triggers the search to move to the next floor if required
void moveLiftToNext();
//Instructs the lift box to move to that floor
void moveLiftTo(int);
public:
//Adds request to the queue
void addRequest(int);
//Gets the total levels the box can move
int getLevel();
//For Emergency
void setEmergency();
void unsetEmergency();
};
class liftbox{
private:
dailpad pad;
elevator ele;
int currLevel; //Current position
bool direction; //True - up ; False- Down
public:
//Instruction to move the box to certain level
void Move(int x){
if(x < 0 || x >= ele.getLevel())
return; //invalid number
//Move the lift
//update direction and currLevel
}
//returns the current level. Used by Elevator
int getCurrLevel();
//returns the current direction of movement.Used by Elevator
int getDirection();
void setEmergency(){
//Do the required
ele.setEmergency();
}
void unsetEmergency(){
ele.unsetEmergency();
}
//can passed to the elevator
void addRequest(int);
};
class dailpad{
private:
//Some DS to represent the dailpad
//Lift box is belongs to
liftbox box;
public:
void recieveCommand(int x){
//Depending on the value we can do the following
box.setEmergency();
//or
box.unsetEmergency();
//or
box.addRequest(x);
}
};
Updated Design:
class elevator{
private:
//The Lift box the elevator controls
liftboxControlUnit & mLiftBoxCtrlUnit;
//constructor
elevator(int Level=1, int NoOfBanks =1 );
//Destructor
~elevator();
//Triggers the search to move to the next floor if required
void moveLiftToNext();
public:
//Adds request to the queue
void addRequest(int FloorNumber){
//Add the request to the queue. The single button outside the elevator door
mLiftBoxCtrlUnit.addRequest(FloorNumber);
}
//For Emergency. Should be accessible to everyone !
void setEmergency();
void unsetEmergency();
};
typedef enum Direction{
UP,
DOWN
}direction;
class liftboxControlUnit{
private:
//The request for various floors
set<int> mRequestQueue;
//The various banks for the whole system
vector<Bank> mBanks;
//The total number of levels. Remains the same for one building
const int mTotalLevel;
//Instruction to move the box to certain level
void processRequest(){
//Do the logic to move the box.
}
//can passed to the elevator
void addRequest(int x){
mRequestQueue.insert(x);
}
//Can be set by elevator class
void setEmergency(){
//Do the required
//Set Emergency on all Banks
}
void unsetEmergency(){
//UnsetEmegency on all banks
}
void emergencyListener(){
//Listen to all the banks if emergency has been set
}
void BankFreeListener(){
//Listen to the banks if any is free
//If so then
processRequest();
}
public:
//Constructor
liftboxControlUnit(int TotalLevels, int NoOfBanks): mTotalLevel(TotalLevels){
for(int i=0 ; i lessthan NoOfBanks; ++ i)
mBanks.push_back(Bank(0,UP));
}
friend class elevator;
};
class Bank{
private:
//The dailpad inside the bank
dailpad & mpad;
//Current Location
int mPresentLevel;
//Current direction of movement
direction mDirection;
//Currently moving
bool mEngaged;
//Manipulate the bank
void move(int NoOfMoves){
setEngaged();
//Move the elevator
unsetEngaged();
}
//getters
int getPresentLevel() const;
int getDirection() const;
//setters
void setPresentLevel(int);
void setDirection(direction);
//Manipulate the engaged flag
bool isEngaged() const;
bool setEngaged();
bool unsetEngaged();
//For emergency
void reset();
//Dailpad Listener
void dailpadListener(){
}
public:
Bank(int StartingLevel, direction Direction): mPresentLevel(StartingLevel),
mDirection(Direction),
mEngaged(false),
mpad()
{
}
//For emergency . Should be available for all.
void SetEmergency();
void UnsetEmergency();
bool isEmergency();
friend class liftboxControlUnit;
};
class dailpad{
private:
//Some DS to represent the state . probably a 2D Array.
void renderDisplay();
public:
//Constructor
dailpad();
void getCommand(int x){
//Depending on the value we can do the following
//Make necessary changes to the display
renderDisplay();
}
friend class Bank;
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.