Search code examples
minizinc

Calling minizinc from cpp program


Is there a possible way to call a constrained model defined in minizinc, as a function call from a C++ program? My environment is VS 2017 (if it matters).


Solution

  • There are two options to use MiniZinc from an C++ project. Probably the easiest way is to use fork and execv. With a combination of these two commands you can just run the minizinc executable with any flags and files that you deem necessary However this does require the user to have MiniZinc installed and available on the system path ($PATH).

    The second way would be to use libminizinc as a C++ library. The source for the MiniZinc compiler/driver can be found here: https://github.com/MiniZinc/libminizinc and can be used as a library. The current support for this kind of behaviour is very limited however. Within a few months, the MiniZinc team intends to release a C API to libminizinc that will likely make the process a lot easier. In the meantime if you choose to use this approach, I would suggest you start your journey from the main.cpp file, as this will likely show you how to use the library.

    Note that even if you take the second approach, FlatZinc solvers like OR Tools, Chuffed, and Oscar CBLS, need to be available on the system path to be available within your application.