0

My objective function in IBM CPLEX is as follows:

objective = opt_model.sum(math.log(r_vars[0,0]*(3*w_vars[0]-1))+math.log(r_vars[1,0]*(3*w_vars[0]-1)))
opt_model.maximize(objective)

The variable w_vars can get a value in the range [0,1] and the value of r_vars can be in the range of [1,100]. But I am getting this error:

TypeError: must be real number, not QuadExpr

I assume the problem is the result of the parentheses for the math.log function. How can I use a log function in the objective function in IBM CPLEX? Or any thoughts on this?

  • Cplex does not do nonlinear programming (with some limited exceptions like quadratic problems or some integer problems). Nonlinear programming problems are almost always better solved with nonlinear programming (NLP) solvers. – Erwin Kalvelagen Feb 08 '23 at 03:47

1 Answers1

1

What you could do is rely on cpo within Cplex

See

https://github.com/AlexFleischerParis/zoodocplex/blob/master/zoononlinear.py

For a tiny example

from docplex.cp.model import CpoModel

mdl = CpoModel(name='buses')
nbbus40 = mdl.integer_var(0,1000,name='nbBus40')
nbbus30 = mdl.integer_var(0,1000,name='nbBus30')
mdl.add(nbbus40*40 + nbbus30*30 >= 300)

#non linear objective
mdl.minimize(mdl.exponent(nbbus40)*500 + mdl.exponent(nbbus30)*400)

msol=mdl.solve()

print(msol[nbbus40]," buses 40 seats")
print(msol[nbbus30]," buses 30 seats") 
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15