How can I implement a callback-function to be executed at specific occurrences after having started to optimize? Specifically, I simply want the primal solution to be printed to the console every time an improved primal solution has been found. I have tried to look at the documentation I could find, but have not found anything helpful.


1 Answer 1


You want a custom separator that doesn't actually do anything. Here's an example:

class Cutter(scip.Sepa):
    def __init__(self):

    def sepaexeclp(self):
        m: scip.Model = self.model
        if not m.getLPSolstat() or not m.isLPSolBasic():
            return {"result": scip.PY_SCIP_RESULT.DIDNOTRUN}

        cols = m.getLPColsData()
        rows = m.getLPRowsData()
        bases = m.getLPBasisInd()

        table = [[col.getPrimsol() for col in cols]]

        for row in rows:
            coefs = row.getVals()
            cols = row.getCols()
            data = []
            for col, coef in zip(cols, coefs):
                data.append(col.getPrimsol() * coef)

        return {"result": scip.PY_SCIP_RESULT.DIDNOTRUN}

And somewhere after you make your model, you need something like this:

model.includeSepa(Cutter(), "my_cutter", "a good one", 10000000, 1, 0.0)
  • $\begingroup$ I am trying to get the simplex tableau information by SCIP. I somewhat know it is possible by sepe callback as mentioned in the GMI example. Would you say please, is it possible to get this information by other callbacks such as event callback? If so, do you know/have any examples to see and benchmark this? (Thanks) $\endgroup$
    – A.Omidi
    Commented Jul 22, 2023 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.