Skip to main content

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:

  1. Model: Define your tasks, constraints, and objective
  2. Solve: Run the constraint programming solver
  3. Solution: Extract the schedule and interpret results

Let's see a minimal example:

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}")

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:

TaskDurationWorkersResource
CutDeskWood30 min1Saw
CutChairWood25 min1Saw
SandDeskParts20 min1
SandChairParts15 min1
AssembleDesk45 min2
AssembleChair35 min1
StainDesk20 min1Spray booth
StainChair15 min1Spray booth
ApplyFinish30 min1Spray booth
FinalInspect10 min1

Dependencies

The tasks must follow a logical order:

CutDeskWood30 min · 1 workerSandDeskParts20 min · 1 workerAssembleDesk45 min · 2 workersStainDesk20 min · 1 workerCutChairWood25 min · 1 workerSandChairParts15 min · 1 workerAssembleChair35 min · 1 workerStainChair15 min · 1 workerApplyFinish30 min · 1 workerFinalInspect10 min · 1 workerSawSpray booth

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:

  1. Precedence: Tasks must happen in order
  2. No-overlap: The saw can only cut one thing at a time
  3. Cumulative: We have only 2 workers total; assembling the desk needs both
  4. Transition times: The spray booth needs cleaning between different stain colors
  5. Alternatives: Sanding can be done by hand (slow) or with a power sander (fast, but shared)
  6. 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

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 →