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
You want a custom separator that doesn't actually do anything. Here's an example:
class Cutter(scip.Sepa):
def __init__(self):
pass
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)
table.append(data)
print(table)
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 asevent
callback? If so, do you know/have any examples to see and benchmark this? (Thanks) $\endgroup$– A.OmidiJul 22 at 7:35