Scenario:
I need to give users opportunity to book different times for the service. Caveat is that i dont have bookings in advance but i need to fill them as they come in.
Bookings can be represented as keyvalue pairs:
[startTime, duration]
So, for example, [9,3]
would mean event starts at 9 o’clock and has duration of 3 hours.
Rules:
- users come in one by one, there is never a batch of users requests
- no bookings can overlap
- service is available 24/7 so no need to worry about “working time”
- users choose
duration
on their own - obviously, once user chooses&confirms his booking we cannot shuffle it anymore
- we dont want gaps to be lesser than some amount of time. this one is based on probability that future users will fill in the gap. for example, if distribution of
durations
over users bookings is such that probability for future users filling the gap shorter thanx
hours is less thanp
then we want a rule that gap cannot be shorter thanx
. (for purpose of this question, we can assumex
being hardcoded, here i just explain reasons) - the goal is to have service-busy-duration maximized
My thinking so far...
- I keep the list of bookings made so far
- I also keep track of gaps (as they are potential slots for new users booking)
- When new user comes with his booking
[startTime, duration]
i first check for ideal case wheregapLength = duration
. if there is no such gaps, i find all slots (gaps) that satisfy conditiongapLength - duration > minimumGapDuration
and order them in descending order by thatgapLength - duration
value - I assign user to the first gap with maximum value of
gapLength - duration
since that gives me highest probability that gap remaining after this booking will also get filled in future
Questions:
Are there some problems with my approach that i am missing?
Are there some algorithms solving this particular problem?
Is there some usual approach (good starting point) which i could start with and optimize later? (i am actually trying to get enough infos to start but not making some critical mistake; optimizations can/should come later)
PS. From research so far it sounds this might be the case for constraint programming. I would like to avoid it if possible as i have no clue about it (maybe its simple, i just dont know) but if it makes a real difference, i will go for its benefits and implement it.
I went through stackoverflow for similar problems but didnt find one with unknown future events. If there is such and this is direct duplicate, please refer to it.