Trying to get cplex to work with minizinc

185 views
Skip to first unread message

Christopher Calzonetti

unread,
Jul 18, 2023, 2:08:51 PM7/18/23
to MiniZinc
Hi there.  I'm very new to minizinc, and I'm trying to get it working with cplex as a solver.

My apologies that this is kind of long and rambly.

We're using the prepackaged version of minizinc available from the ubuntu22 repos:

ccalzone@cpu155:~$ dpkg -l | grep minizinc
ii  minizinc                                         2.5.3+dfsg1-1                              amd64        constraint modelling language and tool chain
ccalzone@cpu155:~$ dpkg -l | grep zinc
ii  flatzinc                                         6.2.0-5                                    amd64        constraint problem modelling language
ii  libgecodeflatzinc49                              6.2.0-5                                    amd64        Gecode support for FlatZinc modelling language
ii  minizinc                                         2.5.3+dfsg1-1                              amd64        constraint modelling language and tool chain


And a locally packaged version of cplex:

ccalzone@cpu155:~$ which cplex
/opt/uw/cplex/22.1.0/cplex/bin/x86-64_linux/cplex
ccalzone@cpu155:~$ cplex

Welcome to IBM(R) ILOG(R) CPLEX(R) Interactive Optimizer 22.1.0.0
  with Simplex, Mixed Integer & Barrier Optimizers
5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5655-Y21
Copyright IBM Corp. 1988, 2022.  All Rights Reserved.

Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.

CPLEX> 

As a test, I'm just using a pretty simple Chessboard Queens problem which runs fine with the builtin solvers:

ccalzone@cpu155:~/Work/minizinc$ cat nqueens.mzn
int: n = 4;
array [1..n] of var 1..n: q; % queen in column i is in row q[i]

include "alldifferent.mzn";

constraint alldifferent(q);                       % distinct rows
constraint alldifferent([ q[i] + i | i in 1..n]); % distinct diagonals
constraint alldifferent([ q[i] - i | i in 1..n]); % upwards+downwards

% search
solve :: int_search(q, first_fail, indomain_min)
      satisfy;
output [ if fix(q[j]) == i then "Q" else "." endif ++
         if j == n then "\n" else "" endif | i,j in 1..n];
         
output [ "q_t = ", show(q)];
ccalzone@cpu155:~/Work/minizinc$ minizinc nqueens.mzn
..Q.
Q...
...Q
.Q..
q_t = [2, 4, 1, 3]
----------


I tried setting my preferences files set up like this:

ccalzone@cpu155:~/Work/minizinc$ cat ~/.minizinc/Preferences.json
{
  "tagDefaults": [["cplex","org.minizinc.cplex"]],
  "solverDefaults": [["org.minizinc.cplex","--cplex-dll","/opt/uw/cplex/22.1.0/cplex/bin/x86-64_linux/libcplex2210.so"]]
}
ccalzone@cpu155:~/Work/minizinc$ cat ~/.minizinc/solvers/cplex.msc
{
"id": "org.minizinc.cplex",
"name": "cplex",
"version": "22.10",
"executable": "/opt/uw/cplex/22.1.0/cplex/bin/x86-64_linux/cplex"
}


And indeed it looks like minizinc can see them:

ccalzone@cpu155:~/Work/minizinc$ minizinc --solvers
MiniZinc driver.
Available solver configurations:
  cplex 22.10 (org.minizinc.cplex)
  Gecode 6.2.0 (org.gecode.gecode, default solver, cp, int, float, set, restart)
  Gecode Gist 6.2.0 (org.gecode.gist, cp, int, float, set, restart)
Search path for solver configurations:
  /u/ccalzone/.minizinc/solvers
  /usr/share/minizinc/solvers
  /usr/local/share/minizinc/solvers


But when I try to use the cplex solver:

