Add elevator module: State-pattern car (idle, moving, doors open, maintenance), LOOK stop rule, round-robin / nearest-car / ETA dispatchers, tick simulation on seeded traffic (8 test classes, 13 transcripts)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6W3VPEBweaeA5DE4n
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
One car, three people, one tick per line (floors 0..9, doors stay open 3 ticks)
|
||||
===============================================================================
|
||||
|
||||
p0 starts at 0 and wants 6 (UP). p1 starts at 4 and wants 8 (UP). p2 starts at 3 and wants 1 (DOWN).
|
||||
All three press their button at tick 0.
|
||||
|
||||
t=00 car0 floor 0 DOORS_OPEN UP stops [4u, 3d, 6] riders [p0(0->6)]
|
||||
t=01 car0 floor 0 DOORS_OPEN UP stops [4u, 3d, 6] riders [p0(0->6)]
|
||||
t=02 car0 floor 0 DOORS_OPEN UP stops [4u, 3d, 6] riders [p0(0->6)]
|
||||
t=03 car0 floor 0 MOVING_UP UP stops [4u, 3d, 6] riders [p0(0->6)]
|
||||
t=04 car0 floor 1 MOVING_UP UP stops [4u, 3d, 6] riders [p0(0->6)]
|
||||
t=05 car0 floor 2 MOVING_UP UP stops [4u, 3d, 6] riders [p0(0->6)]
|
||||
t=06 car0 floor 3 MOVING_UP UP stops [4u, 3d, 6] riders [p0(0->6)]
|
||||
t=07 car0 floor 4 DOORS_OPEN UP stops [3d, 6, 8] riders [p0(0->6), p1(4->8)]
|
||||
t=08 car0 floor 4 DOORS_OPEN UP stops [3d, 6, 8] riders [p0(0->6), p1(4->8)]
|
||||
t=09 car0 floor 4 DOORS_OPEN UP stops [3d, 6, 8] riders [p0(0->6), p1(4->8)]
|
||||
t=10 car0 floor 4 MOVING_UP UP stops [3d, 6, 8] riders [p0(0->6), p1(4->8)]
|
||||
t=11 car0 floor 5 MOVING_UP UP stops [3d, 6, 8] riders [p0(0->6), p1(4->8)]
|
||||
t=12 car0 floor 6 DOORS_OPEN UP stops [3d, 8] riders [p1(4->8)]
|
||||
t=13 car0 floor 6 DOORS_OPEN UP stops [3d, 8] riders [p1(4->8)]
|
||||
t=14 car0 floor 6 DOORS_OPEN UP stops [3d, 8] riders [p1(4->8)]
|
||||
t=15 car0 floor 6 MOVING_UP UP stops [3d, 8] riders [p1(4->8)]
|
||||
t=16 car0 floor 7 MOVING_UP UP stops [3d, 8] riders [p1(4->8)]
|
||||
t=17 car0 floor 8 DOORS_OPEN UP stops [3d] riders []
|
||||
t=18 car0 floor 8 DOORS_OPEN UP stops [3d] riders []
|
||||
t=19 car0 floor 8 DOORS_OPEN UP stops [3d] riders []
|
||||
t=20 car0 floor 8 MOVING_DOWN DOWN stops [3d] riders []
|
||||
t=21 car0 floor 7 MOVING_DOWN DOWN stops [3d] riders []
|
||||
t=22 car0 floor 6 MOVING_DOWN DOWN stops [3d] riders []
|
||||
t=23 car0 floor 5 MOVING_DOWN DOWN stops [3d] riders []
|
||||
t=24 car0 floor 4 MOVING_DOWN DOWN stops [3d] riders []
|
||||
t=25 car0 floor 3 DOORS_OPEN DOWN stops [1] riders [p2(3->1)]
|
||||
t=26 car0 floor 3 DOORS_OPEN DOWN stops [1] riders [p2(3->1)]
|
||||
t=27 car0 floor 3 DOORS_OPEN DOWN stops [1] riders [p2(3->1)]
|
||||
t=28 car0 floor 3 MOVING_DOWN DOWN stops [1] riders [p2(3->1)]
|
||||
t=29 car0 floor 2 MOVING_DOWN DOWN stops [1] riders [p2(3->1)]
|
||||
t=30 car0 floor 1 DOORS_OPEN DOWN stops [] riders []
|
||||
|
||||
Door openings (from the building log):
|
||||
t=0 car0 opens at 0 heading UP off=[] on=[p0(0->6)]
|
||||
t=7 car0 opens at 4 heading UP off=[] on=[p1(4->8)]
|
||||
t=12 car0 opens at 6 heading UP off=[p0(0->6)] on=[]
|
||||
t=17 car0 opens at 8 heading UP off=[p1(4->8)] on=[]
|
||||
t=25 car0 opens at 3 heading DOWN off=[] on=[p2(3->1)]
|
||||
t=30 car0 opens at 1 heading DOWN off=[p2(3->1)] on=[]
|
||||
|
||||
Per person (ticks): wait = button to boarding, ride = boarding to arrival
|
||||
p0 p0(0->6) wait 0 ride 12 total 12
|
||||
p1 p1(4->8) wait 7 ride 10 total 17
|
||||
p2 p2(3->1) wait 25 ride 5 total 30
|
||||
@@ -0,0 +1,8 @@
|
||||
One car at floor 5 heading up, six requests: floors travelled
|
||||
=============================================================
|
||||
|
||||
requests in arrival order: [8, 2, 9, 1, 6, 3]
|
||||
|
||||
FCFS order [8, 2, 9, 1, 6, 3] distance 32
|
||||
SSTF order [6, 8, 9, 3, 2, 1] distance 12
|
||||
LOOK order [6, 8, 9, 3, 2, 1] distance 12
|
||||
@@ -0,0 +1,7 @@
|
||||
A request waits at floor 0; the car is at floor 5; new requests keep appearing at floors 6 and 7
|
||||
================================================================================================
|
||||
|
||||
The stream of new requests lasts 40 ticks. The car moves one floor per tick.
|
||||
|
||||
SSTF far request served at tick 46
|
||||
LOOK far request served at tick 9
|
||||
@@ -0,0 +1,20 @@
|
||||
12 floors, 3 cars (capacity 8), 120 people: same seeded traffic through three dispatchers
|
||||
=========================================================================================
|
||||
|
||||
Times are in ticks. 'wait' is button press to boarding; 'total' is button press to arrival.
|
||||
|
||||
Up-peak (70% start at the lobby), seed 42, arrivals spread over 240 ticks
|
||||
round-robin delivered 120/120 wait avg 18.5 max 57 total avg 32.7 max 79 floors 363 door cycles 134 ticks 299
|
||||
hall calls per car (car0, car1, car2): [15, 15, 15]
|
||||
nearest-car delivered 120/120 wait avg 91.9 max 248 total avg 106.4 max 258 floors 317 door cycles 129 ticks 481
|
||||
hall calls per car (car0, car1, car2): [23, 15, 4]
|
||||
eta delivered 120/120 wait avg 13.7 max 43 total avg 27.6 max 63 floors 338 door cycles 136 ticks 273
|
||||
hall calls per car (car0, car1, car2): [18, 15, 14]
|
||||
|
||||
Between floors (uniform origin and destination), seed 7, arrivals spread over 360 ticks
|
||||
round-robin delivered 120/120 wait avg 13.3 max 45 total avg 22.6 max 69 floors 564 door cycles 181 ticks 400
|
||||
hall calls per car (car0, car1, car2): [30, 30, 29]
|
||||
nearest-car delivered 120/120 wait avg 16.5 max 66 total avg 26.5 max 86 floors 428 door cycles 177 ticks 398
|
||||
hall calls per car (car0, car1, car2): [36, 25, 26]
|
||||
eta delivered 120/120 wait avg 9.9 max 43 total avg 19.6 max 61 floors 489 door cycles 190 ticks 378
|
||||
hall calls per car (car0, car1, car2): [37, 28, 33]
|
||||
@@ -0,0 +1,5 @@
|
||||
ETA forecast for an idle car at floor 0 and a call at floor 7 (UP)
|
||||
==================================================================
|
||||
|
||||
predicted: 7 ticks
|
||||
actual: 7 ticks
|
||||
@@ -0,0 +1,18 @@
|
||||
Taking car0 out of service while it carries a passenger
|
||||
=======================================================
|
||||
|
||||
t=5: maintenance requested for car0, which is carrying 'a' to floor 5
|
||||
|
||||
t=05 car0 floor 2 MOVING_UP UP stops [5] riders [a(0->5)] | car1 floor 8 MOVING_DOWN DOWN stops [2u] riders []
|
||||
t=06 car0 floor 3 MOVING_UP UP stops [5] riders [a(0->5)] | car1 floor 7 MOVING_DOWN DOWN stops [2u] riders []
|
||||
t=07 car0 floor 4 MOVING_UP UP stops [5] riders [a(0->5)] | car1 floor 6 MOVING_DOWN DOWN stops [2u] riders []
|
||||
t=08 car0 floor 5 DOORS_OPEN UP stops [] riders [] | car1 floor 5 MOVING_DOWN DOWN stops [2u] riders []
|
||||
t=09 car0 floor 5 DOORS_OPEN UP stops [] riders [] | car1 floor 4 MOVING_DOWN DOWN stops [2u] riders []
|
||||
t=10 car0 floor 5 DOORS_OPEN UP stops [] riders [] | car1 floor 3 MOVING_DOWN DOWN stops [2u] riders []
|
||||
t=11 car0 floor 5 IDLE NONE stops [] riders [] | car1 floor 2 DOORS_OPEN UP stops [6] riders [b(2->6)]
|
||||
t=12 car0 floor 5 MAINTENANCE NONE stops [] riders [] | car1 floor 2 DOORS_OPEN UP stops [6] riders [b(2->6)]
|
||||
|
||||
car0 entered MAINTENANCE at tick 12 at floor 5
|
||||
hall call for 'b' went to: t=5 hall 2u -> car1 (at 9 IDLE)
|
||||
|
||||
after returnToService(): car0 floor 5 DOORS_OPEN UP stops [9] riders [c(5->9)]
|
||||
@@ -0,0 +1,5 @@
|
||||
Both cars out of service, one person presses a button
|
||||
=====================================================
|
||||
|
||||
after 10 ticks: delivered=0 waiting=1
|
||||
car1 returned to service: delivered after 11 more ticks
|
||||
@@ -0,0 +1,22 @@
|
||||
Capacity 2, five people at the lobby, all going UP
|
||||
==================================================
|
||||
|
||||
hall calls dispatched after five button presses: 1
|
||||
|
||||
t=0 hall 0u -> car0 (at 0 IDLE)
|
||||
t=0 hall 0u -> car0 (at 0 DOORS_OPEN)
|
||||
t=0 car0 opens at 0 heading UP off=[] on=[p0(0->2), p1(0->3)]
|
||||
t=5 car0 opens at 2 heading UP off=[p0(0->2)] on=[]
|
||||
t=9 car0 opens at 3 heading UP off=[p1(0->3)] on=[]
|
||||
t=15 hall 0u -> car0 (at 0 DOORS_OPEN)
|
||||
t=15 car0 opens at 0 heading UP off=[] on=[p2(0->4), p3(0->5)]
|
||||
t=22 car0 opens at 4 heading UP off=[p2(0->4)] on=[]
|
||||
t=26 car0 opens at 5 heading UP off=[p3(0->5)] on=[]
|
||||
t=34 car0 opens at 0 heading UP off=[] on=[p4(0->6)]
|
||||
t=43 car0 opens at 6 heading UP off=[p4(0->6)] on=[]
|
||||
|
||||
p0(0->2) wait 0 ride 5
|
||||
p1(0->3) wait 0 ride 9
|
||||
p2(0->4) wait 15 ride 7
|
||||
p3(0->5) wait 15 ride 11
|
||||
p4(0->6) wait 34 ride 9
|
||||
@@ -0,0 +1,10 @@
|
||||
Requests the building refuses, and the exact message
|
||||
====================================================
|
||||
|
||||
origin above the top floor -> origin floor 12 is outside 0..9
|
||||
origin below the ground floor -> origin floor -1 is outside 0..9
|
||||
destination above the top floor -> destination floor 10 is outside 0..9
|
||||
destination below the ground floor -> destination floor -4 is outside 0..9
|
||||
same origin and destination -> origin and destination are both floor 5
|
||||
|
||||
people waiting afterwards: 0, hall calls dispatched: 0
|
||||
@@ -0,0 +1,4 @@
|
||||
A stop above the top floor
|
||||
==========================
|
||||
|
||||
addStop(10) -> floor 10 is outside 0..9
|
||||
@@ -0,0 +1,7 @@
|
||||
Randomised runs: 150 seeds x 3 dispatchers x 2 traffic shapes, rules checked after every tick
|
||||
=============================================================================================
|
||||
|
||||
runs: 900
|
||||
people delivered: 36000
|
||||
simulated ticks checked: 137430
|
||||
rule violations: 0
|
||||
@@ -0,0 +1,11 @@
|
||||
Hall call UP at floor 3 while car0 (at 4) is going DOWN and car1 waits at 9
|
||||
===========================================================================
|
||||
|
||||
nearest-car: after 4 ticks car0 floor 4 MOVING_DOWN DOWN stops [0] riders [rider(4->0)]
|
||||
nearest-car: t=4 hall 3u -> car0 (at 4 MOVING_DOWN)
|
||||
eta: after 4 ticks car0 floor 4 MOVING_DOWN DOWN stops [0] riders [rider(4->0)]
|
||||
eta: t=4 hall 3u -> car1 (at 9 IDLE)
|
||||
|
||||
wait for the person at floor 3, in ticks:
|
||||
nearest-car 9
|
||||
eta 5
|
||||
@@ -0,0 +1,5 @@
|
||||
Five people at floor 6 all press UP
|
||||
===================================
|
||||
|
||||
hall calls dispatched: 1
|
||||
door cycles used to serve all five: 2
|
||||
Reference in New Issue
Block a user