Given a pyscipopt.Model
and its Solution
, how to pass it to another model as a primal heuristic?
I'm currently writing the solution to a file via writeSol()
, and then calling readSolFile()
and addSol()
. There should probably be a cleaner way.
This depends a bit on the structure of your two models. If they have the same variables in the same order (which is likely from what you wrote), then you can simply create a new solution in your model and copy all the values, ie:
variables = othermodel.getVars()
newvariables = model.getVars()
nvars = othermodel.getNVars()
newsol = self.model.createSol(self)
for i in range(nvars):
newsol[newvariables[i]] = othermodel.getSolVal(oldsol, variables[i])
self.model.trySol(newsol)
Let me know if this work/ doens't work