Topic
• 4 replies
• Latest Post - ‏2012-08-20T21:03:16Z by SystemAdmin
378 Posts

# Pinned topic expressions aggregation

‏2012-07-26T18:24:39Z |
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.
Updated on 2012-08-20T21:03:16Z at 2012-08-20T21:03:16Z by SystemAdmin
378 Posts

#### Re: expressions aggregation

‏2012-07-27T12: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
378 Posts

#### Re: expressions aggregation

‏2012-07-27T15:39:31Z
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
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.setConstant(10);
....
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!
• ol
51 Posts

#### Re: expressions aggregation

‏2012-07-30T16:19:29Z
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.setConstant(10);
....
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!
Hello,
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
378 Posts

#### Re: expressions aggregation

‏2012-08-20T21:03:16Z
• ol
• ‏2012-07-30T16:19:29Z
Hello,
if I understand your problem, you only need to use the <pre class="jive-pre">``` +=``` </pre> operator on expressions. For example:

<pre class="jive-pre">``` 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