Decision Optimization

Decision Optimization

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


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

Problem with callback

  • 1.  Problem with callback

    Posted 03/13/10 12:56 PM

    Originally posted by: SystemAdmin


    Hi everybody,

    I use incumbent callback to play around my integer feasible solutions. I have another class wherein a model MM with a complete model is is introduced and initialized with data. There is a subset of constraints which should be modified based on the solutio to the incumbent. Such change is actually only updating the RHS of some constraints.
    Now the problem is that if I have a range array containing 1160 ranges and try to iterate over them using indexes then the code crashes right on index 80 and does not proceed. I can indeed print out the content of these constraints if only want to see the content but cannot further proceed by seting the upper bound.

    Am I doing some thing wrong?

    best regards,
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problem with callback

    Posted 03/13/10 04:53 PM

    Originally posted by: SystemAdmin


    Crashes how (what error message)? Is there any chance that the constraint at index 80 has been deleted (so that the value in the array is null)?

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Problem with callback

    Posted 03/13/10 07:50 PM

    Originally posted by: SystemAdmin


    Thanks for your attention.
    The range indeed contains all the 1160 elements. I can getExpr(), can getUB() but when I try to modify a bound for a range which is a member of a class that the class is sent (tried both) by values or by reference the error occures and contol goes to the an internal code of cplex , namely the following function and points toward 'notify':

    void IloRangeI::setUb(IloNum val) {
    if (_rhs != val) {
    _rhs = val;
    notify(IloSetRangeBounds(this, _lhs, val));
    }
    }

    I managed to overcome this error by following
    myrngArraycntr = IloRange(env, myrngArraycntr.getExpr(), newBound);

    But, now there is another problem
    If I have a class where my model with all the stuff (rng arrays, vars, cplex, model etc) in it is sent to the callback and solved inside the callback then the model is empty, no matter if you have extracted it before or inside the callback. that is what is really annoying!
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Problem with callback

    Posted 03/14/10 05:10 PM

    Originally posted by: SystemAdmin


    Range constraints and the C++ API is quite an issue. In Concert you can only operate on the original model, but range constraints are automatically transformed into an equation plus an auxiliary variable. I am not so sure whether the range constraint can be modified appropriately inside a Concert callback.

    I propose to model the range constraint directly as an equation and an additional variable, and then modify the bounds of the variable.

    If you have the range constraint

    l <= a*x <= r

    then instead add an equation

    a*x - y = 0

    and a variable

    l <= y <= r

    to your model. Then, changing l and r of your range constraint just means to change the bounds of y. This should work well.
    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Problem with callback

    Posted 03/14/10 06:11 PM

    Originally posted by: SystemAdmin


    Hi Tobias,

    Thank you for your comment.
    Your way of dealing with this issue seems to be promising. There is only one big concern for the case where we have an MIP O(n^5) constraints and O(n^4) are subjected to change in RHS your solution which suggest adding O(n^4) more variables may inject additional complexity to the problem.

    You mentioned this is an issue when C++ API is used--- which api is the less problematic one to work with (java, C#, VB? ??) where I can also benefit from Concert?

    best regards,
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Problem with callback

    Posted 03/14/10 06:21 PM

    Originally posted by: SystemAdmin


    On the engine level (CPLEX internal), using my approach is really no difference, because CPLEX would internally convert your range constraints into equations with additional variables anyway. So, if the additional variables do not kill your model building process inside Concert (which I doubt), your are fine.

    I am currently not sure whether there is a way in the C API (the most powerful, but of course low-level API) to locally change left and right hand sides of range constraints (i.e., to implicitly change the lower and upper bounds of the corresponding auxiliary variables).

    I really think that you should try my suggestion. If it does not work for some reason, then we can think about alternatives.
    Cheers,

    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Problem with callback

    Posted 03/15/10 11:19 AM

    Originally posted by: SystemAdmin


    I'm a bit confused here.

    Shahin, you said you're using an incumbent callback to grab an incumbent and modify some constraints (RHS). Are the constraints you are modifying part of the same model or a separate model?

    If you are modifying constraints from a separate model (one that is not currently in the process of being solved), there should be no problem directly accessing and changing the RHS.

    If you are modifying constraints from the model being solved, then the key is whether you are always tightening them, or whether you might be loosening them in some cases. If you are always tightening them, this can be done (safely) by adding the same constraint with the tighter bounds as a new cut using a LazyConstraintCallback. CPLEX is pretty smart about handling non-binding lazy constraints, so the increase in problem size should not cause the solver to bog down.

    If you are trying in some cases to loosen constraints on the fly, I'm not sure that's feasible. Among other concerns, it would imply that nodes that have already been pruned either as infeasible or suboptimal might need to be resurrected from the dead.

    /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


  • 8.  Re: Problem with callback

    Posted 03/15/10 11:48 AM

    Originally posted by: SystemAdmin


    Hi Paul,

    >>If you are modifying constraints from a separate model (one that is not currently in the process of being solved), there should be no problem directly accessing and changing the RHS.

    that is what supposed to be but that is not the actuall happening. Are you working with 12.1? with 12.1 the some of the things are a bit funny. for example try doing the following:
    in an incumbent callback try to create a model, inside the getEnv environment. introduce every thing needed just here. and the extract the model and solve it. try to write the lp file. you would most probably see that your objective function is not what you expect. run the same code on 11.2 the results are totally different.
    I have major problem with callbacks in 12.1.

    I am not that new to cplex or concert, I have done all these things before without any problem.

    There is also another problem that I suspect and cannot 100% confirm it now but sooner or later I will make a clear example. And that is in the cutcallback. there is a confusion between local and global cut there.
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Problem with callback

    Posted 03/16/10 12:05 PM

    Originally posted by: SystemAdmin


    Shahin,

    I have started to look into the problem you describe concerning callbacks.
    I am not sure if I understood correctly what you were doing. I understood
    that your callback looks something like this
    class IncumbentCallback : public IloCplex::IncumbentCallbackI {
    public:
       ...
       void main() {
          IloModel model(getEnv());
          // Populate the model
          ...
          // Solve and export
          IloCplex cplex(model);
          cplex.solve();
          cplex.exportModel("modelfile.lp");
       }
    };
    

    And modelfile.lp is not what you expect? Is that what you did? How many
    threads are you using? Could you provide more details or contact me at
    daniel(dot)junglas(at)de(dot)ibm(dot)com so that we can figure out what
    goes wrong in your case.
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Problem with callback

    Posted 03/16/10 12:47 PM

    Originally posted by: SystemAdmin


    Daniel,

    I have a class with all members being publicly declared. The environment is send to this class as argument to constructor.

    void main ()
    {
    IloEnv env;
    CP1 P1(env, nr1, nr2);
    }

    // class P1
    class CP1
    {
    // declare everything needed for both problem1 and problem2
    // declare different functions to construct parts of the model
    solveP1();

    }

    Now I have tried two approaches resulted unwantedly and unexpectedly:

    1)

    CP1 ::solveP1()
    {
    // do some crazy stuffs
    m_cplexP1.use(solveP2(env, this, ));
    m_cplexP1.solve();
    }
    now inside the callback
    ILOINCUMBENTCALLBACKn()
    {
    //try to build a local model and solve it make use of the elements of the class. Many difficulties raise here.
    }
    2.1) the second approach is like this:

    Let's separate the P2 elements in a different class CP2 and pass the environment to it:

    establish a complete class of data structures and functionalities.

    Now:
    CP1::solveP1()
    {
    // do some crazy stuffs
    CP2 P2(env, ...);
    m_cplexP1.use(Ben(env, P2, ... )) // sent by value
    }
    now inside the callback
    ILOINCUMBENTCALLBACKn()
    {
    //the constraints are already introduced in the SP
    // just insert them in a model and NOW MAKE YOUR OWN OBJECTIVE add it to the model and solve it.
    // export the model
    / sounds ...
    }

    2.2) the thirs one is that we do not pass it into the callback; rather create it inside the callback
    ILOINCUMBENTCALLBACKn()
    {

    CP2 p2;
    // do create the customized objectve here and add it to the model.
    // no matter if the model has been already extracted to cplex or you wanna do it here.
    }
    All these failed.
    I dont know if I could explain it well; I tried to explain it short and accurate!?

    Plase let me know if you need more details.
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Problem with callback

    Posted 03/16/10 12:57 PM

    Originally posted by: SystemAdmin


    Just to be sure: Do you create a new instance of IloCplex for each sub-problem to solve?
    You don't attempt to re-use an instance of IloCplex to solve multiple models at the same time, do you?
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Problem with callback

    Posted 03/16/10 01:50 PM

    Originally posted by: SystemAdmin


    it does not reach to that point. righ the first attemp is crashed.
    But I will use it if I can pas the first iteration. It does not make sense to each time extract the model into a new instance of solver.
    #CPLEXOptimizers
    #DecisionOptimization