简体   繁体   中英

Event's scheduling algorithm

I've got a list of events each having a duration. I'm looking to write an algorithm to schedule these events for a day. From 9AM to 12PM and then from 1PM to no earlier than 4PM and no later than 5PM.

I'm not sure what will be a good approach to solving this. Since there could be several possible solutions, my first thought is to test random combinations for correctness.

I'd like to know if there's a more deterministic way of solving this. Thanks ;)

EDIT

@svs The timing for events is in minutes and no events should overlap. Also there's no need for pauses between events except for a lunch break from 12PM to 1PM.

Okay Since you basically have two equal time-slot buckets, you can essentially schedule them all in sequence regardless of order, and assuming there is a solution, look for how you can even them out. Start with buckets A and B.

Put the largest event e1 in bucket A. Then put the next largest event e2 in bucket B. Put the largest event in bucket B that is at most e1-e2 minutes long. Keep adding to bucket B until your bucket B has no more than A's total minutes.

Then repeat the above, (switching A for B).

Keep repeating the above until you are complete your events.

This will only work because you each bucket has the same length, 180 minutes.

Actually since you have this 4-5pm rule, any extra events will be left over at the end. They will all go in one bucket, and this will be the afternoon bucket. If for some reason you have an event that is > 180 minutes, then that will book the afternoon. Then if you fit as many as you can in the morning (from largest to smallest), then the rest would go in the afternoon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM