Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Implementing a cut callback class (concert C++)

    Posted Sun March 17, 2013 10:35 AM

    Originally posted by: Trino


    Hi all, I'm trying to implement my own callback class in concert C++ instead of using the macros.

    I decided to do that because my callback will need to use a recursive function that needs the same data passed to the callback, so to avoid passing all the parameters to this function at every call I think it's better to implement it as a method of my callback class, since it would have direct access to the data it needs.

    I've implemented my cut callback class using the code presented in this thread https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14535268&#14535268

    So, for now my code is like below and it seems to be working. Is this the right way to implement a userCutCallBack and is there anything missing?

    
    
    
    class CutCallbackModel1 : 
    
    public IloCplex::UserCutCallbackI 
    { NumVarMatrix2d x;   
    
    public: CutCallbackModel1(IloEnv env, NumVarMatrix2d x) : IloCplex::UserCutCallbackI(env) 
    { this->x = x; 
    }   CutCallbackModel1(IloEnv env): IloCplex::UserCutCallbackI(env) 
    {
    }   IloCplex::CallbackI *duplicateCallback() 
    
    const 
    { 
    
    return 
    
    new (getEnv()) CutCallbackModel1(getEnv()); 
    }   
    
    void main(); bool recursiveFunction();   
    };
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Implementing a cut callback class (concert C++)

    Posted Mon March 18, 2013 03:28 AM

    Originally posted by: SystemAdmin


    The duplicateCallback function should return a clone of the callback. In your implementation this is not the case since the x field is not cloned (so the clone will have an empty x field). So IMO the duplicateCallback function should read
    IloCplex::CallbackI *duplicateCallback() const {
       return new (getEnv()) CutCallbackModel1(getEnv(), x);
    }
    

    Here is how the duplicateCallback function is used:
    When CPLEX runs a solve on multiple threads then it invokes duplicateCallback for each thread so that there is a different instance of the callback class for each thread. The different threads then invoke their thread-specific callback instance during the solve.
    So, if you use only one thread then duplicateCallback will never be invoked (and can be anything). If you use more than one thread then the function will be invoked and the value it returns should be a clone of the callback.
    Note that in parallel callbacks you may need to use locks (you can use class IloFastMutex) to avoid race conditions.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Implementing a cut callback class (concert C++)

    Posted Mon March 18, 2013 03:36 PM

    Originally posted by: Trino


    ok, thank you Daniel.
    #CPLEXOptimizers
    #DecisionOptimization