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. This package builds its own version of OR-Tools and, on Linux, the libraries abseil, re2, protobuf, and protobuf-c.
Online docs: https://inria.github.io/ocaml-ortools/
opam install ocamlfind ortools_solvers
ocamlfind ocamlopt -o cp_is_fun_sat.exe \
-package ortools_solvers -linkpkg \
samples/sat/cp_is_fun_sat.ml
./cp_is_fun_sat.exe
-
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
The ortools-solvers package tries to solve the difficulties of installing
CP-SAT on a given platform and calling it from an OCaml program. To do this,
the source of OR-Tools and required libraries is included in the package and
built with the OCaml interface.
On macOS, the build relies on the homebrew packages abseil, protobuf,
protobuf-c, and re2, and also an internal build of eigen3. On Linux,
all of these libraries are built internally.
There are currently a number of known imperfections based on assumed limitations of dune (at the time of writing):
-
The build assumes that it is possible to run
cmake -j 8(ortools_solvers/dune). Running without any parallelism is much slower, but requesting too much parallelism can overwhelm the build machine. Dune does not currently provide a way of sharing cores between itself and an external build process controlled bycmake/make. See this discussion. -
To run an OCaml program that uses
ortools-solvers, the loader must be able to findlibortools.so(and alsolibabsl_log_internal_message.so,libabsl_raw_logging_internal.so,libabsl_raw_hash_set.so, andprotobuf.so). This is not a problem onceortools-solversis installed since the stub uses$CAMLORIGINto specify the-Land-rpathflags (ortools_solvers/stubs/dune). However, to test against a local build before installation, it is necessary to manually set and export eitherDYLD_LIBRARY_PATH(macOS) orLD_LIBRARY_PATH(Linux). This is also the reason why the build does not try to run such tests, e.g., by running the programs insamples/sat, during continuous integration. (DYLD_LIBRARY_PATH=_build/install/default/lib/ortools_solvers dune exec -- samples/sat/cp_is_fun_sat.exe).