Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Java api complex Objective function

    Posted 01/08/15 06:54 PM

    Originally posted by: has246


    I have a model which i want to apply. The objective function is as follows:

    Ithe x is a binary variable which is held in a IloIntVar[][][]

     

    the second part on the right was easy. My problem is with the left part.

    I tried ti do it as follows

    for (int i = 1; i <= 5; i++)
    {
        IloLinearIntExpr exp = cplex.linearIntExpr();
        for (int j = 1; j <= 4; j++)
        {
            for ( int k = 1; k <= 3; k++)
            {
                // this is my problem
                exp.addTerm(1, x[i][r][p]);
            }
        }
    }
    

    how do I add the: 1 - the term here?

    and how do I multiply it by 5. I tried it alot and I cant cast Ilointexpr to IloLinearIntExpr

     

    Thanks for any help


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Java api complex Objective function

    Posted 01/09/15 02:36 AM

    There are two options:

    1. Use the more generic type IloIntExpr, like so

             for (int i = 1; i <= 5; i++) {
                IloLinearIntExpr exp = cplex.linearIntExpr();
                for (int j = 1; j <= 4; j++) {
                   for ( int k = 1; k <= 3; k++) {
                      exp.addTerm(1, x[i][j][k]);
                   }
                }
                IloIntExpr a = cplex.diff(1, exp);
                IloIntExpr b = cplex.prod(5, a);
             }
    

    2. Explicitly expand the '5 *' and '1 - ' operations:

             for (int i = 1; i <= 5; i++) {
                IloLinearIntExpr exp = cplex.linearIntExpr(5);
                for (int j = 1; j <= 4; j++) {
                   for ( int k = 1; k <= 3; k++) {
                      exp.addTerm(-5, x[i][j][k]);
                   }
                }
             }
    

     


    #CPLEXOptimizers
    #DecisionOptimization