Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Compicated constraints

    Posted 04/17/12 02:37 PM

    Originally posted by: FANS_Nader_Al_Theeb


    Hello, Dear all

    (Using CPLEX - C++):

    I have the complicated constraint shown in the attachment. The constraint should be applied for all (c, o, and t). Left hand side has summations of (tau and P). Whereas the right hand side has summations of ( tau, h, and p) ahich is not the same of left hand side. can any one help me to do that constraints.

    I have the following thoughts so far



    for ( c=0; c<nbComm; c++){
    IloExpr expr(env);
    IloExpr expr2(env);
    IloExpr expr3(env);

    for( o=0; o<nbDNodes; o++){

    for ( t=0; t<curr_t; t++){

    for ( tau=0; tau<t; tau++){

    expr3 += dcot [c] [o] tau ;

    for ( p=0; p<nbNodes; p++){

    if (o==p) {continue;}

    if (top[p][o]>curr_t) {expr=expr + Q_copt[c][o][p]tau;}
    if (top[p][o]<=curr_t){expr=expr + (-1*Q_copt[c][p][o]tau) + Q_copt[c][o][p]tau;}
    for ( h=0; h< nbWoundedCat; h++){

    expr2 += -1*(fc[c] * X_hopt[h][o][p]tau);

    }//end h loop
    }//end tau loop
    }//end p loop
    }//end t loop

    model.add(expr - DEV_cot[c][o]t-1 == expr3 - expr2);

    expr.end();
    expr2.end();
    expr3.end();

    }// end o loop
    }// end c loop


    As a general Idea is that correct? And in this case, I received a segmentation fault because I end the expressions after t-loop, then I re-use them. To solve that, I put the IloExpr definition before starting the loops, then I end them after the loops, I know this is not correct because the expressions will accumulate the values.

    Any help about such constraints, and does the IloExprArray help in such cases?

    Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Compicated constraints

    Posted 04/18/12 01:07 AM

    Originally posted by: SystemAdmin


    I did not check the math of your constraints but to get rid of the segmentation faults just move the initialization of the IloExpr instances from the beginning of the c-loop to the beginning of the o-loop:
    for ( c=0; c<nbComm; c++){
       for( o=0; o<nbDNodes; o++){ 
          IloExpr expr(env);
          IloExpr expr2(env);
          IloExpr expr3(env);
     
          for ( t=0; t<curr_t; t++){
             ...
          } //end t loop
     
          model.add(expr - DEV_cot[c][o]t-1 == expr3 - expr2);
     
          expr.end();
          expr2.end();
          expr3.end();
       }// end o loop
    }// end c loop
    

    And please wrap source code into '{code}' tags in your posts. That makes it much easier to read your code.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Compicated constraints

    Posted 04/18/12 07:41 PM

    Originally posted by: FANS_Nader_Al_Theeb


    Thank you Daniel for your help, may I ask you other question:

    In some constraints such as

    sum~m~ V~opmt~ [o][p][m][t] * cap[m] >= sum~c~ w~c~[c] * Q~copt~[c][o][p][t] + sum~h~ w~h~[h] * X~hopt~ [h][o][p][t] for all o,p,t

    In the previous constraint, For all indices are o,p, and t, but the summations indices are m,c, and h. I can't use for loops in this case, because if I use 3 for loops (o,p, and t), I need after that the final value summations, I mean that I can't use other m,c, and and h loops inside the first three because the last one (h loop) will be done m by c times, not just one at each o,p,t

    any help for doing such constraints

    Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Compicated constraints

    Posted 04/18/12 07:44 PM

    Originally posted by: FANS_Nader_Al_Theeb


    Sorry for bad writing, I use subscripts as shown in plain text help, but it doesn't work

    sum~c~ means sum sum c

    V~opmt~ means V sub opmt

    and so on
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Compicated constraints

    Posted 04/19/12 02:41 AM

    Originally posted by: SystemAdmin


    Even with your correction the constraints are hard to read. I am not sure whether I understood correctly. Do you mean
    for all o, p, t
       sum(m) V[o][p][m][t] * cap[m] >= sum(c) w[c] * Q[c][o][p][t] + sum(h) w[h] * X[h][o][p][t]
    

    This could be achieved by the following loops:
    for (o = 0; o < ...; ++o) {
       for (p = 0; p < ...; ++p) {
          for (t = 0; t < ...; ++t) {
             // Build sum(m) V[o][p][m][t] * cap[m]
             IloExpr expr1(env);
             for (m = 0; m < ...; ++m)
                expr1 += V[o][p][m][t] * cap[m];
             // Build sum(c) w[c] * Q[c][o][p][t]
             IloExpr expr2(env);
             for (c = 0; c < ...; ++c)
                expr2 += w[c] * Q[c][o][p][t];
             // Build sum(h) w[h] * X[h][o][p][t]
             IloExpr expr3(env);
             for (h = 0; h < ...; ++h)
                expr3 += w[h] * X[h][o][p][t];
             // Now add the constraint
             model.add(expr1 >= expr2 + expr3);
             expr3.end();
             expr2.end();
             expr1.end();
          }
       }
    }
    

    #CPLEXOptimizers
    #DecisionOptimization