Setting Up Your First CP-SAT Model in OR-Tools
Learn to build a complete CP-SAT model in Python with OR-Tools: declaring integer and Boolean variables, adding linear constraints, setting an objective, invoking the solver, and reading back the optimal values.
Tutorial
The CpModel Object and Decision Variables
A CP-SAT model is a Python object that holds decision variables, constraints, and (optionally) an objective function. We build one by importing the library and instantiating a :
To add an integer decision variable, call , where and are the inclusive integer lower and upper bounds, and is a string used in solver output:
This declares a variable with domain For Boolean variables (domain ), use instead:
Every variable must be created by the same instance that will later hold constraints referring to it. The argument order is always — bounds first, name last.