Created
January 11, 2024 22:13
-
-
Save Furkan-Gulsen/f5aaedb16c536fcc4d205f8e1ed997be to your computer and use it in GitHub Desktop.
Get Task Index at Cycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_task_index_at_cycle(jobs, cycle): | |
execution_order = sorted(range(len(jobs)), key=lambda k: (jobs[k], k)) | |
total_time = sum(jobs) | |
cycle = cycle % total_time + 1 if cycle >= total_time else cycle | |
current_time = 0 | |
for job_index in execution_order: | |
current_time += jobs[job_index] | |
if cycle <= current_time: | |
return job_index | |
return execution_order[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment