Topic
4 replies Latest Post - ‏2012-08-20T21:03:16Z by SystemAdmin
SystemAdmin
SystemAdmin
386 Posts
ACCEPTED ANSWER

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
  • SystemAdmin
    SystemAdmin
    386 Posts
    ACCEPTED ANSWER

    Re: expressions aggregation

    ‏2012-07-27T12:05:33Z  in response to SystemAdmin
    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
    • SystemAdmin
      SystemAdmin
      386 Posts
      ACCEPTED ANSWER

      Re: expressions aggregation

      ‏2012-07-27T15:39:31Z  in response to SystemAdmin
      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!
      • ol
        ol
        32 Posts
        ACCEPTED ANSWER

        Re: expressions aggregation

        ‏2012-07-30T16:19:29Z  in response to SystemAdmin
        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
        • SystemAdmin
          SystemAdmin
          386 Posts
          ACCEPTED ANSWER

          Re: expressions aggregation

          ‏2012-08-20T21:03:16Z  in response to ol
          Thanks a lot for your reply here, Olivier! It's been resolved