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 |
|---|---|
|
Central class for building optimization models. Creates variables, constraints, and objectives. |
|
Interval (task) variable for scheduling. Has start, end, length, and optional presence. |
|
Integer decision variable with a domain. |
|
Ordered sequence of intervals for routing and sequencing problems. |
|
Advanced solving with callbacks for solutions, bounds, and logs. |
|
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()- returnsSolveResultAdvanced:
Solverclass withon_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 serializationModel.print_model()- Human-readable format
Benchmarking
benchmark() function with BenchmarkParameters.
Learn More
Tutorial - Step-by-step guide building a complete scheduling model
Modeling Reference - Detailed concept explanations
Solving Guide - Understanding solve results and parameters
Examples - Complete benchmark implementations