Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  CPLEX 12.6.0, possible bug in cplex.getValue() ?

    Posted 08/01/14 02:39 PM

    Originally posted by: UserCplex


    Greetings,

    I have defined the following.

    IloEnv env;
    
    IloCplex cplex(env);
    
    IloNumVarArray y(env, MAX_SIZE, 0, IloInfinity, ILOINT);
    
    IloNumArray yvalues(env, MAX_SIZE);
    

    Somewhere later in the code, I solve the cplex instance using

    cplex.solve();
    

    After this, when I try 

    cplex.getValues(y, yvalues);
    

    CPLEX throws an exception.

    To drill down further, I changed yvalues as follows:

    double yvalues[MAX_SIZE];
    

    and tried to access solution values using individual cplex.getValue() function calls as follows:

    for(int i = 0; i < MAX_SIZE; i++){
    
        cout<<i<<endl;
    
        yvalues[i] = cplex.getValue(y[i]);
    
    }
    
    

    The trouble is that i never reaches MAX_SIZE - 1. It stops somewhere halfway with the exception:

    IloAlgorithm::NotExtractedException at memory location 0x0018f640..
    

    That is, some of the .getValue() functions work, while the others do not.

    Am I doing something wrong here? Or is this a bug in CPLEX 12.6.0?

    Thanks in advance.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: CPLEX 12.6.0, possible bug in cplex.getValue() ?

    Posted 08/02/14 05:12 AM

    You are doing something wrong. You can only call getValue() for variables that appear somewhere in your model (in constraints or in the objective function). It looks like some of your variables in the y array do not appear anywhere in your model. You can do model.add(y) to force all variables into the model but it would be better to figure out why some of the variables unexpectedly do not appear in the model.

    BTW, did you try to search this Forum for that exception before posting? This question has been asked and answered many times here.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: CPLEX 12.6.0, possible bug in cplex.getValue() ?

    Posted 08/02/14 06:56 AM

    Originally posted by: UserCplex


    I do apologize for not doing a complete search. I searched for .getValue() bug and did not find anything useful. I should have searched for the exact exception.

    I will try looking through my code again and if it is a problem at my end based on the suggestion provided, will delete the thread so as not to clutter this forum.

    Thanks.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: CPLEX 12.6.0, possible bug in cplex.getValue() ?

    Posted 08/02/14 09:36 AM

    Originally posted by: UserCplex


    I figured out what is happening. 

    The y variables feature only in the constraints. I define these constraints as 

    IloRangeArray con(env);

    I populate elements of this constraint array thus:

    con.add(lhs - rhs >= 0)

    where lhs and rhs are instances of IloExpr

    Coefficients of y variables are populated in different areas of the code.

    lhs has a coefficient for y[5] (say) of +70.

    In a different place where rhs gets populated, coefficient for y[5] turns out to be 70 as well (via a different calculation).

    So, when lhs - rhs is being computed, y[5] gets dropped since its coefficient is 0.

    I know that this variable is being dropped because I export the model just before cplex.solve via cplex.exportModel("test.lp");

    In test.lp, there is no mention of variable y[5].

    Hmm...is there no way of "forcing" a particular variable into a model if it has a 0 coefficient?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: CPLEX 12.6.0, possible bug in cplex.getValue() ?

    Posted 08/02/14 10:00 AM

    Originally posted by: UserCplex


    An update.

    I "forced" the variables in via model.add(y) and the problem goes away.

    The only question remaining is whether this explicit model.add(y) "adds" some additional overhead into the memory/model.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: CPLEX 12.6.0, possible bug in cplex.getValue() ?

    Posted 08/02/14 04:43 PM

     

    I'm fairly certain the impact on both memory and execution time, while not zero, is too small to notice. If you are worried about it, rather than using add() you can access the variable values in a try-catch block, catch the not-extracted exception and just assign the variable a value of zero.

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization