A Python toolkit that optimizes ONNX models by reducing operator count while keeping accuracy, aiming for faster inference.
d-krupke/cpsat-primer
An open-access book-style primer teaching how to model and solve combinatorial optimization problems with Google OR-Tools' CP-SAT solver.
- Stars
- 834
- Forks
- 69
- Open issues
- 9
- Last commit
- 2 months ago
What is it?
The CP-SAT Primer is a free, book-style tutorial for learning Google OR-Tools' CP-SAT solver, a constraint programming and SAT-based solver for combinatorial optimization. It is written for computer science students and developers, with Python examples throughout, and it compares CP-SAT with mixed integer programming (MIP) solvers and other optimization tools.
The first part covers installation, a first model, basic modeling of variables, objectives and constraints, advanced constraints such as circuit, interval and reservoir constraints, solver parameters, and how to read the solver log. The second part addresses practical engineering topics: coding patterns for maintainable optimization code, serving optimization jobs through an API, large neighborhood search heuristics, and benchmarking models.
The primer is maintained by Dominik Krupke at TU Braunschweig and is released under CC-BY 4.0, with a companion website that renders the same content as a book.
Key features
- 01Covers CP-SAT basics: variables, objectives, linear and logical constraints.
- 02Explains advanced constraints such as circuit, interval, and no-overlap.
- 03Shows how to set time limits, hints, and parallelism in the solver.
- 04Teaches interpreting the solver log to judge solution quality.
- 05Compares CP-SAT with MIP solvers and other optimization techniques.
- 06Includes Python code examples and a section on large neighborhood search.
Use cases
- Learning combinatorial optimization as a computer science student.
- Moving from a MIP solver to CP-SAT for scheduling or routing models.
- Building a maintainable optimization service with CP-SAT behind an API.
- Benchmarking and tuning a CP-SAT model for a production problem.
Quick start
- 1
Install OR-Tools with pip
pip install -U ortools - 2
Copy the Knapsack example from the README and run it in Python
Topics
FAQ
- What is cpsat-primer?
- An open-access book-style primer teaching how to model and solve combinatorial optimization problems with Google OR-Tools' CP-SAT solver. The CP-SAT Primer is a free, book-style tutorial for learning Google OR-Tools' CP-SAT solver, a constraint programming and SAT-based solver for combinatorial optimization. It is written for computer science students and developers, with Python examples throughout, and it compares CP-SAT with mixed integer programming (MIP) solvers and other optimization tools.
- Is cpsat-primer free to use? What license does it have?
- cpsat-primer is open source under the CC-BY-4.0 license. Check the license terms before using it in commercial products.
- Is cpsat-primer still maintained?
- Updated within 6 months. The last commit to cpsat-primer was on Sep 6, 2026.
- What can I use cpsat-primer for?
- Learning combinatorial optimization as a computer science student. Moving from a MIP solver to CP-SAT for scheduling or routing models. Building a maintainable optimization service with CP-SAT behind an API. Benchmarking and tuning a CP-SAT model for a production problem.
- How do I install cpsat-primer?
- Install OR-Tools with pip: pip install -U ortools Copy the Knapsack example from the README and run it in Python
- Where can I get cpsat-primer?
- The source code and installation instructions are on GitHub: https://github.com/d-krupke/cpsat-primer
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Windows 10/11 utility for debloating, optimizing and customizing the system, app removal, and creating autounattend.xml files.
Free, open-source Windows optimization tool with 42 tweaks, a settings panel, and built-in tools for startup, scheduled tasks, and cleanup.
C/C++ library for optimizing triangle meshes to render faster on GPUs and to shrink mesh storage and transmission size.
An open-source evolutionary coding agent that uses LLMs to iteratively mutate and score code, aiming to discover better algorithms, implementing the AlphaEvolve approach.
A bytecode optimizer for Android apps that rewrites .dex files to make APKs smaller and faster.