Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only

Creating two expression objects in one single loop would cause problem?

  • 1.  Creating two expression objects in one single loop would cause problem?

    Posted 04/21/12 11:54 PM

    Originally posted by: SystemAdmin


    Dear all,
    I am using CPLEX 12.0 Concert/C++ on Win 7 to solve Qudratic Assignment Problem, which has been transformed into a pure IP model in my case.

    Since I want to reduce the running time so I want to put two expression objects inside one block of 4-nested-for-loop structure. But I kept get infeasible msg after I ran .exe file at the end. Here are the codes:

    int transIndx = 0;
    int countT = 0;
    // add modified Transformed constrains after getting first feasible solution
    for (int i = 0; i < h; i++) {
    for (int j = i+1; j < h; j++) {
    for (int s = 0; s < l; s++) {
    for (int t = s + 1; t < l; t++) {
    if ( s >= m[i] - x_DQ*l/h && s <= m[i] + x_DQ*l/h && t >= m[j] - x_DQ*l/h && t <= m[j] + x_DQ*l/h) {
    //first expression
    IloExpr exprT(env);
    exprT = ZtransIndx - X[i][s] - X[j][t]; // Z and X are both IloBoolVar
    mod.add( exprT >= -1);
    exprT.end();
    //another expression
    IloExpr exprImP(env);
    exprImP = X[i][s] + X[j][t];
    mod.add( exprImP <= 1);
    exprImP.end();
    transIndx++;
    }
    }
    }
    }
    }

    Actually, I can split the above code into two similar 4-nested-for-loop piece of code, which worked as expected, but as I said,I wanted to do the above way because I can save half running time for 4-nested-for-loop
    Note that I defined a 1-d IloBoolArray for Z variable with a fixed size("numValid_Z") determined in in the following code already.

    IloInt numValid_Z=0;
    // count how many valid Z's we would define, so that we can define a 1-dim array for
    //IloBoolArray Z(env);
    for(int i=0; i<h; i++) {
    for(int j=i+1; j<h; j++) {
    for(int s=0; s<l; s++) {
    for(int t=s+1; t<l; t++) {
    if (s >= m[i] - x_DQ*l/h && s <= m[i] + x_DQ*l/h && t>= m[j] - x_DQ*l/h && t <= m[j] + x_DQ*l/h){
    //ZnumValid_Z = IloBoolVar(env);
    numValid_Z++;
    }
    }
    }
    }
    }

    // instead of defining a 4-dim array for Z's, we define only a 1-dim array for Z with size of total # possible Z's

    IloArray<IloBoolVar> Z(env, numValid_Z);
    for (int i = 0; i < numValid_Z; i++)
    { Z[i] = IloBoolVar(env);
    }
    #CPLEXOptimizers
    #DecisionOptimization