Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Quadratic expression in objective function, java cplex

    Posted Fri February 15, 2013 04:03 AM

    Originally posted by: SystemAdmin


    Hello!

    I'm solving a minimization problem using cplex java. I declare the objective function as linearNumExpression, but one of the terms requires the multiplication of two decision variables, so it becomes quadratic. My problem is that if I decplare the objective function as quadratic the rest of the terms that are linear are not working. Have you got any idea how I can overcome this problem? In other words how to use linear and quadratic terms together in the objective function?

    Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Quadratic expression in objective function, java cplex

    Posted Fri February 15, 2013 04:10 AM

    Originally posted by: SystemAdmin


    You can use IloNumExpr instead of IloLinearNumExpr. The former allows any kind of terms in it. Or collect the quadratic terms in an instance of IloQuadNumExpr and in the end use cplex.sum() to add the linear expression and the quadratic expression.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Quadratic expression in objective function, java cplex

    Posted Fri February 15, 2013 04:27 AM

    Originally posted by: SystemAdmin


    Thanks for the quick answer!
    If I use IloNumExpr I cannot use the addTerm. When you say to use cplex.sum() how exactly do you mean it? I provide you with the relevant part of my code

    IloLinearNumExpr obj_func = cplex.linearNumExpr();

    for(i = 0; i < numVs; i++)
    {
    for(j=0; j<numPs; j++)
    {
    obj_func.addTerm((0.2*tDriving[i][j]), y[i][j]); // y is a decision variable, tDriving is a double java variable
    }
    }

    for(j=0; j<numPs; j++)
    {

    for(i=0;i<numVs; i++)
    {
    IloQuadNumExpr p = cplex.quadNumExpr();
    for(int ii=0; ii<numEVs; ii++)
    {
    for (k=0; k<100; k++)
    {
    p.addTerm(1, n[j][k]ii,y[i][j]); // n is the second decision variable
    }
    }
    obj_func.add(p);
    }
    }
    cplex.addMinimize(obj_func);
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Quadratic expression in objective function, java cplex

    Posted Fri February 15, 2013 05:40 AM

    Originally posted by: SystemAdmin


    I think this should work:
    IloLinearNumExpr lin = cplex.linearNumExpr();
     
    for(i = 0; i < numVs; i++) {
      for(j=0; j<numPs; j++) {
        lin.addTerm((0.2*tDriving[i][j]), y[i][j]);
      }
    }
     
    IloQuadNumExpr quad = cplex.quadNumExpr();
    for(j=0; j<numPs; j++) {
      for(i=0;i<numVs; i++) {
        for(int ii=0; ii<numEVs; ii++) {
          for (k=0; k<100; k++) {
            quad.addTerm(1, n[j][k]ii,y[i][j]);
          }
        }
      }
    }
    cplex.addMinimize(cplex.sum(lin, quad));
    

    Please also refer to the QPex1.java, QPex2.java, and QPex3.java examples in the CPLEX distribution. They illustrate how to compose a quadratic objective function.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Quadratic expression in objective function, java cplex

    Posted Fri February 15, 2013 06:46 AM

    Originally posted by: SystemAdmin


    Thanks a lot Daniel! This works!
    #CPLEXOptimizers
    #DecisionOptimization