ccalzone@cpu155:~/Work/minizinc$ minizinc --solver cplex nqueens.mzn
minizinc: Unrecognized option or bad format `--cplex-dll'
minizinc: MiniZinc driver.
Usage: minizinc  [<options>] [-I <include path>] <model>.mzn [<data>.dzn ...] or just <flat>.fzn
More info with "minizinc --help"

And if I take out that --cplex-dll line from my Preferences.json file, I get a different error:

ccalzone@cpu155:~/Work/minizinc$ minizinc --solver cplex nqueens.mzn
Warning: invalid configuration file: internal error

Incorrect usage. Correct command syntax is:
   /opt/uw/cplex/22.1.0/cplex/bin/x86-64_linux/cplex [-i] [-f <commandfile> | -c "<command1>" "<command2>" ...]
Exiting
=====UNKNOWN=====


I thought maybe it wanted me to put a -f option in the executable line, which I tried, and that gave me:

ccalzone@cpu155:~/Work/minizinc$ minizinc --solver cplex nqueens.mzn
Warning: invalid configuration file: internal error
MiniZinc: internal error: Error occurred when executing FZN solver with command "/opt/uw/cplex/22.1.0/cplex/bin/x86-64_linux/cplex -f /tmp/mznfileS7IUMr.fzn ".
=====ERROR=====


Any idea how I can get this working?

Christopher

guido.tack

unread,
Jul 18, 2023, 9:00:32 PM7/18/23
to MiniZinc
Hi Christopher,

Unfortunately, the version of MiniZinc that comes packaged with Ubuntu and other distros is out of date (it's more than 2.5 years old now). I would highly recommend updating to the latest version, using one of the pre-built packages for linux from the MiniZinc website. That should most likely resolve the issue with cplex.

Cheers,
Guido

vdi...@gmail.com

unread,
Jul 19, 2023, 5:13:07 AM7/19/23
to MiniZinc
I could not find any cplex distro on the minizinc site. I tried the executable which comes with ampl (this action works for couenne). But cplex misses  libcplex libraries and the ampl license file. I tried using the msc as mentioned in this conversation, but cplex did not show up in minizinc. Maybe the manual can mention the syntax for all solvers; now it is guessing how the syntax maybe can be. The only example for couenne in the manual works.

Op woensdag 19 juli 2023 om 03:00:32 UTC+2 schreef guido.tack:

guido.tack

unread,
Jul 19, 2023, 11:00:14 PM7/19/23
to MiniZinc
MiniZinc comes with the interface to CPLEX compiled into the binary, but not with the CPLEX shared library itself (due to its commercial licensing). You will need to install CPLEX from the IBM installer packages. MiniZinc should then be able to find CPLEX either automatically (i.e., just by calling minizinc with the --solver cplex argument), or you may have to specify the location of the CPLEX dll on the command line. No other configuration should be required.

Cheers,
Guido

vdi...@gmail.com

unread,
Jul 20, 2023, 3:28:30 AM7/20/23
to MiniZinc
Does a dll work under Linux,  as the original question is about Linux? And the IBM stuff looks like a Windows application to me.

Op donderdag 20 juli 2023 om 05:00:14 UTC+2 schreef guido.tack:

Luis Quesada

unread,
Jul 27, 2023, 5:18:01 AM7/27/23
to MiniZinc
Dear all,
I am trying to get the latest version of cplex (22.1.1) to work with MiniZinc (2.7.6) in my Apple M1 Pro running Ventura 13.4.1.
Before what I used to do with cplex 20.1 was to use the jnilib provided. This, together with the 'arch -x86_64' trick, used to work fine.
The problem now is that cplex 22.1.1 does not come with the libcplex file (as you can see below).
What am I supposed to do now?
Thanks a lot in advance!
Cheers,
Luis
cplexIssue.pdf

Luis Quesada

unread,
Jul 27, 2023, 7:41:32 AM7/27/23
to mini...@googlegroups.com
Grace Tacadao made me realise that libcplex2211.dylib would do the job.
The other thing is that with the latest arm64 version the arch -x86_64 is no longer needed.
Cheers,
Luis

--
You received this message because you are subscribed to a topic in the Google Groups "MiniZinc" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/minizinc/vAPuc4guUGs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to minizinc+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/minizinc/e40e9e43-406b-4fd2-853d-2483482822cfn%40googlegroups.com.
cplexIssue.pdf
Reply all
Reply to author
Forward
0 new messages