lundi 19 avril 2021

random distribution of time ranges minimizing overlap

I have 5 arrays of varying length.

work = [
    np.arange(9),
    np.arange(39),
    np.arange(58),
    np.arange(24),
    np.arange(16)
]

And a randomized schedule:

now = datetime.now().replace(hour=2)
end = now.replace(hour=22, minute=0, second=0, microsecond=0)

from numpy.random import default_rng

rng = default_rng()

schedule = np.linspace(now.timestamp(), end.timestamp(), sum(len(v) for v in work))
rng.shuffle(schedule_range)
worker_schedule = np.split(schedule, np.add.accumulate([len(v) for v in work][:-1]))

I believe this gets me a schedule where the job start times are distributed somewhat randomly with respect to each worker but evenly on aggregate. However each job runtime varies and I would like to avoid hot-spots where I get a bunch of overlapping jobs running simultaneously. Assuming I knew the job run times ahead of time, so:

work = [
    np.random.uniform(5,10,9),
    np.random.uniform(5,10,39),
    np.random.uniform(5,10,58),
    np.random.uniform(5,10,24),
    np.random.uniform(5,10,16)
]

Where each value in the array represents the expected run time for the job at that index.

How would I go about doing this? What concepts can I google to get a good understanding of the problem and known approaches? Finally, what would be a good way to visualize this with pyplot (currently using histograms for the start time distribution but there would be another dimension I would need to represent)?




Aucun commentaire:

Enregistrer un commentaire