Temporal planning: actions, intervals and resources
时间与资源约束规划
Find and independently bound a small resource-constrained schedule while preserving temporal-model assumptions.
temporal-planningA problem to solve
Two workpieces share a machine. Processing A takes three time units, inspecting A on a separate bench takes two, and processing B takes four. Inspection must follow A, but it can overlap B because the workpieces and resources differ. Finishing every operation one after another takes nine units; a valid overlapping schedule can take seven.
Temporal planning asks which actions to perform and when, while respecting conditions and resources. Scheduling fixes some or all action choices and determines their times. The example below solves that smaller scheduling problem exactly within explicit integer bounds. It does not search a full planning domain for which actions should exist.
Definitions and guarantees
Let task start at , last , and finish at . We assume known durations, no interruption, integer start times, and one unit of its named renewable resource throughout execution.
A predecessor must finish before task starts:
For a capacity-one resource shared by and , their intervals cannot overlap:
A temporal difference constraint can bound the distance between two time points. Simple temporal problems use single intervals; choosing which of two tasks goes first introduces a disjunction that is not just one conjunction of difference bounds. Dechter, Meiri and Pearl distinguish simple from general temporal constraint problems. Temporal Constraint Networks
A complete temporal model also needs conditions at action start, during execution and at the end. PDDL2.1 distinguishes these and imposes rules on simultaneous reads and updates. Its over all condition concerns the open interior; endpoint conditions must be stated separately. Our resource convention uses half-open intervals and permits immediate handoff, but does not implement all PDDL2.1 endpoint semantics. PDDL2.1: An Extension to PDDL for Expressing Temporal Planning Domains
The objective is makespan, the last finishing time. A and B require seven units of a capacity-one machine, so no schedule starting at or after zero can finish before time seven. The A-then-inspection chain requires five. The schedule shown below reaches seven, proving optimality even against continuous start times under this resource model.
A minimal implementation
The program enumerates bounded integer starts, rejects precedence or resource violations, and retains the shortest valid makespan. With tasks and horizon , there are at most assignments. Checking one takes with these simple data structures. This exponential search is useful for tiny reference cases, not production-scale scheduling.
Input validation restricts the teaching search to five tasks and horizon twelve. A duration longer than the horizon yields no feasible schedule; an invalid duration or unknown predecessor is rejected. A cycle of positive-duration dependencies has no feasible schedule. Empty work finishes at zero. The helper feasible assumes a validated task model; use check_schedule for a new model.
from dataclasses import dataclass
from itertools import product
from collections import Counter
@dataclass(frozen=True)
class Task:
name: str
duration: int
resource: str
after: tuple = ()
def validate(tasks, horizon, capacities):
if type(horizon) is not int or not 0 <= horizon <= 12 or len(tasks) > 5:
raise ValueError("teaching limits: at most 5 tasks and horizon 0..12")
names = [t.name for t in tasks]
if any(not isinstance(n, str) or not n for n in names) or len(set(names)) != len(names):
raise ValueError("task names must be unique nonempty strings")
if any(type(c) is not int or c < 1 for c in capacities.values()):
raise ValueError("capacities must be positive integers")
for t in tasks:
if type(t.duration) is not int or t.duration < 1:
raise ValueError("durations must be positive integers")
if t.resource not in capacities or any(p not in names for p in t.after):
raise ValueError("unknown resource or predecessor")
def feasible(tasks, starts, horizon, capacities):
by_name = {t.name: t for t in tasks}
if not isinstance(starts, dict) or set(starts) != set(by_name) or any(type(v) is not int for v in starts.values()):
return False
for t in tasks:
s = starts[t.name]
if type(s) is not int or s < 0 or s + t.duration > horizon:
return False
if any(s < starts[p] + by_name[p].duration for p in t.after):
return False
for tick in range(horizon):
used = Counter(t.resource for t in tasks
if starts[t.name] <= tick < starts[t.name] + t.duration)
if any(count > capacities[r] for r, count in used.items()):
return False
return True
def check_schedule(tasks, starts, horizon, capacities):
validate(tasks, horizon, capacities)
return feasible(tasks, starts, horizon, capacities)
def solve(tasks, horizon, capacities):
validate(tasks, horizon, capacities)
best = None
domains = [range(horizon - t.duration + 1) for t in tasks]
for values in product(*domains):
starts = dict(zip((t.name for t in tasks), values))
if not feasible(tasks, starts, horizon, capacities):
continue
finish = max((starts[t.name] + t.duration for t in tasks), default=0)
if best is None or finish < best[0]:
best = (finish, starts)
return best
if __name__ == "__main__":
tasks = [Task("A", 3, "machine"), Task("inspect-A", 2, "bench", ("A",)),
Task("B", 4, "machine")]
result = solve(tasks, 9, {"machine": 1, "bench": 1})
print("makespan:", result[0])
for task in tasks:
start = result[1][task.name]
print(task.name, start, start + task.duration)
print("horizon 6:", solve(tasks, 6, {"machine": 1, "bench": 1}))
makespan: 7
A 0 3
inspect-A 3 5
B 3 7
horizon 6: None
A runs during [0,3), inspection during [3,5), and B during [3,7). The machine is reused at time three without overlap. At horizon six, failure means no schedule exists inside that bound. It does not mean the task collection can never be completed.
Limits and alternatives
A resource constraint is not a complete physical model. This example assumes independent workpieces, a separate inspection bench, no setup time, no transport delay and deterministic durations. Adding a shared operator, a cooling interval or a deadline can invalidate its overlap. State the missing condition before changing the optimizer.
Larger systems use propagation, constraint programming, mixed-integer models or heuristic planning rather than this enumeration. A lower bound remains useful even when an optimizer is more elaborate. Renewable capacity also differs from a consumable quantity such as fuel: returning a machine after use does not restore burned fuel.
Finally, a valid schedule for chosen tasks is not evidence that those tasks achieve the intended goal. Full planning must connect action conditions and effects to that goal, and execution monitoring must detect deviations from assumed durations or states.
Exercises with answers
1. Why can the optimum not be below seven?
The capacity-one machine must process A for three units and B for four, with no overlap.
2. What happens if B goes first?
B ends at four, A at seven, and inspection at nine.
3. What is the optimum if machine capacity is two?
Five: A and B can start together, but A followed by inspection still takes five.
4. Does no schedule under horizon six prove the planning task is impossible?
No. The same task set has a valid schedule under a larger horizon, and full planning may also choose different actions.
Research and next steps
Read the temporal-constraint paper for the distinction between interval bounds and disjunctions, then PDDL2.1 for action semantics. Keep the toy scheduler’s finite search guarantee separate from the expressiveness of either formalism.
Continue with constraint satisfaction, PDDL and planning.
Make a prediction, then check
What is the capacity-one machine lower bound?
Learning objectives
- Separate temporal constraints, resource conflicts and action-goal semantics.
- Verify a bounded schedule with feasibility checks and an independent lower bound.
Prerequisites & connections
Explore related knowledge →References
- PDDL2.1: An Extension to PDDL for Expressing Temporal Planning Domains
Maria Fox; Derek Long · 2003 - Temporal Constraint Networks
Rina Dechter; Itay Meiri; Judea Pearl · 1991
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-07 · Codex single-AI-author technical check: bounded primary-source passages, explicit finite models, executed programs, independent mathematical/exhaustive references, input boundaries and bilingual alignment. Not independent human or second-agent review; no full-system research reproduction claimed.
- Single-agent authored technical review; runnable example, exact or literal reference checks, explicit assumptions and matching bilingual equations/exercises. Automated execution and rendering results recorded separately.
- Verified8 tests including18 duration combinations against the independent machine-load/critical-chain bound, capacity2, horizon failure, dependency cycle, overlap, invalid model and a malformed predecessor start.
- Compared both locale arguments, definitions, assumptions, formulas, code, results and all four exercises. Original finite teaching programs; no published system or research benchmark reproduction claimed. Catalogue IDs corrected before freezing.
- Complete bilingual prose and corresponding exercises promoted with formal status and SHA binding. Algorithm tests read formal MDX; historical essays claim no executable program or computational tests.
- Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
Source locations checked:
- PDDL2.1: An Extension to PDDL for Expressing Temporal Planning Domains · Abstract/introduction and physical11–14 durative action semantics, including open-interval invariants and concurrent access/update.
- Temporal Constraint Networks · Author-linked original scan physical1–3, TCSP versus STP framework; no full proof reproduced.
Related topics