218 [Hard] Elevator Scheduling - mmattioli/reddit-dailyprogrammer GitHub Wiki

Challenge details

While this one is a hard challenge, it's also open ended - be creative in how you solve the problem. I encourage you to compare notes, think about the challenge before you write code, and explore your algorithms. See the bonus questions below for some additional questions. Description

Most of us have seen and ridden elevators - you crazy folks in the UK and commonwealth countries often call them "lifts" - but I'm sure I'm not the only one who has puzzled about the scheduling algorithms. Which riders do you pick up and when? Do you service requests in the order of arrival or do you work on maximal overlap? For this challenge, you'll have to answer those questions. You're designing an elevator scheduling algorithm for a building and you have plenty of riders to keep happy. You can have any algorithm you want as long as you stick to the constraints - the cars have a fixed capacity and speed. Make sure you see the bonus questions after the challenge input.

Input description

You'll be given a single integer N on a line. The first N lines will identify elevator cars and with these fields: Car identifier, capacity, vertical speed in floors per second, and starting floor. Assume instantaneous getting on or off the elevator for the riders once you arrive on the floor. Assume that the elevator is able to leave with the rider as soon as it is able, but it may linger waiting for more people to arrive - the choice is yours.

Example

C1 12 .1 1

This translates to Car 1, capacity of 12 people, moves at .1 floors per second (ten seconds to traverse a floor up or down), and starting at floor 1. Then you'll get another integer on a line, M. The next M lines will show riders, with fields: Rider identification, elevator request time in seconds, source floor and destination floor. Rider identification numbers will be stable, meaning the rider will have the same identifier the entire exercise.

Example

R1 0 1 4

This translates to Rider 1 who at time point 0 wants to go from floor 1 to floor 4. Riders will not transit floors without an elevator.

Output description

The main thing to show in the output is the time point at which all requests have been satisfied. (Yes, this is trying to get you guys to compete for the most efficient algorithm). Optionally show all intermediate steps and journeys, and wait times for riders.

Challenge input

This was randomly generated, and so it has a few "oddities" in it, like riders who get on and off on the same floor, and riders who change their destination in the next second (e.g. in the middle of a ride). You still have to satisfy every request.

See repo for challenge input file

Bonus

Which improves delivery efficiency most?

  • Longer linger times?
  • More cars?
  • Faster cars?

Notes, ideas, additional information

Reddit page

Golang slice manipulation techniques