Maniacal Midsummer Marathon 2014 by AL, TL, JJ
Fun fact: Do you like mashing on those door-close buttons in elevators? Well, in most elevators built since the 90s, those buttons are just there to give passengers a false sense of control.
You were noticeably enraged when your friend, the lead engineer working for a large elevator firm, told you this fact. "What is this bamboozlement I've been experiencing my whole life?" you ask him. "Elevators are always so slow and lead to such long waiting times. And you blame us, the passengers for always being in a hurry and slamming on the door-close buttons. Can't you guys just design better elevators?"
He responds by telling you that behind-the-scenes, elevator companies work really hard to make elevators really efficient. The best elevator algorithm still remains a very difficult open problem. Companies even keep their own algorithms a trade secret.
That's when your entitled ass started boasting to him about easily being able to design a way better algorithm than whatever garbage his incompetent team can come up with. You quickly realize that this was a big mistake, because he actually challenged you to an elevator face-off. Being the lead engineer, he actually has the resources to pull this off. He claims that he'll give you a job at his firm if you manage to win or tie against him, but that you'll have to wax his hairy back if you lose. Being the sad, unemployed nerd you are, living with your parents and eating Cheetos off your chest every day, you have no choice but to accept his challenge to finally try and land yourself a job.
The challenge is to write a program for the computer of the elevator in a building, such that the average waiting time for passengers is minimized. There will be cameras on each floor of the building to record the waiting times of passengers. First, he'll hook your algorithm up to run for a period of time and record the results. Then, your friend will take the passenger data collected from your service period, enter it into his special elevator simulator software, and run his own company's algorithm on it. In the end, the average waiting time of your algorithm and his algorithm will be compared.
After digging through some articles online, you discovered that - big surprise! - elevator systems actually do require quite a bit of complicated mathematical theory. There's no way you'll be able to learn it all in time. Just as you were heading out to buy some wax paper, a dastardly thought suddenly goes through your mind – what if you rigged the challenge?
The day before your contest, you've secretly paid off the building manager, having him make an announcement to everyone that the elevators are out of service for the time period of your bet. You also told him to seal off the doors so that only certain people can enter and use the elevators. Why? Well, you've secretly arranged for passengers to use the elevator during the challenge. You'll know the exact times and floors related to their elevator usage so that you can rig your algorithm accordingly. Since your engineer friend has no clue about this, he'll have to rely on his algorithm being efficient during the actual service, while your algorithm will secretly have the traffic data way beforehand. What a perfect trick!
Your program will have the following information before the challenge:
- There are floors in the building being serviced, uniquely labeled with an integer from to .
- The elevator may change directions at any time. The time it takes to change directions is negligible.
- The elevator travels at a constant speed of (, is a real number) floors per second. While the elevator is traveling, it may stop at any floor, either to remain idle, or to pick up/drop off passengers.
- The elevator may stop for as long as possible on a floor. Standard regulations require elevator doors to open for at least (, is an integer) seconds each time. This means that if an elevator is told to stop for fewer than seconds, it will simply remain idle with its doors closed, and no passengers may get on or off. Note that your passengers are bribed, so they will take no more than total seconds to get on and off. They will never delay the door-close by hitting the door-open button or standing in the way of the sensors.
- There are passengers that need to be serviced. The passengers are each uniquely labeled with an integer from to .
- The following information is known about the passengers you've
bribed:
- At seconds (, is an integer), passenger will arrive at the elevator doors on floor .
- Passenger would like to go to floor .
- Passengers will be patient. That is, a passenger will never abandon their waiting spot until the elevator arrives.
- If the elevator doors are open on a passenger's initial floor , then the passenger will immediately step into the elevator.
- Similarly, if a passenger is on the elevator which is currently on their designated floor with its doors open, then the passenger will immediately step out of the elevator. For example, if the elevator doors open at , then we consider the time of all passengers getting off during this stop to also be .
- If an elevator door opens at and closes at , and a passenger arrives at during that range, then they may enter the elevator if and only if .
The waiting time experienced by passenger is the time from when
they arrive, , to the time when they get off (i.e. the moment the
elevator doors open on their designated floor ).
The average waiting time is the sum of the waiting times of all of the
passengers, divided by the number of passengers .
Initially, the elevator is on floor (closed) and the time is . Your program must output commands to direct the elevator, and must eventually move all the passengers to their designated floors. Furthermore, your program should try to service all passengers such that the average waiting time of all passengers is minimized. In the end, your average end time will be scored against your friend's. Only when you beat or tie him will you be safe from waxing his back. The odds are already in your favor, so you'd better not screw up!
Input Specification
The line will contain the numbers , , and , respectively
representing the number of floors in the building, the minimum time that
the elevator must open, and the speed of the elevator in floors/second.
and will be integers, while will be a real number.
The line will contain the integer , representing the number of
passengers.
The following lines each contain three integers describing the
request of a passenger. Namely, line will contain the values
, , and , indicating that passenger starts his
or her wait at time by the elevator doors on floor , and
would like to be taken to floor .
Output Specification
In order to control the elevator, you must first become familiar with the two commands of the elevator's system. They are the following:
Command | Format | Description |
---|---|---|
GO b | G b |
Move the elevator from its current floor to floor (, is an integer) at a speed of floors per second. If the elevator arrives on floor at a non-whole number of seconds, then it will wait until the entire second is over before processing more commands. Specifically, if the current floor is and the current time is , then the elevator will stop on floor at time , where is the absolute value function, and is the smallest integer greater than or equal to . |
STOP t | S t |
Stop the elevator for (, is an integer) seconds. If is less than the minimum regulated time , then the elevator will simply idle on its current floor and passengers will not be able to get on for this stopped period. Otherwise if , then the elevator doors will open for seconds, allowing passengers to get on or off at the floor it's currently on. If the current time is , then passengers arriving may step into the elevator during any time in the range — that is, including but not including (when the door closes). |
Each line of the output should describe an elevator command in one of
the two formats listed above. The commands will be performed back to
back (with the slight exception of those that follow a GO
command,
which will be performed at the next available whole number second after
the elevator arrives at its floor), and will control the behavior of the
elevator from start to finish.
Sample Input
10 2 3.0
4
0 2 5
2 1 10
4 5 10
21 10 4
Sample Output
S 3
G 2
S 2
G 5
S 2
G 10
S 11
G 4
S 2
Explanation
There are floors in the building. The elevator must stay open for at least seconds every time it opens. The elevator moves at a rate of floors per second. There are passengers, respectively arriving at times , , , and . The execution of the output commands are as outlined in the following table.
Time | Command | Description | Passenger Status | |||
---|---|---|---|---|---|---|
STOP 3 |
The elevator is on floor . It opens for seconds to wait for passenger . Meanwhile, passenger has arrived and now waits on floor . |
|||||
Passenger arrives on floor , immediately entering the elevator just before it closes. | ||||||
GO 2 |
The elevator travels at floors per second, so going up by more floor will require of a second. Thus, the elevator will only take seconds rounded up, which is second. |
|||||
STOP 2 |
The elevator is on floor . It opens for seconds, and the waiting passenger enters. | |||||
GO 5 |
The elevator travels to floor from floor ( floors total). Since its speed is floors/second, its total time to reach floor will be second. |
|||||
STOP 2 |
The elevator is on floor . It opens for seconds. During this second, passenger gets off. Also, passenger gets on. |
|||||
GO 10 |
The elevator goes to floor from floor . This takes seconds. | |||||
STOP 11 |
The elevator is on floor . It opens for seconds to allow both passengers and to get off. Afterwards, the elevator idles to wait for passenger to arrive at . |
|||||
Passenger arrives and enters immediately. | ||||||
GO 4 |
floors will take seconds to traverse. | |||||
STOP 2 |
The elevator doors open on floor . Passenger exits immediately. | |||||
In the above table: means that the passenger has arrived and is waiting at their initial floor, and means that the passenger is inside the elevator.
Passenger waits during the range for a total of seconds.
Passenger waits during the range for a total of seconds.
Passenger waits during the range for a total of seconds.
Passenger waits during the range for a total of seconds.
The average waiting time is seconds. Note
that this may not be the best possible solution for this scenario.
Scoring
For each test case, let's say the average waiting time for passengers
during your lift service is seconds, and the average waiting time
for your friend's algorithm is seconds.
Then, your score out of for the test case will be:
- , if any of the following holds true:
- The output format is incorrect (lines do not follow one of the two formats listed above); or
- Not all passengers have an opportunity to get on and off the elevator to reach their destination.
- between and , if .
- Your program scores base points for getting any valid way of moving all passengers to their designated floors, plus an additional score that is determined from a rational scale based on the values and .
- Specifically, your score will be , rounded to the nearest integer.
- (or over), if .
Here, will actually be the average waiting time for the test case obtained by the current submission with the highest score. Thus, the cases will be updated periodically in accordance with the current best submission (perhaps until a very nice solution is found).
Experimentation
For testing purposes, you are provided with a program to simulate the activities of the elevator and passengers. The simulator program simulator.py will accept the following command line options:
-h
will give a brief overview of the available options-i INFILE
loads the input file in the input format as described above-cmd CMDFILE
loads the command file in the output format as described above-log LOGFILE
specifies the file into which to dump information about the simulation. This is optional, as the same information will always be logged in standard output.
Comments