Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  cplex eclipse - summation

    Posted 07/10/18 12:08 AM

    Originally posted by: vahid_mlkr


    Hi

    I was wondering that after importing cplex to eclipse, does the following functions return the summations over all i and j of the arrays or not.

    Let's say:

     m =10; n=10; I = {1,..,10}; t={1,...,10}  J = {1,..,10}; i in I and j in J

    Considering Xi,j,t as the decision variable, Li,j as a Binary variable and C as a constant.

    =======

    //defining the decision variable

    IloNumVar [][][] x = new IloNumVar[m][][];
    for(int i=0; i<m; i++) {
    x[i] = new IloNumVar[n][];
    for(int j=0; j<n; j++) {
    x[i][j] = cplex.boolVarArray(t);
        }
    }

    //defining an expression, the value of a parameter called D

    IloNumExpr D = cplex.numExpr();
    for (int i = 0; i<m; i++){
    for(int j=0; j<n; j++) {
    for (int k = 0 ; k<t.length; t++){
    D = cplex.prod(cplex.prod(x[i][j][tt], L[i][j]), c);

    =========

    Does this D retrieves the summation over all i and j OR is it just retrieving a single value over a single i and j at a time ?

    What I mean is that does cplex.prod (since I have 3 parameters (decision variable, binary variable and constant, all to be multiplied to each other) does the same job as cplex.addTerm ?

    =========

    As best of my understanding cplex.addTerm is of course additive and does the summation over all i and j (if I have understood that correctly)

    =========

    And my 2nd question is if this ever considered as a linear or quadratic problem ?

    Many thanks in advance


    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: cplex eclipse - summation

    Posted 07/10/18 02:35 AM

    The expression

    cplex.prod(cplex.prod(x[i][j][tt], L[i][j]), c);

    computes c*x[i][j][t]*L[i][j] as expected. But just assigning this to D will not sum up anything. At the end of the loop, D will just point to the last term created in that way. What you need is something D = cplex.sum(D, <your term here>), so that the new term is added to D.

    But there is a much easier and much more efficient way to do that: Use IloQuadNumExpr:

    IloQuadNumExpr D = cplex.quadNumExpr();
    for (...) for (...) for (...) D.addTerm(c, x[i][j][tt], L[i][j]);

    And yes, with this sort of expression your model will have a quadratic objective and/or quadratic constraints, depending on where you use that expression.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: cplex eclipse - summation

    Posted 07/10/18 05:38 PM

    Originally posted by: vahid_mlkr


    Thanks a lot. Really appreciated

    I took your advise and modified the last line as follows

    D = cplex.sum(D, cplex.prod(cplex.prod(x[i][j][tt], L[i][j]), c));

    ======

    I tried your 2nd advise as well to see the differences:

    IloQuadNumExpr D = cplex.quadNumExpr();
    for (...) for (...) for (...) D.addTerm(c, x[i][j][tt], L[i][j]); 

    This one returned an error message that:

    The method addTerm(double, IloNumVar, IloNumVar) in the type IloQuadNumExpr is not applicable for the arguments 
     (IloNumVar, double, double)

    So, it seems it requires 2 variables of type "IloNumVar" but instead I have one variable of type IloNumVar and 2 variables of type double

    Many thanks again


    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: cplex eclipse - summation

    Posted 07/11/18 01:06 AM

    About the problem with IloQuadNumExpr: I think you messed up the arguments to the addTerm() function. As you can see from the error message, you passed one instance of IloNumVar (or IloIntVar, a subclass of that) and two instances of 'double' (which are just plain numbers). So you did not pass two variables and a coefficient but one variable and two coefficients. Two multiply to 'double's, you don't need cplex.prod() or anything. Just use the '*' operator.

     

    About the multiple objective error: you call cplex.addMinimize() inside the loop. Thus in each iteration you add a new objective. CPLEX can only handle one objective. Move the call to cplex.addMinimize() out of the loop.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: cplex eclipse - summation

    Posted 07/11/18 11:26 PM

    Originally posted by: vahid_mlkr


    Thanks a lot

    And is there any way to print the values of the decision variables ?

    I went through all the available functions of "cplex.get...." and couldn't really find one that can do this. I was trying cplex.getBasisStatuses and cplex.getValues

    Basically I am working on an assignment problem and I want to see if job j is assigned to agent i at time tt in my model. That's why the result of the objective function itself is not sufficient enough

    I have 3 different decision variables x[i][j][tt], y[i][tt] and z[i][j][tt] and wondering if it is possible to have their values in eclipse similar to what cplex itself shows when we model the problem at there.

    Many thanks

     


    #DecisionOptimization
    #MathematicalProgramming-General


  • 6.  Re: cplex eclipse - summation

    Posted 07/12/18 04:29 AM

    You can use System.out.println() to dump the values to the console output.

    If you want any sort of widget to display the values then you will have to roll your own. If you want to show this integrated inside eclipse then you will have to write an eclipse plugin.


    #DecisionOptimization
    #MathematicalProgramming-General


  • 7.  Re: cplex eclipse - summation

    Posted 07/10/18 09:26 PM

    Originally posted by: vahid_mlkr


    And I do highly appreciate if you please can provide  some hints for the following problem in conjunction with above.

    I changed the above expression to the linear expression by taking out the L[i][j]. Since L[i][j] is a binary variable, I modified the above as follows:

    ============

    IloLinearNumExpr D = cplex.linearNumExpr();
     
    for (int i = 0; i<m; i++){
         for(int j=0; j<n; j++) {
              for (int tt = 0 ; tt<td_max.length; tt++){
                         if ( L[i][j] == 1 ) 
    D.addTerm(x[i][j][tt], c);
           }
       }
    }

    ============

    I have something similar as above for 2 more decision variables and I will be having E.addTerm(y[i][j], c) and F.addTerm(z[i][j][tt], c);

    ============

    IloLinearNumExpr obj = cplex.linearNumExpr();
    for (int i = 0; i<m; i++){
         for(int j=0; j<n; j++) {
              for (int tt = 0 ; tt<td_max.length; tt++){
                   if(L[i][j] == 1)
     
    obj.addTerm(x[i][j][tt], c);
    obj.addTerm(y[i][tt], c);
    obj.addTerm(z[i][j][tt], c);
    cplex.addMinimize(obj);

          }
       }

    }

    ============

    Basically I want to minimize (D + E + F). This code doesn't have any syntax error but it returns the ilog.cplex.MultipleObjectiveException
    I tried to remove the 2nd and 3rd line of objective and remain with x[i][j][tt] just to see if I can at least get something out of it, but the error is still remained the same
    Many thanks in advance

    ============


    #DecisionOptimization
    #MathematicalProgramming-General