1

I am trying to solve a model on Matlab by using CPLEX. When the objective is

Maximize x1 + 2 x2 + 3 x3 + x4

Introducing cplex.Model.obj = [ 1; 2; 3; 1]; is enough.

What shall I do when the objective is

Maximize abs(x1) + 2 x2 + 3 x3 + x4

  • I don't know if CPLEX or it's matlab-API support this out of the box, but i'm assuming the docs are high-quality and will answer that (i'm no CPLEX user). But you can always (some conditions; your task looks ok) do this [manually](http://lpsolve.sourceforge.net/5.1/absolute.htm) (lp_solve's docs with an extra section about it). – sascha Mar 05 '18 at 01:04
  • Thank you for your example. I can't linearize the objective because this was a very simplified example. I will try to use in a more complicated function. And I find IBM's documentation very lacking. It is hard to find things. – independentvariable Mar 05 '18 at 01:14
  • Then either explain why you can't do it or bring additional info about your model. Every linearization of something nonlinear should be based on some assumptions (or let's call it: nonsmooth -> smooth). If CPLEX would do this for you, it would not be different in it's core (i know Gurobi supports it; and of course other libs like cvx which serve a different purpose; the latter actually might be an alternative for you in some cases **edit: oops:** seems there are some restrictions to solver-support; unlike python's cvxpy). – sascha Mar 05 '18 at 01:17
  • Oh.. I was using Yalmip actually, which was providing abs() function in matlab easily. However, now I need to save time so I can't use these tools like Yalmip or CVX. Are you sure that I need to linearize CPLEX? If that's the case I will play with the model. I was using 10000*z >= abs(x) where z is binary vector of size 2^n and x is a real vector of size 2^n. (Note that this is not in the objective but constraint). Do I need to split it to 10000*z >= x and -10000*z>= x – independentvariable Mar 05 '18 at 01:42
  • i think this is more an issue within the modelbuilding: if you have abs(x1) in your objective function the model is no longer linear. What you can do to keep it linear is to create some additional decision variables like `x1 = (x1a - x1b)` and constraints that forces `x1a=0` if `x1b > 0` and the other way around. Then you can add both in the objective function `Maximize x1a + x1b + ...` to have a linear modell AND an absolute value. – Finn Mar 05 '18 at 09:42

1 Answers1

1

The short answer is that the CPLEX MATLAB API does not support an absolute value function "out of the box". So, as suggested in the comments, if you want to use the MATLAB API, you'll have to formulate it yourself. However, the C++, Java, and .NET Concert APIs do support abs (e.g., for the Java API see here). It is also supported in the docplex modeling API (see here).

The documentation for the CPLEX MATLAB API for version 12.8 (currently, the latest release) is here. I'm not sure if it will help make the documentation easier to use, but for me it is far easier to navigate if you click on the "Table of contents" link in the upper-left corner. This will allow you to expand the documentation tree and hop around easier. It is definitely worth looking at the examples that are shipped with CPLEX.

rkersh
  • 4,447
  • 2
  • 22
  • 31