Currently only a subset of CP-SAT is supported.
Pull requests providing the missing features are welcome, but please pay attention to documentation and tests.
This project provides two packages:
-
ortoolsis an OCaml interface for building CP-SAT models. It does not require an installation of OR-Tools as it simply works with the protocol buffer format. Seeutils/sat_solve_pb.{c,py}for examples of interfacing with the CP-SAT solver. -
ortools_solversbuilds onortoolsto provide a simple OCaml interface for calling CP-SAT. Building and installing it requires an OR-Tools installation (see below).
Online docs: https://inria.github.io/ocaml-ortools/
Ensure that libortools.9.dylib (macOS) or libortools.so.9 (Linux), and
the other runtime libraries, are accessible by your compiler and loader.
For example, on macOS, set the LIBRARY_PATH (for compilation) and
DYLD_LIBRARY_PATH (for execution) environment variables.
On Linux, set the LD_LIBRARY_PATH (for compilation and execution)
environment variable.
There are several options for obtaining the runtime libraries.
-
Download or build from source following the official instructions (see the C++ section). See also the notes below.
-
Install the Python libraires with
pip. The OR-Tools runtime can be found insite-packages/ortools/.libs. -
From the or-tools releases on github, download
Google.OrTools.runtime.<os>-<arch>.9.<minor>.<patch>.nupkgwhere os ∈ { linux, osx, win } and arch ∈ { arm64, x64 } andunzipit. The required files are inruntimes/*/native.
I would have liked all this to be automatic, but:
-
There do not seem to be suitable brew/linux packages that could be linked from opam;
-
Vendoring the source in the opam package and building it on install is error-prone and resource-intensive;
-
Including several binary versions in the opam package is tedious to maintain and wasteful to download; and
-
Dynamically downloading the library on build is prevented by opam sandboxing (see the
downloadbranch for a prototype).
On macOS, install the required libraries:
brew install abseil protobuf protobuf-c re2 zlib bzip2 eigen@3
Then, in the OR-Tools source directory:
cmake -DBUILD_SAMPLES=OFF -DBUILD_EXAMPLES=OFF -DBUILD_FLATZINC=OFF \
-DBUILD_TESTING=OFF \
-DUSE_COINOR=OFF -DUSE_CPLEX=OFF -DUSE_GLPK=OFF -DUSE_HIGHS=OFF \
-DUSE_PDLP=OFF -DUSE_SCIP=OFF -DUSE_GLOP=ON -DUSE_XPRESS=OFF \
-DUSE_GUROBI=ON \
-S . -B build
cmake --build build --config Release -j -v
For me, this sufficed to build v9.12, but my attempts to build v9.13 or
v9.14 failed due to changes in Abseil around absl:Nonnull. It was possible
however to build the main branch (62fbfbc55e71d67217b08eebfdc268646ae2c41a).
The USE_GUROBI and USE_GLOP options are needed to avoid missing symbols
errors during linking.
On debian, the required libraries are:
sudo apt install libabsl-dev protobuf-compiler libprotobuf-c-dev \
libre2-dev libz-dev libbz2-dev libeigen3-dev
The Protocol Buffers interfaces have been generated with ocaml-protc (with pull/263).
If required, they can be regenerated as follows.
git clone [email protected]:google/or-tools.git
cd or-tools
git checkout v9.14 % TODO: update with required version
opam install ocaml-protoc
ocaml-protoc --binary --pp --make --ml_out src/model \
<path-to-or-tools>/ortools/sat/cp_model.proto
ocaml-protoc --binary --pp --make --ml_out src/model \
<path-to-or-tools>/ortools/sat/sat_parameters.proto
Cheat sheets
- git tag -a -m '...release notes...' --sign
- dune-release bistro
- in ocaml-ortools: build the docs
dune build @doc - check out the
gh-pagesbranch to ocaml-ortools-gh-pages - in ocaml_ortools-gh-pages:
rm -r index.html odoc.support ortools ortools_solvers - in ocaml_ortools-gh-pages:
cp -r ../ocaml-ortools/_build/default/_doc/_html/* . git add,commit,push`, etc.
-
More sophisticated
Ortools_solversinterface: write in C++, require OR-Tools headers.- Support FeasibleSolutionObserver interface with callbacks into OCaml.
- Eliminate the redundant copy in
ocaml_ortools_sat_solve.
-
Finish migrating OR-Tools
sat/samples -
Use
alcotestto test the interface. -
CP-SAT: Support
Intervalconstraints -
CP-SAT: Support
NoOverlapconstraints -
CP-SAT: Support
NoOverlap2Dconstraints -
CP-SAT: Support
Elementconstraints -
CP-SAT: Support
Circuitconstraints -
CP-SAT: Support
Routesconstraints -
CP-SAT: Support
Tableconstraints -
CP-SAT: Support
Automatonconstraints -
CP-SAT: Support
Inverseconstraints -
CP-SAT: Support
Reservoirconstraints -
CP-SAT: Support
Cumulativeconstraints -
CP-SAT: Support
Dummyconstraints -
Support other solvers