Timeout Budget Split Across Sequential Steps
Problem Statement
An agent plan runs steps sequentially under one overall timeout. Assign each step a per-step timeout proportional to its expected cost, but never below a floor, and report whether the plan fits.
Background
Given a total budget and per-step expected costs costs, the naive split gives step i a share budget * costs[i] / sum(costs). To avoid starving cheap steps, each allocation is raised to at least floor seconds. Because flooring can push the sum over budget, the plan is feasible only if sum(max(share_i, floor)) <= budget. Report each allocation (rounded to 4 decimals) and feasibility.
Your Task
def split_timeout(costs, budget, floor):
Return a dict {"allocations": [...], "feasible": bool}, allocations rounded to 4 decimals.
Input Format
- costs (list of positive floats), budget (float), floor (float).
Output Format
- A dict with "allocations" (list of floats) and "feasible" (bool).
Sample
print(split_timeout([1.0, 3.0], 8.0, 0.5))
Output:
{'allocations': [2.0, 6.0], 'feasible': True}
Example
print(split_timeout([1.0, 3.0], 8.0, 0.5))
{'allocations': [2.0, 6.0], 'feasible': True}- Calculate the total expected cost to determine proportional weights: .
- Compute the raw proportional share for each step using the formula :
- Step 1:
- Step 2:
- Apply the minimum floor constraint by taking the maximum of the raw share and the floor value ():
- Step 1:
- Step 2:
- Check feasibility by summing the final allocations and comparing to the budget: , which is , so the plan is feasible.
- The final output is
{'allocations': [2.0, 6.0], 'feasible': True}
Constraints
- Share is
budget * costs[i] / sum(costs), then raised tofloor. feasibleissum(allocations) <= budget(use a small tolerance).- Round allocations to 4 decimals;
costsis non-empty with positive sum.