Best way to implement a primal heuristic that fixes certain Variables

124 views Asked by At

I am using PySCIPOpt and have a MIP with some quadratic constraints (works). Now, I want to implement a Primal Heuristic (should run once before presolving), that fixes certain Variables and optimizes afterwards.

Ìn pseudo-code something like:

For x in ToFIX:
    model.fixVar(x, my_guess(x))
model.optimize()
*Any found solution is used as solution of the original problem*
For x in ToFIX:
    model.unFixVar(x)

I worked around that problem by creating a second model, solving that, identifying the variables by their name and using model.trySol(). This mostly works but is slow and certainly not the way it is meant to be implemented.

Any hint, which functionalities to use is appreciated.

1

There are 1 answers

1
Leon On BEST ANSWER

sorry this took a while to answer.

What you want to implement is a sub-scip heuristic. This is certainly possible, but if you want to do it in PySCIPOpt you might have to wrap some missing methods from the C-API.

I suggest you take a look at heur_rens.c in the SCIP code. The methods you would need to wrap are probably SCIPcopyLargeNeighborhoodSearch and SCIPtranslateSubSol which should save you a lot of trouble. Please refer to the section extending the interface in the PySCIPopt Readme.