Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

hasIncumbent() returns false when the log shows that it found the 1st feasible solution

  • 1.  hasIncumbent() returns false when the log shows that it found the 1st feasible solution

    Posted Thu December 20, 2018 05:09 AM

    Originally posted by: Lessi


     

    I have write some lines of code to test if I understand the callback:

    ILOINCUMBENTCALLBACK0(feasibilityCheck)
    
    {
    
    cout << "we are in an incumbent callback!!!" << endl;
    
    
    int newIncumbent = this->hasIncumbent();
    
    
    if (newIncumbent)
    
    {
    
    cout << "we have an incumbent solution" << endl;
    
    }
    
    
    }
    

    ------------------------------------------------------------------------------

    This is the output, there are 2 solutions, so I think the following sentence should appear two times. Am I correct? Thank.
    we have an incumbent solution
    

    -----------------------------------------------------------------

    This is the log.

          Nodes                                         Cuts/
       Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap         Variable B NodeID Parent  Depth

          0     0      127.8125     5                    127.8125       20         
    we are in an incumbent callback!!!
    *     0+    0                          119.0000      127.8125             7.41%   => I think this is a solution (an incumbent)
          0     0      126.0199    15      119.0000       Cuts: 3       28    5.90%
          0     0      124.9401    18      119.0000      Cuts: 19       39    4.99%
          0     0      123.9318    17      119.0000      Cuts: 27       49    4.14%
          0     0      123.7923    15      119.0000   ZeroHalf: 1       52    4.03%
          0     0      123.6677    18      119.0000   ZeroHalf: 2       54    3.92%
    we are in an incumbent callback!!!
    we have an incumbent solution
    *     0+    0                          120.0000      123.6677             3.06%
          0     0      123.6397    21      120.0000       Cuts: 6       56    3.03%
          0     0      123.5945    18      120.0000   ZeroHalf: 1       58    3.00%
          0     0      123.5779    22      120.0000       Cuts: 9       61    2.98%
          0     0      123.4845    22      120.0000   ZeroHalf: 3       65    2.90%
          0     0      123.4705    21      120.0000      Cuts: 11       69    2.89%
          0     2      123.4705    21      120.0000      123.4704       69    2.89%                        0             0
    Elapsed time = 0.07 sec. (33.42 ticks, tree = 0.00 MB, solutions = 2)


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: hasIncumbent() returns false when the log shows that it found the 1st feasible solution

    Posted Thu December 20, 2018 05:26 AM

    Originally posted by: Lessi


    Another question: when I add codes to extract the value of the incumbent solution, it throws an exception. Your suggestion is valueable!

     

    IloBoolVarArray y(env, 0); //this is the declaration of the y variables

    ...

    ILOINCUMBENTCALLBACK0(feasibilityCheck)
    {
    cout << "we are in an incumbent callback!!!" << endl;
     
    int newIncumbent = this->hasIncumbent();
     
    if (newIncumbent)
    {
    cout << "we have an incumbent solution" << endl;

    //those two lines of code throw an exception - I also try with IloNumArray y_val(env,"Number of variables to extract"); but it does not solve the issue

    IloNumArray y_val(env); 
    this->getValues(y_val, y);
                //I also try again with getValue(y[0]); it throws the same exception. 
    }
     
    }

     I put the code in a try/catch, and it shows: Error: IloExtractable 2 IloNumVarI has not been extracted by IloAlgorithm 

     

    Thanks,

    -----------------------

    Solved: I use model.add method to explicitly add the variables to the model.  


    #CPLEXOptimizers
    #DecisionOptimization