-1

can CPLEX, e.g., in python API, solve a problem like max( Sum(log(x)) )? Basically i have a problem with logarithmic ( as simple as log(x) ) objective and linear constraints.

best, Pavlos

1 Answers1

0

then you could use CPOptimizer:

In OPL the following code works fine

using CP;

dvar int x in 0..100000;
dvar int y in 0..100000;

dexpr float ax=1+x/1000;
dexpr float ay=1+y/1000;

minimize log(ax-ay);
subject to
{
  abs(ax-ay)>=1;
}

and with python docplex you can write

from docplex.cp.model import CpoModel

mdl = CpoModel(name='buses')
x = mdl.integer_var(0,100000,name='x')
y = mdl.integer_var(0,100000,name='y')
mdl.add(mdl.abs(x/1000-y/1000)>=1);
mdl.minimize(mdl.log(mdl.abs(x/1000-y/1000)))

msol=mdl.solve()

print("x=",msol[x])
print("y=",msol[y])
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • thanks for your answer. I followed the documentation for docplex as well, thanks. So in order to have a log obj function i need to use docplex, it can't be done with cplex python api? I am asking because i have my problem build (among with other things) in cplex, and docplex syntax is a bit different – Pavlos Basaras Jan 16 '20 at 14:09
  • If in your objective you have a "log" of some decision variable then you should either use CPOptimizer or linearize your log function through piecewise linear function. – Alex Fleischer Jan 16 '20 at 15:17
  • thanks again for your prompt replies. I see from http://ibmdecisionoptimization.github.io/docplex-doc/mp_vs_cp.html that cp problems do not support continuous variables, and that mp problems do no support log objective functions. My problem has continuous and binary decision variables with log obj function, so it cannot be addresed by this, correct? Is there any other solution? Thanks again. – Pavlos Basaras Jan 16 '20 at 17:10
  • for the continuous decision variables with cpo see https://stackoverflow.com/questions/59766834/cplex-studio-does-not-support-dvar-float/59767374#59767374 – Alex Fleischer Jan 16 '20 at 17:57
  • As log is monotonic increasing, minimizing log(z) is equivalent to minimizing z, so in your case minimizing abs(x/1000 - y/1000) which docplex.mp is able to express – Philippe Couronne Jan 20 '20 at 14:38