Introduction to Scheduling
Welcome to the OptalCP tutorial. This guide will teach you how to model and solve scheduling problems using constraint programming. We'll work through a complete example step by step, building up from a simple model to one that handles real-world complexities.
What is Scheduling?
Scheduling is about deciding when to perform tasks and how to allocate resources. You might need to:
- Schedule manufacturing operations on machines
- Assign workers to jobs
- Plan project activities with dependencies
- Optimize delivery routes with time windows
These problems are hard because of constraints: some tasks must happen before others, resources are limited, and there are often many ways to organize the schedule. Constraint programming helps you find good solutions efficiently.
The Model → Solve → Solution Workflow
OptalCP follows a simple three-step pattern:
- Model: Define your tasks, constraints, and objective
- Solve: Run the constraint programming solver
- Solution: Extract the schedule and interpret results
Let's see a minimal example:
- Python
- TypeScript
import optalcp as cp
# 1. MODEL
model = cp.Model()
task = model.interval_var(length=10, name="task")
model.minimize(task.end()) # Finish as early as possible
# 2. SOLVE
result = model.solve()
# 3. SOLUTION
if result.solution:
print(f"Task ends at: {result.solution.get_end(task)}")
print(f"Optimal: {result.proof}")
import * as CP from '@scheduleopt/optalcp';
// 1. MODEL
const model = new CP.Model();
const task = model.intervalVar({ length: 10, name: "task" });
model.minimize(task.end()); // Finish as early as possible
// 2. SOLVE
const result = await model.solve();
// 3. SOLUTION
if (result.solution) {
console.log(`Task ends at: ${result.solution.getEnd(task)}`);
console.log(`Optimal: ${result.proof}`);
}
This simple model creates a task with duration 10 and minimizes its end time. The solver finds that the optimal schedule starts at time 0 and ends at time 10.
When to Use OptalCP
OptalCP is designed for scheduling and resource allocation problems where:
- Tasks have durations and dependencies
- Resources are limited (machines, workers, materials)
- You want to optimize objectives like makespan, cost, or tardiness
- Constraints are complex (precedence, transitions, alternatives)
OptalCP is especially powerful when your problem has many types of constraints. In constraint programming, you simply list your constraints—precedence, resource limits, time windows, transitions—and the solver handles them all together. With custom algorithms, adding a new constraint type often means redesigning the entire algorithm from scratch.
The Furniture Workshop Problem
In this tutorial, we'll work with a toy example: a small furniture workshop making a custom wooden desk and matching chair. This keeps the code readable, but OptalCP can handle real-world problems with hundreds of thousands of tasks.
Here are the tasks we need to schedule:
| Task | Duration | Workers | Resource |
|---|---|---|---|
| CutDeskWood | 30 min | 1 | Saw |
| CutChairWood | 25 min | 1 | Saw |
| SandDeskParts | 20 min | 1 | — |
| SandChairParts | 15 min | 1 | — |
| AssembleDesk | 45 min | 2 | — |
| AssembleChair | 35 min | 1 | — |
| StainDesk | 20 min | 1 | Spray booth |
| StainChair | 15 min | 1 | Spray booth |
| ApplyFinish | 30 min | 1 | Spray booth |
| FinalInspect | 10 min | 1 | — |
Dependencies
The tasks must follow a logical order:
Both the desk and chair must be stained before the final finish coat is applied, and everything must be inspected at the end.
Constraints We'll Model
As we progress through the tutorial, we'll add different types of constraints:
- Precedence: Tasks must happen in order
- No-overlap: The saw can only cut one thing at a time
- Cumulative: We have only 2 workers total; assembling the desk needs both
- Transition times: The spray booth needs cleaning between different stain colors
- Alternatives: Sanding can be done by hand (slow) or with a power sander (fast, but shared)
- Reservoirs: Dust accumulates and must be cleaned before exceeding safety limits
Objective
We want to minimize the makespan: the total time from starting work until the final inspection is complete. This means finishing the entire order as quickly as possible.
What You'll Learn
By the end of this tutorial, you'll know how to:
- Create interval variables to represent tasks
- Express precedence and timing constraints
- Model limited resources (machines, workers, materials)
- Handle alternatives and optional activities
- Set objectives and interpret solutions
- Understand solver output and solution quality
Each chapter builds on the previous one, progressively adding features to our model. You'll see working code at every step, and you can run these examples yourself.
Prerequisites
This tutorial assumes basic programming knowledge in Python or TypeScript. No prior experience with constraint programming is required—we'll explain concepts as we go.
Make sure you've installed OptalCP (see the Quick Start guide). The examples use the Preview edition, which is free but reports solution variables as absent (objective values are correct). This means code that accesses solution values (like get_start(), get_end()) will return None/null in Preview edition. For full solution details, use the Academic or Full edition.
See Also
- Quick Start Guide — Installation and first model
- Modeling / Intervals — Complete reference for interval variables
- Solving / Basics — Understanding solve results
Next Steps
Ready to start modeling? In the next chapter, we'll build our first real schedule with precedence constraints and optimize the makespan.
Continue to: Basic Model →