Call gecode from Java using MiniZinc model

437 views Asked by At

I would like to solve a model with dynamic arguments at run-time in Java. I have my problem written in MiniZinc. From a terminal I can solve the model by calling the following commands:

mzn2fzn model.mzn model_data.dzn  (this produces model.fzn file)
fzn-gecode model.fzn (actually solves the model)

Basically there are 2 steps, first I need to compile minizinc model into flatzinc format while supplying the data file, and then I need to run gecode itself on the flatzinc model.

Ofcourse I can do these steps by calling an external process (using ProcessBuilder in Java or subprocess 'like' in python). But I would like to know if there is a better way. Particularly I would like to avoid recompiling my model into flatzinc for every call.

Is there some alternatives to the way I am trying to call gecode?

Thanks!

1

There are 1 answers

0
Dekker1 On BEST ANSWER

The is currently no direct interface from Java to libminizinc, written in C++. The best option is thus to run MiniZinc as an external process.

However, you don't have to call two separate processes. Using the process mzn-fzn, found in the MiniZinc 2 distribution, you can compile and run using a given solver while only constructing one process.

The given code could thus be expressed as: mzn-fzn --solver fzn-gecode model.mzn model_data.dzn

You can avoid saving the data to a file by using the -D flag.