7110https://www.ibm.com/developerworks/community/forums/atom/replies?topicUuid=77777777-0000-0000-0000-000014954484Variable bounds do not work together with objective function in C++ CPLEX Replies2013-03-11T08:16:30.207ZIBM Connections - Discussion Forumurn:lsid:ibm.com:forum:77777777-0000-0000-0000-000014955299Re: Variable bounds do not work together with objective function in C++ CPLEX2013-03-11T08:16:30.207ZSystemAdmin110000D4XKactive2013-03-11T08:16:30.207Z
By how much does the solution violate the bounds?<br />
This may just be a matter of numerical roundoff. For example, a negative value like -1e-9 for a non-negative variable is within numerical tolerances, while a negative value of -0.1 is usually not.<br />
If the bound violation is not within numerical tolerances, could you attach your problem as SAV file and the offending solution as SOL file here?
none, view_forum, view_categoryurn:lsid:ibm.com:forum:77777777-0000-0000-0000-000014955174Re: Variable bounds do not work together with objective function in C++ CPLEX2013-03-10T09:24:07.611ZSystemAdmin110000D4XKactive2013-03-10T09:24:07.611Z
problem occurred again
none, view_forum, view_categoryurn:lsid:ibm.com:forum:77777777-0000-0000-0000-000014955173Re: Variable bounds do not work together with objective function in C++ CPLEX2013-03-10T09:23:24.249ZSystemAdmin110000D4XKactive2013-03-10T09:23:24.249Z
I still have one further question, because the problem occurred again. <br />
<br />
I have a lot of constraints and the optimal solution returned by cplex does not satisfy the variable bounds. <br />
<br />
Because of my previous experience, I think it might be because some constraints are incompatible (but this time, this is not easily checked), but why does cplex return an optimal solution, which does not satisfy the variable bounds (e.g. some variables are negative), and it does not say that my program is infeasible?<br />
<br />
Thank you
none, view_forum, view_categoryurn:lsid:ibm.com:forum:77777777-0000-0000-0000-000014954624Re: Variable bounds do not work together with objective function in C++ CPLEX2013-03-07T22:16:11.837ZSystemAdmin110000D4XKactive2013-03-07T22:16:11.837Z
Yes, I just tried this, and I saw that there was an error in the model (the - should always be a +). So now, it seems to work. Thanks a lot for your advise with the exportModel.
none, view_forum, view_categoryurn:lsid:ibm.com:forum:77777777-0000-0000-0000-000014954620Re: Variable bounds do not work together with objective function in C++ CPLEX2013-03-07T21:55:52.185ZSystemAdmin110000D4XKactive2013-03-07T21:55:52.185Z
To format code nicely you should wrap it into '{code}' tags.<br />
One thing you should do is to add cplex.exportModel("model.lp") right before you call cplex.solve(). This writes the model that CPLEX will solve into model.lp which is a human readable format. Then look at the created model.lp file. Do the bounds in the file look correct? Maybe post the file here.
none, view_forum, view_categoryurn:lsid:ibm.com:forum:77777777-0000-0000-0000-000014954617Re: Variable bounds do not work together with objective function in C++ CPLEX2013-03-07T21:45:44.882ZSystemAdmin110000D4XKactive2013-03-07T21:45:44.882Z
Thanks a lot for your reply. I still have the problem, and I don't understand it.<br />
<br />
This is how I define the model (sorry, I don't know how to format the post nicely): <br />
<br />
#define EPS 1.0e-3<br />
<br />
IloModel genInst (env);<br />
IloNumVarArray Sizes(env,N,0.25+EPS,1.0-EPS);<br />
IloObjective Weight = IloAdd(genInst, IloMaximize(env,IloSum(Sizes))); <br />
<br />
Then I have a loop where I add constraints like this (i1,.. are indices):<br />
<br />
genInst.add(Sizes<a href="http://www.ibm.com/developerworks/forums/">i1</a> + Sizes<a href="http://www.ibm.com/developerworks/forums/">i2</a> + Sizes<a href="http://www.ibm.com/developerworks/forums/">i3</a><=1);<br />
genInst.add(Sizes<a href="http://www.ibm.com/developerworks/forums/">i1</a> + Sizes<a href="http://www.ibm.com/developerworks/forums/">i2</a> + Sizes<a href="http://www.ibm.com/developerworks/forums/">i3</a> - Sizes[j] >= 1+EPS); <br />
<br />
Whenever I don't have any expression for the objectiv function (e.g. just leave it to be 1), I get values in the range ]0.25,1.0[ after I solve the LP, e.g. like this:<br />
<br />
Report 5: Best sum of sizes 1<br />
Size values<br />
0.251 0.251 0.251 0.251 0.251 0.251 0.251 0.251 0.251 0.251 0.75 0.75 0.75 0.75 0.75<br />
<br />
But when I set the objectiv function to be the sum of the variables, the variables of the solution are outside the range, e.g. <br />
<br />
Report 5: Best sum of sizes 2.219<br />
Size values<br />
-0.001 1.517 -1.516 1.262 0.251 -1.516 -1.516 -1.012 -0.76 0.251 2.265 0.243 1.254 0.999 0.498<br />
<br />
I tried different possibilities like adding the range restrictions as further constraints, which does not work either so I guess something with the way I add the constraints is wrong. There I tried to follow the populate-by-row solution as in http://www.tu-chemnitz.de/mathematik/discrete/manuals/cplex/doc/getstart/html/ilocplex13.html.
none, view_forum, view_categoryurn:lsid:ibm.com:forum:77777777-0000-0000-0000-000014954525Re: Variable bounds do not work together with objective function in C++ CPLEX2013-03-07T18:25:34.218ZSystemAdmin110000D4XKactive2013-03-07T18:25:34.218Z
What exactly is your EPS and what are the invalid solution values you get? I just tried the following here and it worked without problem:<br />
<pre class="jive-pre">
<code class="jive-code jive-java">
#include <iostream> #include <ilcplex/ilocplex.h> #define N 5 #define EPS 1e-6 <span style="color: navy">
<b>
int</b></span> main(<span style="color: navy">
<b>
void</b></span>) <span style="color: navy">
{</span> IloEnv env; IloModel genInst (env); IloNumVarArray Sizes(env,N,0.25+EPS,1.0-EPS); IloObjective Weight = IloAdd(genInst, IloMaximize(env,IloSum(Sizes))); IloCplex cplex(genInst); cplex.exportModel(<span style="color: red">
"bounds.lp"</span>); cplex.solve(); IloNumArray vals(env); cplex.getValues(Sizes, vals); <span style="color: navy">
<b>
for</b></span> (IloInt i = 0; i < vals.getSize(); ++i) std::cout << vals[i] << std::endl; <span style="color: navy">
<b>
return</b></span> 0; <span style="color: navy">
}</span></code>
</pre>
<br />
How does the bounds.lp file look like when you plug in your EPS and your N? And what solution values do you get?
none, view_forum, view_category