Forum Discussion

FICO's avatar
FICO
Community Manager
9 years ago

Implementing Lazy Constraints (C++)

I'm implementing a B&Cut algorithm with BCL - C++ using the cut manager callback.

Also I have to implement Lazy Constraints, that is, after each integer solution, search the violated constraints and add it.

Now, I'm using XPRSsetcbintsol callback to detect all the integer solutions during the B&B. In my actual code, after some interations yes... the callback detect an integer solution, for that, there are a violated constraint, I  indicate that this constraint is a lazy constraint with "setDelayed(true)" but, in the next iteration the MIP optimizer said "optimal solution"... that is, finish the search through the tree and the last solution is the same that if i don't add the lazy constrait... some help? I'm not sure if i'm using the correct callback (setcbintsol), or if I need to disable (or able) come option for this function.

5 Replies

  • FICO's avatar
    FICO
    Community Manager

    The delayed constraint property can only be set before you load the problem into the solver, not during the MIP search.

    If you wish to add cuts, you need to do so via the 'addCuts' routine in the cutmanager callback.

    Furthermore, if you wish to be able to reject an integer solution, this can be done in the 'preintsol' callback.

  • FICO's avatar
    FICO
    Community Manager

    Thanks,

    And... inside the preintsol callback...what is the funtion to reject the integer solution? there are some example code?

  • FICO's avatar
    FICO
    Community Manager

    From within the preintsol callback in a Mosel model you can call the subroutines 'rejectintsol' and 'setcbcutoff' to pass information back to Xpress-Optimizer (see documentation of 'setcallback' in the Mosel Language Reference Manual).

    For instance, using some code like the following where the test 'check_some_condition' is assumed to be implemented by your model:

    public procedure mypreintsol(isheur:boolean,cutoff:real)

      if check_some_condition then

         rejectintsol

      end-if

    end-function

    ! ... problem definition ...

    setcallback(XPRS_CB_PREINTSOL, "mypreintsol")

    ! ... start optimization ...

  • FICO's avatar
    FICO
    Community Manager

    I'm working with BCL C++, which is the way to used 'rejectintsol' and 'setcbcutoff' callbacks... (I've searched in the Mosel Language Reference Manual as you suggested, but is not available to C++).

  • FICO's avatar
    FICO
    Community Manager

    With BCL you can directly use the callback functions of the Xpress Optimizer library; for BCL C++ these would be the C library functions of the solver as shown, for example, in https://examples.xpress.fico.com/example.pl?id=bcl_cpp_18_6

    The subroutines 'rejectintsol' and 'setcbcutoff' that I have mentioned earlier are auxiliary routines for working with Optimizer callbacks in Mosel; if you are directly using the C functions, all information is passed back via arguments of the corresponding callback function. Please take a look at the documentation of 'XPRSsetcbpreintsol' in the Xpress-Optimizer Manual for a description of its arguments. Its use is similar to some of the other node callback functions shown in https://examples.xpress.fico.com/example.pl?id=optimizer_c_1