Guys,

I need help with an algorithm. I'm writing a program that sends a repeated
pattern of requests to a service. Each request has a "weight" that controls
the relative frequency with which I need to send that particular request. So
given:

   foo => 1
   bar => 3

I would send four requests, one of which is a 'foo', and the other three are
'bar'. So my requests would look like:

   foo, bar, bar, bar, foo, bar, bar, bar, ...

If I have a case like:

   foo => 1
   bar => 1
   qux => 6

I can easily send one foo, followed by a bar, followed by 6 qux:

   foo
   bar
   qux qux qux qux qux qux

However, what I need to do is to distribute the requests so that the
intervals between instances of a given request are distributed as equally as
possible. For example:

   foo 
   qux qux qux
   bar 
   qux qux qux

Now I have only intervals of 0 or 1 between successive "qux", instead of an
interval of 2 as in the previous case.

As an extreme example, if I had a dozen requests with a weight of 1 and a
final request with a weight of 12, I would "starve" the highly-weighted
request until the first 12 had been sent.

How can I generalize this for any given set of requests and weights? Is
anyone aware of any general literature on this kind of problem? (Sounds like
a scheduling algorithm maybe?)

Thanks,
Bob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to