Dependency-Aware Agent Task Scheduler
Problem statement
You are given n unit-duration tasks numbered from 0 to n - 1. Each task is assigned to one of agentCount agents by taskAgents[i].
A pair [before, after] in prerequisites means that task before must finish before task after can start. In addition, tasks assigned to the same agent must run in their input order: for each agent, every task depends on the previous lower-indexed task assigned to that agent.
Execution proceeds in synchronous rounds. At the start of a round, a task is ready when all of its explicit and same-agent prerequisites finished in earlier rounds. Schedule at most concurrencyLimit ready tasks in a round, choosing the smallest task IDs when more tasks are ready than the limit. All selected tasks finish at the end of that round.
Return the scheduled task IDs for every round. IDs inside each round must be ascending.
Function
scheduleTasks(agentCount: int, concurrencyLimit: int, taskAgents: int[], prerequisites: int[][]) → int[][]Examples
Example 1
agentCount = 2concurrencyLimit = 2taskAgents = [0,1,0,1]prerequisites = [[0,3]]return = [[0,1],[2,3]]Tasks 0 and 1 are initially ready. Their completion unlocks the next task for each agent, so tasks 2 and 3 run together.
Example 2
agentCount = 3concurrencyLimit = 2taskAgents = [0,1,2,0,1]prerequisites = [[0,2],[1,2],[2,3],[2,4]]return = [[0,1],[2],[3,4]]The first two tasks run at the limit. Task 2 then becomes ready by itself, and its completion unlocks tasks 3 and 4.
Example 3
agentCount = 2concurrencyLimit = 1taskAgents = [0,1,0]prerequisites = []return = [[0],[1],[2]]Only one task may run per round. When tasks 1 and 2 are both ready, the smaller ID runs first.
Constraints
1 <= agentCount <= n <= 2000.1 <= concurrencyLimit <= agentCount.taskAgents.length == n.0 <= taskAgents[i] < agentCount.0 <= prerequisites.length <= 5000.- Every prerequisite is a distinct pair
[before, after]with valid, different task IDs. - The graph formed by explicit prerequisites and same-agent ordering is acyclic.