0
votes

I have this simple optimization problem with 4 variables and I want to maximize a simple objective.

 dvar float+ x1;
 dvar float+ x2;
 dvar float+ x3;
 dvar float+ x4;
 
 maximize -0.4311513304710388 * x1 + 0.7867446541786194 * x2 +
  0.9110395312309265 * x3 + 0.130537211894989 * x4;
 subject to {
   -1 <= x1 <= 1;
   -1 <= x2 <= 1;
   -1 <= x3 <= 1;
   -1 <= x4 <= 1;
 }

The optimal answer should be x1 = -1 and x2 = x3 = x4 = 1 resulting in total value of 2.2594727277755737. But CPLEX somehow always ignores the variables with negative coefficients and just chooses x1 = 0 and x2 = x3 = x4 = 1 and gives answer as 1.82832139730453. What am I doing wrong here?

1
dvar float+ x1; declares x1 as a non-negative float. Similarly for the other variables. - njuffa
@njuffa thanks. Please add it as an answer so I can mark it as accepted. - Samvid Mistry
I actually don't know CPLX, my comment was based on simply looking at the documentation. A proper answer has since been posted. I would suggest upvoting and accepting that. - njuffa

1 Answers

0
votes
dvar float x[1..4] in -1..1;
 
 maximize -0.4311513304710388 * x[1] + 0.7867446541786194 * x[2] +
  0.9110395312309265 * x[3] + 0.130537211894989 * x[4];
 subject to {
   
 }

gives

// solution (optimal) with objective 2.25947272777557


x = [-1
         1 1 1];