Compare commits
48 Commits
7649656e64
...
master
Author | SHA1 | Date | |
---|---|---|---|
7d22e586d1 | |||
55e8c1ea0f | |||
9d1796ef4c | |||
9b42c0f1c1 | |||
9a16e37d7a | |||
b6711dd7bc | |||
be70eedea3 | |||
98501165ff | |||
2972cd0e0e | |||
735aab4b30 | |||
8475ff4ee0 | |||
f53827dd4f | |||
733fd2a75e | |||
5f23f2b50b | |||
ca166b8853 | |||
9aeb29c895 | |||
5a5e0791ee | |||
069ab2bd77 | |||
7df6aef090 | |||
0e3dfd140e | |||
7a1ca1ef65 | |||
f58b035252 | |||
579f33d34e | |||
3d09306c8c | |||
2a87eee0f8 | |||
c9d9eafa3d | |||
30d5b607a7 | |||
dc78296e89 | |||
2ed258e60e | |||
0541b38e50 | |||
055979374c | |||
19d679e53b | |||
9c0836d89f | |||
4cba85c27a | |||
cc2d08f6e4 | |||
d75c088637 | |||
a2fdc0934e | |||
0b3dc7381c | |||
a9708d8d14 | |||
3463e4c8a7 | |||
724bee4117 | |||
864419c22e | |||
0d56ac1e3c | |||
27c2ffefaa | |||
9a9c128f31 | |||
771d76da3f | |||
b820f041ae | |||
483a5a8189 |
BIN
AutomateSystemControl_Motor.odg
Normal file
BIN
AutomateSystemControl_Motor.odg
Normal file
Binary file not shown.
BIN
Cahier_des_charges.odt
Normal file
BIN
Cahier_des_charges.odt
Normal file
Binary file not shown.
BIN
Cahier_des_charges.pdf
Normal file
BIN
Cahier_des_charges.pdf
Normal file
Binary file not shown.
4
Makefile
4
Makefile
@ -1,12 +1,14 @@
|
||||
all: build assemble
|
||||
|
||||
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
mkdir -p build
|
||||
javac -Xlint $(shell find src -type f -name '*.java') -d build
|
||||
|
||||
assemble:
|
||||
cd build/; jar cvmf ../MANIFEST.MF ../Elevator.jar $(shell cd build/; find -type f -name '*.class')
|
||||
cd build/; jar cvmf ../MANIFEST.MF ../Elevator.jar $(patsubst %,'%',$(shell cd build; find -name '*.class'))
|
||||
|
||||
clean:
|
||||
-rm -r build/*
|
||||
|
BIN
Specifications.odt
Executable file
BIN
Specifications.odt
Executable file
Binary file not shown.
1
diag_Elevator.drawio
Normal file
1
diag_Elevator.drawio
Normal file
@ -0,0 +1 @@
|
||||
<mxfile host="www.draw.io" modified="2019-10-19T11:10:49.617Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0" etag="bc-bvE1HKCYPkqLAi2Dp" version="12.1.3" type="device" pages="1"><diagram name="Page-1" id="929967ad-93f9-6ef4-fab6-5d389245f69c">7Vxtc6M4DP41nel9aAdCIMnHJmn3dqbb6V739uWjAy7xLWAOnCbZX38ymBdjJyFpSDt76XTaWNgCpEeyJKu9sCbh6kOC4vkn6uHgomd4qwtretHrmUavD784ZZ1TbMPOCX5CPDGpIjyRX7hYKagL4uFUmsgoDRiJZaJLowi7TKKhJKFLedozDeS7xsjHCuHJRUFBvbYr+jfisbmgm86ouvAnJv5c3HzYc/ILM+T+9BO6iMQdIxrh/EqICjbiLdM58uiyRrJuL6xJQinLP4WrCQ64YAuZFevYunjQC2s8Z2EAAxM+ZpfvNiw22yyG90pwxOq328TvarX+/vCL9R68n99W6PPX9T+r1ZWVc3lBwULc5ImEiwAxQiPl/umShAEC8VjjZxqxJ3GFPwwKiB/BZxceBidAeMEJI6CgG3GB0Rio7pwE3j1a0wV/5JSB7IvReE4T8gvYouIF4XLCBNZAW/UZT3wlkA2gJjiFOY+FHMwG6RNaSRPvUcoEwaVBgOKUzMrXCFHik2hMGaOhmMTf9A6FJOCmMaGLhMD79YwHvNTqQGiNvz5e1UhCJx8wDTFL1jBFXLWdYb5EmN7AElBeVjAGe8xp8xqCTUsQkTAev+RdoQA+CCDsAYq+AoorGP67wDAEkFk38PNjlLJk4XKcfM4vgD1ZqxsQCp+MA/yCGE3K+bclQZrnLhIu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al file
Binary file not shown.
1
diag_Event.drawio
Normal file
1
diag_Event.drawio
Normal file
@ -0,0 +1 @@
|
||||
<mxfile host="www.draw.io" modified="2019-10-19T10:41:19.971Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0" etag="fBNO9_0xkaawxpGQ27Aw" version="12.1.3" type="device" pages="1"><diagram name="Page-1" id="929967ad-93f9-6ef4-fab6-5d389245f69c">7VtZb9s4EP41BnYfElinlcfYTroLtEW2KbbtIy0xNreU6KXoRO6v36FE3fSlWHaCNWAg5ogcijPfnGYG1iRMPnC0XHxiAaYDcxgkA2s6ME1jaNrwR1LWGcWxbjLCnJNATSoJj+QXzlcq6ooEOK5NFIxRQZZ1os+iCPuiRkOcs5f6tCdG67su0Ry3CI8+ojn12inp30ggFopuuDflgz8wmS/U5p7pZg9myP8552wVqR0jFuHsSYhyNuqU8QIF7KVCsu4G1oQzJrJvYTLBVAo2l1m+TqzzFx1Y44UIKQwM+Jo+vt+w2NhnMZyL40hUt9vE7ypZf//8S5ifg5/fEvTX3+t/kuTKyrg8I7pSm3zByF/g4J4yxu+eJe/ma8QvJKQIpGSNn1gkHtUT+U6IknkE331YhzkQnjEXBPR0qx4ItgSqvyA0+IjWbCXfPBaggnw0XjBOfgFblJ8THnOhIAdKq854lCuBPAQqxzHMecjFYTRIn1BSm/gRxUIRfEYpWsZkVhwjRHxOojETgoVqkjzpPQoJlRYyYStO4Hzm8DN+0apCKU8eHycVklLNB8xCLPgapiS5xSmwKAt0bYXolxLNpqPmLCpAdj1lRsqE5gXrEgvwRcHhAGjYLWhcSQtecXnKFB4wHFi3ko9ECdiTldyCNCrTpoSDuRMWFVMrlGJBC2EgM5FqnrOfeMIobGVNU8MERRBKG6QcdRQ/iY2Yi5fIJ9H8YzpnapeUL0qWksRg7RNNbXxBggBHEi9MIIEycEgkLBkcNxW2M4YPqGQyBPfjwItPYGyUY/jI6VxMWARnQSRFBwbkvWCJvkNBtdWCdyN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5r2ACV19Xdei13e+q0V3fFMLu/Q4orb9EqrFzqIc2LPuXVn0rzt4Hx7rd9Xt1xL26KV5FgaCpfZ7gZCK8rfdsd91cIuXIn7u0I2XbbraXTCtk+LNn1KYpj4nfyoFX3WW0i7PCgtRT2ens19goH2mfbQHf72empk+B17CSYxnk7CfZhGezxgPjGcNhnsf//xiEMy3+iy6aX/6Zo3f0H</diagram></mxfile>
|
BIN
diag_Event.pdf
Normal file
BIN
diag_Event.pdf
Normal file
Binary file not shown.
1905
diag_classes.uml
Normal file
1905
diag_classes.uml
Normal file
File diff suppressed because it is too large
Load Diff
42
src/Events/CallFromElevatorEvent.java
Normal file
42
src/Events/CallFromElevatorEvent.java
Normal file
@ -0,0 +1,42 @@
|
||||
package Events;
|
||||
|
||||
import commandSystem.Direction;
|
||||
|
||||
public class CallFromElevatorEvent implements Event {
|
||||
|
||||
private final int requestedFloor;
|
||||
|
||||
public CallFromElevatorEvent(int requestedFloor) {
|
||||
this.requestedFloor = requestedFloor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getRequestedDirection() {
|
||||
return Direction.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequestedFloor() {
|
||||
return requestedFloor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIncomingCallFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType() {
|
||||
return EventType.CALLFROMELEVATOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getCurrentDirection() {
|
||||
return Direction.NONE;
|
||||
}
|
||||
}
|
46
src/Events/CallFromFloorEvent.java
Normal file
46
src/Events/CallFromFloorEvent.java
Normal file
@ -0,0 +1,46 @@
|
||||
package Events;
|
||||
|
||||
import commandSystem.Direction;
|
||||
|
||||
public class CallFromFloorEvent implements Event {
|
||||
|
||||
|
||||
private final int incomingCallFloor;
|
||||
private final Direction direction;
|
||||
|
||||
public CallFromFloorEvent(int incomingCallFloor, Direction direction) {
|
||||
this.incomingCallFloor = incomingCallFloor;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getRequestedDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequestedFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIncomingCallFloor() {
|
||||
return incomingCallFloor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType() {
|
||||
return EventType.CALLFROMFLOOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getCurrentDirection() {
|
||||
return Direction.NONE;
|
||||
}
|
||||
|
||||
}
|
40
src/Events/CancelEmergencyStopEvent.java
Normal file
40
src/Events/CancelEmergencyStopEvent.java
Normal file
@ -0,0 +1,40 @@
|
||||
package Events;
|
||||
|
||||
import commandSystem.Direction;
|
||||
|
||||
public class CancelEmergencyStopEvent implements Event{
|
||||
|
||||
public CancelEmergencyStopEvent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getRequestedDirection() {
|
||||
return Direction.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequestedFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIncomingCallFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType() {
|
||||
return EventType.CANCELEMERGENCYSTOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getCurrentDirection() {
|
||||
return Direction.NONE;
|
||||
}
|
||||
|
||||
}
|
39
src/Events/EmergencyStopEvent.java
Normal file
39
src/Events/EmergencyStopEvent.java
Normal file
@ -0,0 +1,39 @@
|
||||
package Events;
|
||||
|
||||
import commandSystem.Direction;
|
||||
|
||||
public class EmergencyStopEvent implements Event {
|
||||
|
||||
public EmergencyStopEvent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getRequestedDirection() {
|
||||
return Direction.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequestedFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIncomingCallFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType() {
|
||||
return EventType.EMERGENCYSTOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getCurrentDirection() {
|
||||
return Direction.NONE;
|
||||
}
|
||||
}
|
76
src/Events/Event.java
Normal file
76
src/Events/Event.java
Normal file
@ -0,0 +1,76 @@
|
||||
package Events;
|
||||
|
||||
import commandSystem.Direction;
|
||||
|
||||
public interface Event {
|
||||
|
||||
/**
|
||||
* Gets the EventType associated with the event
|
||||
*
|
||||
* @return the EventType of the event.
|
||||
*/
|
||||
public EventType getType();
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* CallFromFloorEvent methods
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the direction of a floor call.
|
||||
*
|
||||
* @return the direction of the floor call, unconcerned extending classes return
|
||||
* NONE.
|
||||
*/
|
||||
public Direction getRequestedDirection();
|
||||
|
||||
/**
|
||||
* Gets the source floor of a floor call.
|
||||
*
|
||||
* @return the floor the event was called from, unconcerned extending classes
|
||||
* return -1.
|
||||
*/
|
||||
public int getIncomingCallFloor();
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* CallFromElevatorEvent methods
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the requested floor of an inside-elevator call.
|
||||
*
|
||||
* @return the requested floor, unconcerned extending classes return -1.
|
||||
*/
|
||||
public int getRequestedFloor();
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* ReachedFloorEvent methods
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the index of the floor just reached.
|
||||
*
|
||||
* @return the floor the elevator just reached, unconcerned extending classes
|
||||
* return -1.
|
||||
*/
|
||||
public int getCurrentFloor();
|
||||
|
||||
/**
|
||||
* Gets the direction the elevator reached the last floor from.
|
||||
*
|
||||
* @return the direction of the elevator. Unconcerned extending classes return
|
||||
* NONE.
|
||||
*/
|
||||
public Direction getCurrentDirection();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package Requests;
|
||||
package Events;
|
||||
|
||||
public enum RequestType {
|
||||
CALLFROMFLOOR, CALLFROMELEVATOR, EMERGENCYSTOP, CANCELEMERGENCYSTOP
|
||||
public enum EventType {
|
||||
CALLFROMFLOOR, CALLFROMELEVATOR, EMERGENCYSTOP, CANCELEMERGENCYSTOP, REACHEDFLOORSIGNAL
|
||||
}
|
46
src/Events/ReachedFloorEvent.java
Normal file
46
src/Events/ReachedFloorEvent.java
Normal file
@ -0,0 +1,46 @@
|
||||
package Events;
|
||||
|
||||
import commandSystem.Direction;
|
||||
|
||||
public class ReachedFloorEvent implements Event{
|
||||
|
||||
private final int currentFloor;
|
||||
private final Direction currentDirection;
|
||||
|
||||
public ReachedFloorEvent(int currentFloor, Direction currentDirection) {
|
||||
this.currentFloor = currentFloor;
|
||||
this.currentDirection = currentDirection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getRequestedDirection() {
|
||||
return Direction.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequestedFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIncomingCallFloor() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType() {
|
||||
return EventType.REACHEDFLOORSIGNAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentFloor() {
|
||||
return currentFloor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getCurrentDirection() {
|
||||
return currentDirection;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package Requests;
|
||||
|
||||
public class CallFromElevatorRequest extends Request {
|
||||
|
||||
public CallFromElevatorRequest(int wantedFloor) {
|
||||
super();
|
||||
this.wantedFloor = wantedFloor;
|
||||
this.type = RequestType.CALLFROMELEVATOR;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package Requests;
|
||||
|
||||
import commandSystem.Direction;
|
||||
|
||||
public class CallFromFloorRequest extends Request {
|
||||
|
||||
|
||||
public CallFromFloorRequest(int sourceFloor, Direction direction) {
|
||||
super();
|
||||
this.sourceFloor = sourceFloor;
|
||||
this.direction = direction;
|
||||
this.type = RequestType.CALLFROMFLOOR;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package Requests;
|
||||
|
||||
public class EmergencyStopRequest extends Request {
|
||||
|
||||
public EmergencyStopRequest() {
|
||||
super();
|
||||
this.type = RequestType.EMERGENCYSTOP;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package Requests;
|
||||
|
||||
import commandSystem.Direction;
|
||||
|
||||
public abstract class Request {
|
||||
|
||||
protected RequestType type;
|
||||
protected int wantedFloor;
|
||||
protected int sourceFloor;
|
||||
protected Direction direction;
|
||||
|
||||
public Request() {
|
||||
this.wantedFloor = -1;
|
||||
this.sourceFloor = -1;
|
||||
this.direction = Direction.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the direction of the request, unconcerned extending classes return NONE
|
||||
*/
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the wished floor, unconcerned extending classes return -1
|
||||
*/
|
||||
public int getWantedFloor() {
|
||||
return wantedFloor;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the floor it was called from, unconcerned extending classes return -1
|
||||
*/
|
||||
public int getIncomingCallFloor() {
|
||||
return sourceFloor;
|
||||
}
|
||||
|
||||
|
||||
public RequestType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
224
src/commandSystem/BasicInstructionQueue.java
Normal file
224
src/commandSystem/BasicInstructionQueue.java
Normal file
@ -0,0 +1,224 @@
|
||||
package commandSystem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import Events.Event;
|
||||
import Events.EventType;
|
||||
|
||||
public class BasicInstructionQueue implements InstructionQueue {
|
||||
private ArrayList<Integer> upQueue = new ArrayList<>();
|
||||
private ArrayList<Integer> downQueue = new ArrayList<>();
|
||||
private boolean emergencyState;
|
||||
|
||||
private int currentFloor;
|
||||
private Direction currentDirection;
|
||||
|
||||
public BasicInstructionQueue() {
|
||||
|
||||
upQueue = new ArrayList<Integer>();
|
||||
downQueue = new ArrayList<Integer>();
|
||||
emergencyState = false;
|
||||
currentFloor = 0;
|
||||
currentDirection = Direction.UP;
|
||||
}
|
||||
|
||||
public boolean computeEvent(Event event) {
|
||||
boolean haveToWait = false;
|
||||
|
||||
/*
|
||||
* Emergency state prevents any event from affecting the queue except the cancel
|
||||
* emergency stop event.
|
||||
*/
|
||||
if (emergencyState && event.getType() != EventType.CANCELEMERGENCYSTOP)
|
||||
return haveToWait;
|
||||
|
||||
switch (event.getType()) {
|
||||
|
||||
/*
|
||||
* The elevator will have to stop at this floor when it's headed in the same
|
||||
* direction the call is directed to.
|
||||
*/
|
||||
case CALLFROMFLOOR:
|
||||
if (currentFloor == event.getIncomingCallFloor())
|
||||
break;
|
||||
switch (event.getRequestedDirection()) {
|
||||
/*
|
||||
* Adds the instruction to the upQueue then sorts it.
|
||||
*/
|
||||
case UP:
|
||||
if (!upQueue.contains(event.getIncomingCallFloor()))
|
||||
appSort(upQueue, event.getIncomingCallFloor(), false);
|
||||
break;
|
||||
|
||||
/*
|
||||
* Adds the instruction to the downQueue then sorts it.
|
||||
*/
|
||||
case DOWN:
|
||||
if (!downQueue.contains(event.getIncomingCallFloor()))
|
||||
appSort(downQueue, event.getIncomingCallFloor(), true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* If the requested floor is under the elevator, adds the instruction to the
|
||||
* downQueue then sorts it. if it's above, adds the instruction to the upQueue
|
||||
* then sorts it. If it's the same floor, doesn't do anything.
|
||||
*/
|
||||
case CALLFROMELEVATOR:
|
||||
if (event.getRequestedFloor() > currentFloor && !upQueue.contains(event.getRequestedFloor()))
|
||||
appSort(upQueue, event.getRequestedFloor(), false);
|
||||
else if (event.getRequestedFloor() < currentFloor && !upQueue.contains(event.getRequestedFloor()))
|
||||
appSort(downQueue, event.getRequestedFloor(), true);
|
||||
break;
|
||||
|
||||
/*
|
||||
* Puts emergencyState to true. Blocks every event from affecting the queue and
|
||||
* clears it.
|
||||
*/
|
||||
case EMERGENCYSTOP:
|
||||
emergencyState = true;
|
||||
clearQueues();
|
||||
break;
|
||||
|
||||
/*
|
||||
* Puts emergencyState to false. Unblocks events.
|
||||
*/
|
||||
case CANCELEMERGENCYSTOP:
|
||||
emergencyState = false;
|
||||
break;
|
||||
/*
|
||||
* Refreshes the local values of current floor and current rrentFloodirection with the
|
||||
* ones given by the event. These values will
|
||||
*/
|
||||
case REACHEDFLOORSIGNAL:
|
||||
currentFloor = event.getCurrentFloor();
|
||||
currentDirection = event.getCurrentDirection();
|
||||
if (currentFloor == getNextInstruction()) {
|
||||
removeInstruction(currentFloor);
|
||||
haveToWait = true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return haveToWait;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next floor the elevator has to go to
|
||||
*
|
||||
* @return the next floor if it exists, else -1
|
||||
*/
|
||||
public int getNextInstruction() {
|
||||
int nextFloor = -1;
|
||||
|
||||
// System.out.println("we go " + currentDirection + " current floor: " + currentFloor + " queues: " + upQueue + downQueue);
|
||||
|
||||
switch (currentDirection) {
|
||||
// get the first element of upQueue that is ABOVE the elevator's current floor
|
||||
case UP:
|
||||
for (int i = 0; i < upQueue.size() && nextFloor < 0; i++) {
|
||||
if (upQueue.get(i) >= currentFloor) {
|
||||
nextFloor = upQueue.get(i);
|
||||
}
|
||||
}
|
||||
// change direction if every floor in upQueue is UNDER the elevator's current
|
||||
// floor
|
||||
if (nextFloor < 0 && downQueue.size() > 0) {
|
||||
nextFloor = downQueue.get(0);
|
||||
}
|
||||
if (nextFloor < 0 && upQueue.size() > 0) {
|
||||
nextFloor = upQueue.get(0);
|
||||
}
|
||||
break;
|
||||
|
||||
// get the first element of downQueue that is UNDER the elevator's current floor
|
||||
case DOWN:
|
||||
for (int i = 0; i < downQueue.size() && nextFloor < 0; i++) {
|
||||
if (downQueue.get(i) <= currentFloor) {
|
||||
nextFloor = downQueue.get(i);
|
||||
}
|
||||
}
|
||||
// change direction if every floor in downQueue is ABOVE the elevator's current
|
||||
// floor
|
||||
if (nextFloor < 0 && upQueue.size() > 0) {
|
||||
nextFloor = upQueue.get(0);
|
||||
}
|
||||
if (nextFloor < 0 && downQueue.size() > 0) {
|
||||
nextFloor = downQueue.get(0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return nextFloor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new floor to the argument's <b>queue</b> then sorts the elements.
|
||||
*
|
||||
* @param queue the list to be sorted.
|
||||
* @param floor the index of the floor that will be added.
|
||||
* @param reversed if set to true, the queue will be sorted by descending order.
|
||||
*/
|
||||
private void appSort(ArrayList<Integer> queue, int floor, boolean reversed) {
|
||||
queue.add(floor);
|
||||
if (reversed)
|
||||
Collections.sort(queue, Collections.reverseOrder());
|
||||
else
|
||||
Collections.sort(queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes one instruction from the queue - has to be called when the elevator
|
||||
* reaches targeted floor.
|
||||
*
|
||||
* @param floor the reached floor.
|
||||
* @param currentDirection the direction of the elevator.
|
||||
*/
|
||||
private void removeInstruction(int floor) {
|
||||
switch (currentDirection) {
|
||||
|
||||
/* current floor: 0 queues: [0, 1, 2, 3][4, 3, 2, 1]
|
||||
Next instruction: 0
|
||||
* Elevator is headed upwards.
|
||||
*/
|
||||
case UP:
|
||||
if (upQueue.contains(floor))
|
||||
upQueue.remove(upQueue.indexOf(floor));
|
||||
else
|
||||
downQueue.remove(downQueue.indexOf(floor));
|
||||
break;
|
||||
|
||||
/*
|
||||
* Elevator is headed downwards.
|
||||
*/
|
||||
case DOWN:
|
||||
if (downQueue.contains(floor))
|
||||
downQueue.remove(downQueue.indexOf(floor));
|
||||
else
|
||||
upQueue.remove(upQueue.indexOf(floor));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// eliminate floor if next instruction is floor because already satisfied
|
||||
if (getNextInstruction() == floor) {
|
||||
removeInstruction(floor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears both queues.
|
||||
*/
|
||||
private void clearQueues() {
|
||||
downQueue.removeAll(downQueue);
|
||||
upQueue.removeAll(upQueue);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package commandSystem;
|
||||
|
||||
public interface Elevator {
|
||||
|
||||
|
||||
public void sendFloorReachedNotification();
|
||||
public int getCurrentFloor();
|
||||
public Direction getCurrentDirection();
|
||||
}
|
@ -5,4 +5,6 @@ public interface ElevatorListener {
|
||||
public void elevatorCall(int floor);
|
||||
public void floorCall(int floor, Direction direction);
|
||||
public void floorChange(Direction direction);
|
||||
public void emergency();
|
||||
public void cancelEmergency();
|
||||
}
|
||||
|
@ -1,160 +0,0 @@
|
||||
package commandSystem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import Requests.Request;
|
||||
|
||||
// emergencyStop -> clear the queue
|
||||
|
||||
public class EventQueue {
|
||||
private ArrayList<Integer> upQueue = new ArrayList<>();
|
||||
private ArrayList<Integer> downQueue = new ArrayList<>();
|
||||
private boolean emergencyState;
|
||||
private Elevator elevator;
|
||||
|
||||
public EventQueue(Elevator elevator) {
|
||||
|
||||
this.elevator = elevator;
|
||||
upQueue = new ArrayList<Integer>();
|
||||
downQueue = new ArrayList<Integer>();
|
||||
emergencyState = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new floor to <b>queue</b> queue and sort it to keep floors order
|
||||
*
|
||||
* @param queue ArrayList<Int>
|
||||
* @param floor int - the floor we add to queue
|
||||
* @param reversed boolean - reverse queue order
|
||||
*/
|
||||
public void appSort(ArrayList<Integer> queue, int floor, boolean reversed) {
|
||||
queue.add(floor);
|
||||
if (reversed)
|
||||
Collections.sort(queue, Collections.reverseOrder());
|
||||
else
|
||||
Collections.sort(queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute a request into the {@link #EventQueue} depending on the elevator
|
||||
* status
|
||||
*
|
||||
* @param request - the request to compute
|
||||
*/
|
||||
public void computeRequest(Request request) {
|
||||
|
||||
switch (request.getType()) {
|
||||
case CALLFROMFLOOR:
|
||||
if (emergencyState)
|
||||
return;
|
||||
switch (request.getDirection()) {
|
||||
case UP:
|
||||
if (!upQueue.contains(request.getIncomingCallFloor()))
|
||||
appSort(upQueue, request.getIncomingCallFloor(), false);
|
||||
break;
|
||||
case DOWN:
|
||||
if (!downQueue.contains(request.getIncomingCallFloor()))
|
||||
appSort(downQueue, request.getIncomingCallFloor(), true);
|
||||
break;
|
||||
default:
|
||||
System.out.println("foiop");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CALLFROMELEVATOR:
|
||||
if (emergencyState)
|
||||
return;
|
||||
if (request.getWantedFloor() > elevator.getCurrentFloor() && !upQueue.contains(request.getWantedFloor()))
|
||||
appSort(upQueue, request.getWantedFloor(), false);
|
||||
else if (request.getWantedFloor() < elevator.getCurrentFloor()
|
||||
&& !upQueue.contains(request.getWantedFloor()))
|
||||
appSort(downQueue, request.getWantedFloor(), true);
|
||||
break;
|
||||
case EMERGENCYSTOP:
|
||||
if (emergencyState)
|
||||
return;
|
||||
emergencyState = true;
|
||||
clearQueue();
|
||||
break;
|
||||
case CANCELEMERGENCYSTOP:
|
||||
emergencyState = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* removes one instruction from the queue - call when the elevator reaches
|
||||
* targeted floor
|
||||
*
|
||||
* @param reachedFloor
|
||||
* @param direction of elevators
|
||||
*/
|
||||
public void removeInstruction(int reachedFloor, Direction direction) {
|
||||
switch (direction) {
|
||||
case UP:
|
||||
if (upQueue.contains(reachedFloor))
|
||||
upQueue.remove(upQueue.indexOf(reachedFloor));
|
||||
else // we go up to the top of descending queue
|
||||
downQueue.remove(downQueue.indexOf(reachedFloor));
|
||||
break;
|
||||
case DOWN:
|
||||
if (downQueue.contains(reachedFloor))
|
||||
downQueue.remove(downQueue.indexOf(reachedFloor));
|
||||
else // we go down to the bottom of ascending queue
|
||||
upQueue.remove(upQueue.indexOf(reachedFloor));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the next floor the elevator has to go to
|
||||
*
|
||||
* @return next floor if exists else -1
|
||||
*/
|
||||
public int getNextInstruction() {
|
||||
//System.out.println("" + upQueue + '\n' + downQueue);
|
||||
int nextFloor = -1;
|
||||
switch (elevator.getCurrentDirection()) {
|
||||
// get first element of upQueue that is ABOVE the elevator's current floor
|
||||
case UP:
|
||||
for (int i = 0; i < upQueue.size() && nextFloor < 0; i++) {
|
||||
if (upQueue.get(i) >= elevator.getCurrentFloor()) {
|
||||
nextFloor = upQueue.get(i);
|
||||
}
|
||||
}
|
||||
// change direction if every floor in upQueue is UNDER the elevator's current
|
||||
// floor
|
||||
if (nextFloor < 0 && downQueue.size() > 0) {
|
||||
nextFloor = downQueue.get(0);
|
||||
}
|
||||
break;
|
||||
|
||||
// get first element of downQueue that is UNDER the elevator's current floor
|
||||
case DOWN:
|
||||
for (int i = 0; i < downQueue.size() && nextFloor < 0; i++) {
|
||||
if (downQueue.get(i) <= elevator.getCurrentFloor()) {
|
||||
nextFloor = downQueue.get(i);
|
||||
}
|
||||
}
|
||||
// change direction if every floor in downQueue is ABOVE the elevator's current
|
||||
// floor
|
||||
if (nextFloor < 0 && upQueue.size() > 0) {
|
||||
nextFloor = upQueue.get(0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return nextFloor;
|
||||
}
|
||||
|
||||
public void clearQueue() {
|
||||
downQueue.removeAll(downQueue);
|
||||
upQueue.removeAll(upQueue);
|
||||
}
|
||||
}
|
21
src/commandSystem/InstructionQueue.java
Normal file
21
src/commandSystem/InstructionQueue.java
Normal file
@ -0,0 +1,21 @@
|
||||
package commandSystem;
|
||||
|
||||
import Events.Event;
|
||||
|
||||
public interface InstructionQueue {
|
||||
|
||||
/**
|
||||
* Compute a request into the instruction queue.
|
||||
*
|
||||
* @param event - the request to compute
|
||||
* @return true if the elevator have to wait at floor
|
||||
*/
|
||||
public boolean computeEvent(Event event);
|
||||
|
||||
/**
|
||||
* Returns the next floor the elevator has to go to.
|
||||
*
|
||||
* @return the next floor if it exists, else -1
|
||||
*/
|
||||
public int getNextInstruction();
|
||||
}
|
@ -1,49 +1,55 @@
|
||||
package commandSystem;
|
||||
|
||||
import Requests.CallFromElevatorRequest;
|
||||
import Requests.CallFromFloorRequest;
|
||||
import Events.CallFromElevatorEvent;
|
||||
import Events.CallFromFloorEvent;
|
||||
import Events.ReachedFloorEvent;
|
||||
|
||||
public class Test {
|
||||
|
||||
private static boolean running = false;
|
||||
private static EventQueue queue;
|
||||
private static InstructionQueue queue;
|
||||
|
||||
private static TestElevator elevator = new TestElevator();
|
||||
private static Direction currentDirection = Direction.UP;
|
||||
private static int currentFloor = 0;
|
||||
|
||||
public static void iter() {
|
||||
int nextDestination = queue.getNextInstruction();
|
||||
//System.out.println("next dest = " + nextDestination);
|
||||
|
||||
if (!running) {
|
||||
if (nextDestination > 0) { // return -1 if no next destination
|
||||
// would be -1 if the queue doesn't have any next instruction
|
||||
|
||||
//System.out.println("next dest : " + nextDestination);
|
||||
if (nextDestination != -1) {
|
||||
running = true;
|
||||
elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
|
||||
currentDirection = currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
|
||||
}
|
||||
} else {
|
||||
if (elevator.currentFloor == nextDestination) {
|
||||
queue.removeInstruction(elevator.currentFloor, elevator.direction);
|
||||
//System.out.println("not running");
|
||||
// if we just reached a new floor
|
||||
if (currentFloor == nextDestination) {
|
||||
queue.computeEvent(new ReachedFloorEvent(currentFloor, currentDirection));
|
||||
running = false;
|
||||
} else {
|
||||
elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
|
||||
elevator.currentFloor += elevator.direction == Direction.UP ? 1 : -1;
|
||||
currentDirection = currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
|
||||
currentFloor += currentDirection == Direction.UP ? 1 : -1;
|
||||
}
|
||||
}
|
||||
System.out.println("elevator floor " + elevator.currentFloor + " direction " +
|
||||
(elevator.direction == Direction.UP? "up" : "down") + " running: " + running);
|
||||
System.out.println("elevator floor " + currentFloor + " direction " +
|
||||
(currentDirection) + " running: " + running);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
queue = new EventQueue(elevator);
|
||||
queue = new BasicInstructionQueue();
|
||||
iter();
|
||||
iter();
|
||||
queue.computeRequest(new CallFromFloorRequest(2, Direction.DOWN));
|
||||
iter();
|
||||
queue.computeEvent(new CallFromFloorEvent(2, Direction.DOWN));
|
||||
System.out.println("someone calls from floor 2 to go down");
|
||||
iter();
|
||||
queue.computeRequest(new CallFromFloorRequest(1, Direction.UP));
|
||||
queue.computeEvent(new CallFromFloorEvent(1, Direction.UP));
|
||||
System.out.println("someone calls from floor 1 to go up");
|
||||
iter();
|
||||
|
||||
queue.computeRequest(new CallFromElevatorRequest(5));
|
||||
queue.computeEvent(new CallFromElevatorEvent(5));
|
||||
System.out.println("the guy who entered calls for floor 5");
|
||||
|
||||
iter();
|
||||
|
@ -1,30 +0,0 @@
|
||||
package commandSystem;
|
||||
|
||||
public class TestElevator implements Elevator{
|
||||
|
||||
public int currentFloor;
|
||||
public Direction direction;
|
||||
|
||||
public TestElevator() {
|
||||
this.direction = Direction.UP;
|
||||
this.currentFloor = 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendFloorReachedNotification() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentFloor() {
|
||||
return currentFloor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getCurrentDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
package gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import Requests.CallFromElevatorRequest;
|
||||
import Requests.CallFromFloorRequest;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import simulation.Elevator;
|
||||
import simulation.Simulation;
|
||||
|
||||
@ -23,7 +26,8 @@ public class ElevatorApplication implements ActionListener {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
canvas.setElevatorY((canvas.getElevatorY() + 1) % canvas.getHeight());
|
||||
elevator.update();
|
||||
canvas.repaint();
|
||||
}
|
||||
|
||||
private void createAndShowGUI() {
|
||||
@ -39,13 +43,15 @@ public class ElevatorApplication implements ActionListener {
|
||||
canvas.setAlignmentY(Component.TOP_ALIGNMENT);
|
||||
pane.add(canvas);
|
||||
|
||||
pane.add(Box.createRigidArea(new Dimension(40, 0)));
|
||||
|
||||
FloorPanels fp = new FloorPanels(5, simulation);
|
||||
fp.setAlignmentY(Component.TOP_ALIGNMENT);
|
||||
pane.add(fp);
|
||||
|
||||
pane.add(Box.createRigidArea(new Dimension(20, 0)));
|
||||
pane.add(Box.createRigidArea(new Dimension(40, 0)));
|
||||
|
||||
ElevatorPanel elevatorPanel = new ElevatorPanel(5);
|
||||
ElevatorPanel elevatorPanel = new ElevatorPanel(5, simulation);
|
||||
elevatorPanel.setAlignmentY(Component.TOP_ALIGNMENT);
|
||||
pane.add(elevatorPanel);
|
||||
|
||||
|
@ -9,9 +9,8 @@ import commandSystem.Direction;
|
||||
class ElevatorCanvas extends JPanel {
|
||||
private final static int WIDTH = 40;
|
||||
private final static int HEIGHT = 50;
|
||||
private final static Dimension DIMENSIONS = new Dimension(WIDTH, 200);
|
||||
private final static Dimension DIMENSIONS = new Dimension(WIDTH, 300);
|
||||
|
||||
private int y = 0;
|
||||
private Elevator elevator;
|
||||
|
||||
public ElevatorCanvas(Elevator elevator) {
|
||||
@ -34,27 +33,27 @@ class ElevatorCanvas extends JPanel {
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (elevator.getStoppingNextFloor()) {
|
||||
if (elevator.getEmergency()) {
|
||||
g.setColor(Color.RED);
|
||||
}
|
||||
else if (elevator.getStoppingNextFloor()) {
|
||||
g.setColor(Color.BLUE);
|
||||
}
|
||||
else if (elevator.getDirection() == Direction.NONE) {
|
||||
g.setColor(Color.GRAY);
|
||||
}
|
||||
else if (elevator.getEmergency()) {
|
||||
g.setColor(Color.RED);
|
||||
g.setColor(Color.GREEN);
|
||||
}
|
||||
else {
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
g.fillRect(0, y, WIDTH, HEIGHT);
|
||||
}
|
||||
g.fillRect(0, (int) DIMENSIONS.getHeight() - HEIGHT - (int) (((int) DIMENSIONS.getHeight() - HEIGHT) * elevator.getHeight()), WIDTH, HEIGHT);
|
||||
|
||||
public void setElevatorY(int y) {
|
||||
this.y = y;
|
||||
repaint();
|
||||
}
|
||||
g.setColor(Color.GRAY);
|
||||
int nbFloors = elevator.getNbFloors();
|
||||
for (int i = 0; i < nbFloors; i++) {
|
||||
int y = HEIGHT + i * ((int) (DIMENSIONS.getHeight() - HEIGHT) / (nbFloors - 1));
|
||||
g.fillRect(0, y-1, WIDTH, 3);
|
||||
}
|
||||
|
||||
public int getElevatorY() {
|
||||
return y;
|
||||
Toolkit.getDefaultToolkit().sync();
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,46 @@
|
||||
package gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import commandSystem.ElevatorListener;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class ElevatorPanel extends JPanel {
|
||||
private JButton emergencyStop = new JButton("Emergency stop.");
|
||||
private JButton cancelEmergencyStop = new JButton("Cancel emergency stop.");
|
||||
private JButton[] buttons;
|
||||
|
||||
public ElevatorPanel(int nbFloors) {
|
||||
public ElevatorPanel(int nbFloors, ElevatorListener l) {
|
||||
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
||||
this.add(new JLabel("Elevator panel."));
|
||||
|
||||
buttons = new JButton[nbFloors];
|
||||
for (int i = 0; i < nbFloors; i++) {
|
||||
for (int i = nbFloors-1; i >= 0; i--) {
|
||||
final int j = i;
|
||||
buttons[i] = new JButton("" + i);
|
||||
buttons[i].addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
l.elevatorCall(j);
|
||||
}
|
||||
});
|
||||
this.add(buttons[i]);
|
||||
this.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||
}
|
||||
emergencyStop.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
l.emergency();
|
||||
}
|
||||
});
|
||||
add(emergencyStop);
|
||||
}
|
||||
|
||||
public void addEmergencyStopListener(ActionListener l) {
|
||||
emergencyStop.addActionListener(l);
|
||||
this.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||
cancelEmergencyStop.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
l.cancelEmergency();
|
||||
}
|
||||
});
|
||||
add(cancelEmergencyStop);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import commandSystem.ElevatorListener;
|
||||
import commandSystem.Direction;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@ -17,19 +18,34 @@ class FloorPanels extends JPanel {
|
||||
floors = new JPanel[nbFloors];
|
||||
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
|
||||
this.add(new JLabel("Call."));
|
||||
for (int i = 0; i < nbFloors; i++) {
|
||||
for (int i = nbFloors-1; i >= 0; i--) {
|
||||
floors[i] = new JPanel();
|
||||
floors[i].setLayout(new BoxLayout(floors[i], BoxLayout.LINE_AXIS));
|
||||
floors[i].add(new JLabel("" + (i + 1)));
|
||||
floors[i].add(new JLabel("" + i));
|
||||
floors[i].add(Box.createRigidArea(new Dimension(5, 0)));
|
||||
if (i < nbFloors - 1) {
|
||||
final int j = i;
|
||||
JButton upButton = new JButton("↑");
|
||||
upButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
l.floorCall(j, Direction.UP);
|
||||
}
|
||||
});
|
||||
floors[i].add(upButton);
|
||||
floors[i].add(Box.createRigidArea(new Dimension(5, 0)));
|
||||
}
|
||||
if (i > 1) {
|
||||
if (i > 0) {
|
||||
final int j = i;
|
||||
JButton downButton = new JButton("↓");
|
||||
downButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
l.floorCall(j, Direction.DOWN);
|
||||
}
|
||||
});
|
||||
floors[i].add(downButton);
|
||||
}
|
||||
this.add(floors[i]);
|
||||
this.add(Box.createRigidArea(new Dimension(0, 5)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,21 +8,24 @@ import commandSystem.ElevatorListener;
|
||||
|
||||
|
||||
public class Elevator {
|
||||
static final int PRECISION = 10;
|
||||
static final int PRECISION = 100;
|
||||
private double floorHeight;
|
||||
private double step;
|
||||
private double slow_step;
|
||||
private double height;
|
||||
// private int currentFloor = 0;
|
||||
// private boolean betweenFloors = false; /* Between currentFloor and the one above it. */
|
||||
private Direction direction = Direction.NONE;
|
||||
private boolean stoppingNextFloor = false;
|
||||
private boolean emergency = false;
|
||||
private ElevatorListener listener;
|
||||
private int nbFloors;
|
||||
|
||||
public Elevator(int currentFloor, int nbFloors) {
|
||||
height = (double) currentFloor / nbFloors;
|
||||
floorHeight = 1. / nbFloors;
|
||||
this.nbFloors = nbFloors;
|
||||
height = (double) currentFloor / (nbFloors - 1); // -1 car rez-de-chaussée
|
||||
floorHeight = 1. / (nbFloors - 1);
|
||||
step = floorHeight / PRECISION;
|
||||
slow_step = step / 2;
|
||||
System.out.println("step: " + step + ", floorHeight: " + floorHeight);
|
||||
}
|
||||
|
||||
public void setActionListener(ElevatorListener listener) {
|
||||
@ -41,8 +44,9 @@ public class Elevator {
|
||||
direction = Direction.DOWN;
|
||||
}
|
||||
|
||||
public void stopElevator() {
|
||||
public void stop() {
|
||||
direction = Direction.NONE;
|
||||
stoppingNextFloor = false;
|
||||
}
|
||||
|
||||
public void stopNextFloor() {
|
||||
@ -60,55 +64,33 @@ public class Elevator {
|
||||
|
||||
public void update() {
|
||||
if (emergency) return;
|
||||
int prevFloor = (int) Math.floor(height / floorHeight);
|
||||
|
||||
double delta;
|
||||
if (stoppingNextFloor) {
|
||||
delta = slow_step;
|
||||
}
|
||||
else {
|
||||
delta = step;
|
||||
}
|
||||
|
||||
switch (direction) {
|
||||
case DOWN:
|
||||
height -= step;
|
||||
|
||||
/* Bottom reached. */
|
||||
if (height < step) {
|
||||
height = 0;
|
||||
direction = Direction.NONE;
|
||||
}
|
||||
|
||||
/* Passed a floor, invoke the listener. */
|
||||
if (Math.floor(height / floorHeight) < prevFloor && listener != null) {
|
||||
listener.floorChange(Direction.UP);
|
||||
}
|
||||
// /* Go halfway below. */
|
||||
// if (!betweenFloors) currentFloor--;
|
||||
// betweenFloors = !betweenFloors;
|
||||
break;
|
||||
case UP:
|
||||
height += step;
|
||||
|
||||
/* Top reached. */
|
||||
if (height > 1-step) {
|
||||
height = 1;
|
||||
direction = Direction.NONE;
|
||||
}
|
||||
|
||||
/* Passed a floor, invoke the listener. */
|
||||
if (Math.floor(height / floorHeight) < prevFloor && listener != null) {
|
||||
height -= delta;
|
||||
if (height % floorHeight < delta && listener != null) {
|
||||
listener.floorChange(Direction.DOWN);
|
||||
}
|
||||
// /* Go halfway above. */
|
||||
// if (betweenFloors) currentFloor++;
|
||||
// betweenFloors = !betweenFloors;
|
||||
break;
|
||||
case UP:
|
||||
height += delta;
|
||||
if (height % floorHeight < delta && listener != null) {
|
||||
listener.floorChange(Direction.UP);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// public int getCurrentFloor() {
|
||||
// return currentFloor;
|
||||
// }
|
||||
|
||||
// public boolean getBetweenFloors() {
|
||||
// return betweenFloors;
|
||||
// }
|
||||
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
@ -124,4 +106,8 @@ public class Elevator {
|
||||
public boolean getEmergency() {
|
||||
return emergency;
|
||||
}
|
||||
|
||||
public int getNbFloors() {
|
||||
return nbFloors;
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
package simulation;
|
||||
|
||||
import Requests.CallFromElevatorRequest;
|
||||
import Requests.CallFromFloorRequest;
|
||||
|
||||
import commandSystem.EventQueue;
|
||||
import commandSystem.BasicInstructionQueue;
|
||||
import Events.CallFromElevatorEvent;
|
||||
import Events.CallFromFloorEvent;
|
||||
import commandSystem.Direction;
|
||||
import commandSystem.ElevatorListener;
|
||||
import simulation.Elevator;
|
||||
import Events.*;
|
||||
|
||||
|
||||
public class Simulation implements ElevatorListener {
|
||||
private boolean running = false;
|
||||
private int currentFloor = 0;
|
||||
private EventQueue queue;
|
||||
private int secondToWait = 1;
|
||||
private BasicInstructionQueue queue = new BasicInstructionQueue();
|
||||
private Elevator elevator;
|
||||
|
||||
public Simulation(Elevator elevator) {
|
||||
@ -20,13 +21,21 @@ public class Simulation implements ElevatorListener {
|
||||
}
|
||||
|
||||
public void elevatorCall(int floor) {
|
||||
System.out.println("Call from elevator: " + floor);
|
||||
queue.computeEvent(new CallFromElevatorEvent(floor));
|
||||
update();
|
||||
}
|
||||
|
||||
public void floorCall(int floor, Direction direction) {
|
||||
System.out.println("Call from floor: " + floor + " going " + direction);
|
||||
queue.computeEvent(new CallFromFloorEvent(floor, direction));
|
||||
update();
|
||||
}
|
||||
|
||||
public void floorChange(Direction d) {
|
||||
switch (d) {
|
||||
public void floorChange(Direction direction) {
|
||||
System.out.println("Floor reached: " + direction);
|
||||
boolean haveToWait;
|
||||
switch (direction) {
|
||||
case UP:
|
||||
currentFloor++;
|
||||
break;
|
||||
@ -34,30 +43,53 @@ public class Simulation implements ElevatorListener {
|
||||
currentFloor--;
|
||||
break;
|
||||
}
|
||||
// iter();
|
||||
haveToWait = queue.computeEvent(new ReachedFloorEvent(currentFloor, direction));
|
||||
if (haveToWait) {
|
||||
long t1 = System.nanoTime();
|
||||
elevator.stop();
|
||||
running = false;
|
||||
while ((System.nanoTime() - t1) / 1_000_000_000 < secondToWait);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
// public void iter() {
|
||||
// int nextDestination = queue.getNextInstruction();
|
||||
// int currentFloor = 0;
|
||||
// //System.out.println("next dest = " + nextDestination);
|
||||
// if (!running) {
|
||||
// if (nextDestination > 0) { /* We have a destination to go to. */
|
||||
// running = true;
|
||||
// elevator.goDown();
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// if (elevator.currentFloor == nextDestination) {
|
||||
// queue.removeInstruction(elevator.currentFloor, elevator.direction);
|
||||
// running = false;
|
||||
// }
|
||||
// else {
|
||||
// elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
|
||||
// elevator.currentFloor += elevator.direction == Direction.UP ? 1 : -1;
|
||||
// }
|
||||
// }
|
||||
// System.out.println("elevator floor " + elevator.currentFloor + " direction " +
|
||||
// (elevator.direction == Direction.UP? "up" : "down") + " running: " + running);
|
||||
// }
|
||||
public void emergency() {
|
||||
elevator.emergencyStop();
|
||||
}
|
||||
|
||||
public void cancelEmergency() {
|
||||
queue = new BasicInstructionQueue();
|
||||
elevator.cancelEmergency();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
final int next = queue.getNextInstruction();
|
||||
System.out.println("Current floor: " + currentFloor);
|
||||
System.out.println("Next instruction: " + next);
|
||||
|
||||
if (next == -1 || next == currentFloor) {
|
||||
System.out.println("Stopping.");
|
||||
elevator.stop();
|
||||
running = false;
|
||||
return;
|
||||
}
|
||||
|
||||
else if (next > currentFloor) {
|
||||
System.out.print("Going up.");
|
||||
running = true;
|
||||
elevator.goUp();
|
||||
}
|
||||
else if (next < currentFloor) {
|
||||
System.out.print("Going down.");
|
||||
running = true;
|
||||
elevator.goDown();
|
||||
}
|
||||
|
||||
if (next == currentFloor + 1 || next == currentFloor - 1) {
|
||||
System.out.print("\b (slowly).");
|
||||
running = true;
|
||||
elevator.stopNextFloor();
|
||||
}
|
||||
System.out.println("\n");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user