Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Extracting all solutions from populate raising IloExtractable exception

  • 1.  Extracting all solutions from populate raising IloExtractable exception

    Posted 07/17/18 04:04 AM

    Originally posted by: Jernej1


    Hello,

     

    I am building a ILP model that I am interested in solving and examining all its solutions. The underlying problem is pretty much a (integer) partition problem with some constraints on partition sizes. By following the ilopopulate.cpp example, I have come up with the following code

    static void refine(const unsigned d[CONF_SIZE]) {
    
        unsigned i,j;
        int status;
    
        try {
    
            IloModel model(env);
            IloNumVarArray var(env);
            IloRangeArray con(env);
            IloCplex cplex(model);
       
            cplex.setParam(IloCplex::Param::MIP::Pool::Intensity, 4); 
            cplex.setParam(IloCplex::Param::MIP::Limits::Solutions, SOLSBOUND);
            cplex.setParam(IloCplex::Param::MIP::Limits::Populate, SOLSBOUND);
    
            for (i = 0; i < 2*CONF_SIZE; i++) {
                var.add( IloNumVar(env, 0, d[i], IloNumVar::Int));
                var.add( IloNumVar(env, 0, d[i], IloNumVar::Int));
            }   
        
            for (i = 0; i < CONF_SIZE; i++) {
                con.add(var[2*i] + var[2*i+1] == d[i]);
            }   
    
            for (i = 0; i < 2*CONF_SIZE; i++) {
                IloExpr expr = (N-K+1)*var[i];
                for (j = 0; j < K; j++) {
                    expr += var[i ^ (1<<j)];
                }   
                con.add( expr >= 1<<(N-K) );
            }   
            model.add(con);
            cplex.populate();
    
            int numsol = cplex.getSolnPoolNsolns();
    
            for (i = 0; i < numsol; i++) {
                IloNumArray vals(env);
                cplex.getValues(vals, var, i);
            }
        } catch(IloException& e) {
            std::cerr << "Concert exception caught: " << e << std::endl;
        }
        catch(...) {
            std::cerr << "Unknown exception caught" << std::endl;
        }
    }
    

     

    Unfortunately this example raises an exception due to the call to getValues, namely 

     

    Concert exception caught: IloExtractable 9 IloNumVarI has not been extracted by IloAlgorithm 0x3f0bf10

    I have no idea why this error is being caused. Can someone help me understand how to use populate properly so that I can access all the feasible solutions of the modeled problem?


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Extracting all solutions from populate raising IloExtractable exception

    Posted 07/17/18 04:12 AM

    This exception is thrown if you attempt to query the value of a variable that does not appear in any constraint or the objective function.

    As a workaround, you can just call model.add(var) to explicitly add all variables. However, I think in your case it is unexpected that variables do not appear in the model. To figure out what is the offending variable just use IloNumVar::setName() to assign a name to each variable, then the name of that variable will appear in the exception message.

    Is it intended that your array 'var' contains 4*CONF_SIZE variables? From the rest of the code it seems only 2*CONF_SIZE variables are intended (I might be misreading)?


    #CPLEXOptimizers
    #DecisionOptimization