Python API Reference

This is the auto-generated API reference for the OptalCP Python library.

New to OptalCP? Start with the Tutorial for a hands-on introduction, or Quick Start for installation.

Key Classes

Class

Description

Model

Central class for building optimization models. Creates variables, constraints, and objectives.

IntervalVar

Interval (task) variable for scheduling. Has start, end, length, and optional presence.

IntVar

Integer decision variable with a domain.

SequenceVar

Ordered sequence of intervals for routing and sequencing problems.

Solver

Advanced solving with callbacks for solutions, bounds, and logs.

Solution

Access to variable values after solving.

Common Entry Points

Creating a Model

import optalcp as cp
model = cp.Model()

See Model for all factory methods: int_var(), interval_var(), sequence_var().

Solving

  • Simple: Model.solve() - returns SolveResult

  • Advanced: Solver class with on_solution(), on_log() callbacks

Constraints

Most constraints are methods on Model:

  • Scheduling: no_overlap(), alternative(), span()

  • Precedence: end_before_start(), start_at_end(), etc.

  • Resources: pulse(), step_at_start(), cumul_le()

  • Forbid: forbid_start(), forbid_end(), forbid_extent()

Expressions

Expressions use operators. See IntExpr for arithmetic (+, *, <=) and BoolExpr for boolean logic (&, |, ~).

Interval expressions: start(), end(), length(), presence().

Parameters

Parameters controls solver behavior: timeLimit, nbWorkers, searchType, logLevel, etc.

Parse from command line: parse_parameters(), parse_known_parameters().

Solution Access

Solution methods: get_start(), get_end(), get_value(), is_absent().

Model Export

  • Model.export_model() / Model.import_model() - JSON serialization

  • Model.print_model() - Human-readable format

Benchmarking

benchmark() function with BenchmarkParameters.

Learn More

Indices and tables