Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Solve ILP in UserCutCallback

    Posted 01/13/12 10:42 AM

    Originally posted by: MarkusS.


    Hello,

    I am working with Concert and CPLEX 12.3 and have a model, where I want to solve an ILP in a subproblem to generate cuts, which strengthen the formulation.

    However, I get an "accessing IloAlgorithm through 0 handle" error in the Callback (I want to add the myCover Expression to the original model)

    Here is my code-snippet of the callback:
    
    ILOUSERCUTCALLBACK3(CoverCallback, Graph*, G, 
    
    const IloBoolVarArray&, y, int, U_) 
    { 
    
    int n_nodes=G->get_number_of_nodes(); 
    
    int U=U_;   IloCplex subCplex; IloEnv subEnv; IloModel subModel;     IloNumArray y_lp(getEnv(),n_nodes); getValues(y_lp,y);   
    
    try
    { subEnv=IloEnv(); subModel=IloModel(subEnv); IloBoolVarArray z(subEnv, n_nodes);   
    
    for (
    
    int i=0;i<n_nodes;i++) 
    { stringstream myname; myname << 
    "z_" << i; z[i]=IloBoolVar(subEnv, myname.str().c_str()); 
    }   IloExpr myKP(subEnv); 
    
    for (
    
    int i=0;i<n_nodes;i++) 
    { 
    
    int r=G->get_revenue(i); myKP+=r*z[i]; 
    } subModel.add(myKP<=U); myKP.end();   IloExpr myObjective(subEnv); 
    
    for (
    
    int i=0;i<n_nodes;i++) 
    { myObjective+=y_lp[i]*z[i]; 
    } subModel.add(IloMinimize(subEnv,myObjective)); myObjective.end();   subCplex.solve();   
    
    double result=subCplex.getObjValue();   
    
    if(result<1) 
    { 
    
    int size=0; IloNumArray z_lp(subEnv); subCplex.getValues(z_lp,z); IloExpr myCover(getEnv()); 
    
    for (
    
    int i=0;i<n_nodes;i++) 
    { 
    
    if(z_lp[i]>0.9) 
    { size++; myCover+=y[i]; 
    } 
    } add(myCover<=size-1); myCover.end(); 
    }   subEnv.end(); 
    } 
    
    catch(IloException& e) 
    { cerr<< 
    "Concert exception2!"<<endl; cerr<<e<<endl; 
    } 
    
    catch(...) 
    { cerr<< 
    "Unknown exception2!"<<endl; 
    } 
    }
    


    Moreover, I have another small question in this direction: I want to repeatedly resolve my original problem with different objective functions and each time, I want to have another value for parameter U of my callback. So after solving the model, I need to remove the current callback, and add it again with different value for U, how can I do this? Also, does CPLEX keep the cuts generated with my callback for resolving with a different objective? (actually I do not want this do happen, so if yes, is there a way to remove these cuts before resolving?)
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Solve ILP in UserCutCallback

    Posted 01/13/12 01:09 PM

    Originally posted by: MarkusS.


    Ok, I have spotted my error in the code, I have forgotten IloCplex subCplex(subModel)...

    But now I've got another problem resulting in the error-message "IloExtractable 501 IloNumVarI has not been extracted by IloAlgorithm". This is due to the line subCplex.getValues(z_lp,z); and I think it happens, because some coefficients of z-Variables are 0? Is there any elegant way to fix this problem without changing the code much?
    #CPLEXOptimizers
    #DecisionOptimization