Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Problem with callback

    Posted 04/11/10 03:37 AM

    Originally posted by: SystemAdmin


    Hi Everybody,

    inside an incumbent callback I need to solve an LP. I have made a complete implementation of a class duplicating the incumbentcallback in c++. The first time when I declare an object from this type of callback it internalizes every thing builds the model etc. Then when a feasible solution found I come back to this callback try to setExpression for objective function and it report an UGLY error message which is not clear what it is.
    I dont do any further changes to the model or any thing else.
    I even export the model as an lp and it seems quite ok except it has zero values for all coefficients in the objective function.

    I am attaching the error message in the case is needed.

    any comment is appreciated.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problem with callback

    Posted 04/11/10 11:09 AM

    Originally posted by: SystemAdmin


    I don't know about "ugly", but that error message is a tad uninformative.

    I take it you're using C++? It's been a while since I've done any C++ programming (but not long enough). Without seeing the code it's hard to tell what's going on, but the first thing that occurs to me is to ask whether there is any possibility that the LP model is still there, intact, when the cut callback is invoked. You said you exported the LP model -- was that immediately after initializing the callback, or was it immediately before invoking setExpression? Have you tried trapping any possible null pointers? (Null pointers were one reason among many that I switched to Java.)

    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Problem with callback

    Posted 04/11/10 11:40 AM

    Originally posted by: SystemAdmin


    I declare an instance of the incumbent class I have written.
    every thing is initialized. during initialization I even set the objective expression to some thing.
    No error every thing is fine.
    Then when the first incumbent is found I come again here in the implementation part inside the class and create an expression. I print the expression it is correct (contains something and is not NULL) and its related environment must be the same as the model.
    now when I try to set the objective expression to this then I get error message. I cannot export the lp file afterwards. I attach a new picture which shows the error message resulted from running without debug.
    I can guess it has something to do with null pointer or perhaps the two environment are not the same due to an unknown logic but I have no idea why should be the case.
    When the expression has an entry then why should it be a NULL pointer or when the models and Objective exist why should they be NULL?
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Problem with callback

    Posted 04/11/10 02:30 PM

    Originally posted by: SystemAdmin


    > Shahin G wrote:
    Then when the first incumbent is found I come again here in the implementation part inside the class and create an expression. I print the expression it is correct (contains something and is not NULL) and its related environment must be the same as the model.
    > now when I try to set the objective expression to this then I get error message.

    Before your try to set the objective function to that expression, check that the pointer to the objective function is not null (and actually points to the correct thing). Assuming it is non-null, I think you should be able to invoke the isObjective method on it to confirm it is an objective. Is the pointer to the objective a member field in the callback class, or are you IloCplex::getObjective to access it each time?

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Problem with callback

    Posted 04/11/10 03:10 PM

    Originally posted by: SystemAdmin


    Thanks for comment.
    The objective is a member of the implemented class which is attached to the same environment as the rest.
    I have already checked the object it it not NULL I paste the output here:
    Warning:  Output names have been modified to conform to LP format.
    Tried aggregator 3 times.
    MIP Presolve eliminated 2123 rows and 986 columns.
    MIP Presolve modified 2305 coefficients.
    Aggregator did 328 substitutions.
    Reduced MIP has 2317 rows, 1548 columns, and 27337 nonzeros.
    Reduced MIP has 1311 binaries, 237 generals, 0 SOSs, and 0 indicators.
    Presolve time =    0.61 sec.
    Warning: Control callbacks may disable some MIP features.
    Clique table members: 1486.
    MIP emphasis: balance optimality and feasibility.
    MIP search method: traditional branch-and-cut.
    Parallel mode: none, using 1 thread.
    Root relaxation solution time =    0.45 sec.
     
            Nodes                                         Cuts/ 
       Node  Left     Objective  IInf  Best Integer     Best Node    ItCnt     Gap
           Variable B NodeID Parent  Depth
     
          0     0    -1100.1429   337                  -1100.1429      940
    1Warning:  Output names have been modified to conform to LP format.
    2 * u1[0][1]
    obj597021 = (2 * u1[0][1] , IloObjective, Minimize);
     
    Warning:  Output names have been modified to conform to LP format.
    

    Upon detecting the fist incumbent I check the lp objective expression; it is 2*u1[0][1]. Then I export the lp file and try to change the objective. Then I get that warning.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Problem with callback

    Posted 04/11/10 04:09 PM

    Originally posted by: SystemAdmin


    Okay, any chance that the new objective expression contains a variable that the LP does not already contain?

    Also, what happens if you invoke getExpr on the objective and then invoke setExpr with that expression, something like

    IloCplex cplex;
    //...
    IloObjective obj = cplex.getObjective();
    IloNumExprArg e = obj.getExpr();
    obj.setExpr(e);

    Does that blow up as well?

    I'm assuming here that within the callback you are modifying a second problem (LP) that is distinct from the problem to which the callback is attached. I don't think CPLEX will let you modify a model while it's being solved, but I'm pretty sure you already know that and are not doing it (just checking).

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Problem with callback

    Posted 04/11/10 04:30 PM

    Originally posted by: SystemAdmin


    //Okay, any chance that the new objective expression contains a variable that the LP does not already contain?
    No. Absolutely not.

    //Also, what happens if you invoke getExpr on the objective and then invoke setExpr with that expression, something like
    Does that blow up as well?
    Yes -- I can get the objective expression but can not set the same expression again one line after that.
    //I'm assuming here that within the callback you are modifying a second problem (LP) that is distinct from the problem to which the callback is attached.

    It might be, I also suspect this. But I am pretty much sure that there is only one model which is initialized in the constructor of class and can be exported to be checked.

    //I don't think CPLEX will let you modify a model while it's being solved, but I'm pretty sure you already know that and are not doing it (just checking).

    Callback is attached to an MIP while the problem to be solved is an lp and they are totally different. I am not changing any element of the MIP that I am in its callback.

    I faced with such problem with callbacks before. This time I said ok I will write a class instead of simple Macro based callbacks.

    thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Problem with callback

    Posted 04/11/10 07:30 PM

    Originally posted by: SystemAdmin


    > Shahin G wrote:
    >
    > //Also, what happens if you invoke getExpr on the objective and then invoke setExpr with that expression, something like
    > Does that blow up as well?
    > Yes -- I can get the objective expression but can not set the same expression again one line after that.
    >

    Now that is truly weird. I think you said earlier that the LP lives in the same environment as the MIP. Can you switch it to a different environment as a test? I've done callback classes, but only in Java (or at least I only remember the ones I did in Java), where the mechanics are slightly different. In particular, the Java API doesn't have explicit environments.

    Also, I think when I did callback classes for Benders decomposition I made the subproblem(s) global. Does declaring the LP in global scope rather than within the callback class help? I don't know why it would make a difference, but then none of this makes sense.

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Problem with callback

    Posted 04/12/10 12:54 AM

    Originally posted by: SystemAdmin


    How many threads do you use? Does the problem also happen if you use only 1 thread?
    When using callbacks and multiple threads there are several things that must be observed carefully (these are explained in the user manual). Two of them are:
    • Each thread will have its own instance of the callback, so the duplicateCallback() function must be implemented in a meaningful way.
    • Each thread has its own environment and the callback will be invoked with this thread-local environment.
    • You should not use the global model's environment in the callback.
    If you are using more than 1 thread I suggest you do the following:
    • Create one extra instance incEnv of IloEnv to setup the incumbent callback.
    • When the incumbent callback is invoked use incEnv to manipulate the previously setup stuff and solve the LP.
    • Use IloMutex or whatever to synchronize the callback, i.e. to make sure that you don't access incEnv from multiple threads simultaneously in case two threads find a new incumbent at the same time.

    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Problem with callback

    Posted 04/12/10 06:51 AM

    Originally posted by: SystemAdmin


    Thanks Paul for your comments.
    Daniel, I switch for the moment to single thread and seems ok. Thanks for helpful comment.
    #CPLEXOptimizers
    #DecisionOptimization