Elevator Scheduling pair Programming
1. Title: Design an elevator scheduling algorithm, to achieve the basic elevator scheduling function, requires four elevators, each elevator layer, and has a weight test algorithm.
2. Pre-Design preparation: To determine the end of the right, we first to the design of the problems that may be encountered in the general analysis and discussion, determined the direction of programming (Java language) and agreed to some programming specifications, syntax specification for the use of eclipse the format specification code in, other programming problems that may be encountered are communicated at any time during development. Then we have a more in-depth analysis of the topic, taking into account the various conditions of the elevator operation and to express their views, thinking about the design of appropriate algorithms to solve scheduling problems. Finally, we went online to consult a lot of information on the elevator scheduling algorithm, and downloaded some online code for reference.
3. Design : in the design encountered a lot of difficulties, not only two people cooperation is not tacit understanding of the problem, there are basic problems, the programming foundation is not solid, the most difficult is the algorithm to write, to take into account all kinds of situations, such as four elevator optimal scheduling. Finally overcome the difficulties, after looking at a lot of code, learning the ideas of others, finally the project to complete some of the basic functions.
4. Experience: Through this pair programming, let me fully understand that in the project, two people should be in advance to consider the possible problems, as soon as possible to solve the problems found, to prevent the future of the program to leave hidden trouble, in addition, in the cooperation encountered may affect the project problem should be two people to discuss, cooperation to solve, Avoid your own arbitrary cause of loss. The following are specific items:
(1) There are six categories of projects, namely:
Elevatortest Project main class, program's entrance
Elevatorframe Program main window
Elevatorpanel Program main window interface Layout
Mainpanel Elevator Layout
ControlPanel command layout and monitoring
Subpanel the interface layout and management of an elevator
(2) The main algorithm of the project:
Private Boolean ProcessInput (int[] floorstop, int num, int currentfloor,
int currentstate) {
if (CurrentState = = 1) {
if (num > Currentfloor) {
Floorstop[num] = 1;
return true;
}
} else if (CurrentState = = 2) {
if (num < Currentfloor) {
Floorstop[num] = 1;
return true;
}
} else {
Floorstop[num] = 1;
return true;
}
return false;
}
Private Boolean Isthesamefloor (int[] floorstop) {
if (floorstop[currentfloor] = = 1) {
return true;
}
return false;
}
Private Boolean IsUP (int[] floorstop) {
int i;
for (i = 1; i <=; ++i) {
if (floorstop[i] = = 1) {
Break
}
}
if (Currentfloor < i) {
return true;
} else {
return false;
}
}
Determine if the elevator is going to continue up and running
Private Boolean Isstillup (int[] floorstop, int current) {
int i;
for (i = current + 1; I <=; ++i) {
if (floorstop[i] = = 1) {
return true;
}
}
return false;
}
Determine if the elevator is going to run down
Private Boolean Isstilldown (int[] floorstop, int current) {
int i;
for (i = Current-1; i > 0; i.) {
if (floorstop[i] = = 1) {
return true;
}
}
return false;
}
Determine if the elevator is to be docked on a floor
Private Boolean isstoped (int[] floorstop, int current) {
if (floorstop[current] = = 1) {
return true;
}
return false;
}
Scheduling (one of them):
private void Isassignedtostopelevatordown (ArrayList runnableelevators) {
if (runnableelevators.size () = = 0) {
Return
}
for (int i = 0; i < downwardarray.length; ++i) {
if (downwardarray[i] = = 2) {
int nearestdistence = 999;
int nearestelevator =-1;
for (int j = 0; J < runnableelevators.size (); ++j) {
if ((Subpanel) Runnableelevators.get (j)). Getcurrentstate ()
= = 0) {
int temp =
((Subpanel) Runnableelevators.get (j))
. Getcurrentfloor ();
if (Math.Abs (i-temp) < nearestdistence) {
Nearestdistence = Math.Abs (i-temp);
Nearestelevator = j;
}
}
}
if (nearestelevator! =-1) {
(
(subpanel) Runnableelevators.get (
Nearestelevator)). Settask (
i);
Downwardarray[i] = 0;
Nearestdistence = 999;
Nearestelevator =-1;
}
}
}
}
(3) operation
The lower drop-down box is the elevator external button, you in several floors on the choice of several floors of the building number, choose to go upstairs or downstairs, the least number of floors from your elevator will be moved to your floor, enter the elevator can choose their own floor (notice elevator rise can not go to the floor below, fall can not go to the upper floor)
Github:https://github.com/mtj075/Elevator.git
An elevator scheduling algorithm for pairing programming