1

Please forgive me if this is a well-known class of problem with a well-known solution. I've been searching but obviously not succeeding.

Assume I have n events that must occur in an interval (e.g., [0,1]). Each event is associated with a duration that is stochastically drawn from a predefined distribution. Assume that the interval is much larger than all the event durations combined: valid schedules always exist. The probabilities of event occurrence over the [0,1] interval are not uniform, but the events are independent as long as they are not overlapping.

What is an efficient and accurate (random) way to schedule these events?

Here's my current pseudocode:

lowerBound = min(interval)
upperBound = max(interval)
for n in numEvents {
  draw startTime 
  draw endTime
  while ( startTime is less than lowerBound || endTime exceeds upperBound ) {
    draw startTime
    draw endTime
  }
  add event
  reset lowerBound and upperBound to define largest remaining (event-free) interval
}

I think that by choosing the larger remaining interval in which to schedule the new event, I'm making the events overdispersed--more spaced out than they'd otherwise be. This nonetheless seems very efficient and probably extremely accurate when the number of events is small.

I'm using C++, although that's probably irrelevant.

I'd also greatly appreciate search terms, if you know what this kind of problem is called.


Context: Accuracy is most important to me here. This is not a time-intensive step in the overall program.

Sarah
  • 1,614
  • 1
  • 23
  • 37
  • 2
    You haven't defined *accuracy*. – Beta Mar 15 '13 at 23:19
  • I don't have a formal definition. I'm worried about introducing biases beyond the rules defined above, e.g., I don't want to introduce more time between events than should occur randomly. – Sarah Mar 16 '13 at 02:45
  • The word I should have used was "unbiased." – Sarah Mar 18 '13 at 14:00

1 Answers1

2

I'd just place each event randomly, checking for collisions, and if there's a collision wipe the slate clean and start over.

You say that the interval is much larger than the sum of the event durations, so collisions will be rare, so this method is quite fast in practice.

You say you want accurate results. I'm not sure what that means, but at a guess I'd say that all valid solutions should be equally probable; the current solution in the question doesn't satisfy that requirement, but this one does.

Beta
  • 96,650
  • 16
  • 149
  • 150
  • Hahaha. This is beautifully straightforward, but I don't think it had occurred to me. It is possible that the parameters may be set so that the durations:interval ratio approaches 1, but I'll add some kluges and warnings for that case. Thanks. – Sarah Mar 16 '13 at 02:51