Hello :)
I have a complex objective function where the final expression is created by the linear aggregation of expressions in the model. That is, lets assume following simplified objective function:
F = e1 + e2 +... where
e1 = x1+x2+...+xi
e2 = min(xj,xk,e') e': could be another linear expression in the model
.
.
Some parts of the objective function expression include min/max. I'm wondering if anybody can shed some lights for expression aggregation since there is no way to cast IloNumExpr to IloLinearNumExpr.
I'm grateful for some help on this topic.
Topic

Re: expressions aggregation
20120727T12:05:33ZThis is the accepted answer. This is the accepted answer.Hello,
Could you precise your question ?
Why do you need to know whether the type of expression you define is linear or not ? Cannot you just use IloNumExpr ?
By the way, if you are using CPLEX optimizer and not CP Optimizer and if your question is more related to CPLEX modeling, I suggest you post your question on the CPLEX forum here.
Regards,
Philippe 
Re: expressions aggregation
20120727T15:39:31ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20120727T12:05:33Z
Hello,
Could you precise your question ?
Why do you need to know whether the type of expression you define is linear or not ? Cannot you just use IloNumExpr ?
By the way, if you are using CPLEX optimizer and not CP Optimizer and if your question is more related to CPLEX modeling, I suggest you post your question on the CPLEX forum here.
Regards,
Philippe
IloLinearNumExpr e1,e2,e3
e1.addTerm(5, X[0]);
e1.addTerm(3, X[1]);
e1.addTerm(7, X[2]);
e1.setConstant(10);
e2.addTerm(10, X[6]);
....
e2.addTerm(n, X20);
IloNumExpr e3 = model.min(e1,e2);
...
...
en
and the final expression is the summation of all expressions: F = e1+e2+...+en
what is really needed to build up the final expression is casting IloNumExpr expressions (e.g., e3) to IloLinearNumExpr in the course of iteration to be able to create the final expression in a loop. However, the casting is not plausible. So I'm wondering how we can deal with it! 
Re: expressions aggregation
20120730T16:19:29ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20120727T15:39:31Z
Thank you for your response here, Philippe! Actually I generate expressions individually for objective function in different steps according to particular patterns in a decision tree in my model. Afterward I sum up these expressions to construct the final expression. So I use IloLinearNumExpr to more easily build up linear expressions in loops. For instance,
IloLinearNumExpr e1,e2,e3
e1.addTerm(5, X[0]);
e1.addTerm(3, X[1]);
e1.addTerm(7, X[2]);
e1.setConstant(10);
e2.addTerm(10, X[6]);
....
e2.addTerm(n, X20);
IloNumExpr e3 = model.min(e1,e2);
...
...
en
and the final expression is the summation of all expressions: F = e1+e2+...+en
what is really needed to build up the final expression is casting IloNumExpr expressions (e.g., e3) to IloLinearNumExpr in the course of iteration to be able to create the final expression in a loop. However, the casting is not plausible. So I'm wondering how we can deal with it!
if I understand your problem, you only need to use the
operator on expressions. For example:+=
IloExpr objExp = IloIntExpr(env, 0); for (IloInt i = 0; i < n; i++) { for (IloInt j = i+1; j < n; j++) { objExp += a[i][j]*cost[i][j]; } }
Regards,
Olivier 
Re: expressions aggregation
20120820T21:03:16ZThis is the accepted answer. This is the accepted answer. ol
 20120730T16:19:29Z
Hello,
if I understand your problem, you only need to use the <pre class="jivepre">+=
</pre> operator on expressions. For example:
<pre class="jivepre">IloExpr objExp = IloIntExpr(env, 0); for (IloInt i = 0; i < n; i++) { for (IloInt j = i+1; j < n; j++) { objExp += a[i][j]*cost[i][j]; } }
</pre>
Regards,
Olivier