Forum Discussion

FICO's avatar
FICO
Community Manager
4 years ago

Using callback to re-set (modify) control in middle on B&B search [Using Python]

Hello Xpress Experts,

I am wondering if any of you could help me with this callback in Python. I want to quickly find an integer solution during the BB, and then, switch to the default BB search settings of Xpress.

To do that, I am trying to set a callback such that after the first integer solution is found, the setControl for SBBEST and SBESTIMATE are re-set. Also, I do not want to keep using such callback function further in the BB, so I want to remove it.

Below you can see a piece of the code where I am trying to achieve what I mentioned before. Can anyone tell me why Xpress is stopping immediately after the first integer solution is found and says that stopped by user?

# Define callback to depth search first and then switch to Xpress default

def change_search_strategy(prob):

  prob.setControl({'sbbest':-1,'sbestimate':-1})

  print("CHANGED THE BRANCH STRATEGY")

  prob.removecbintsol()

# Add function to callback

p.addcbintsol(change_search_strategy, None,0)

2 Replies

  • FICO's avatar
    FICO
    Community Manager

    Not an answer to your question but would it not be much simpler to

    1. Set your special parameters
    2. Set the integer solution limit (MAXMIPSOL) to 1
    3. Call solve()
    4. Reset your special parameters and reset the integer solution limit to its default.
    5. Call solve()

    This should give you the same effect but without any callbacks.

  • FICO's avatar
    FICO
    Community Manager

    Hi Daniel,

    First of all, thanks a lot for your message. Actually, I ended up doing something like that, I interrupted the search and reset the parameters. But MaxMipsol seems to do exactly the same but effortless. I am just getting to know all the capabilities, so I missed that control parameter.

    Thanks a lot, it is really helpful.