<div dir="ltr">Hi<div><br></div><div>According to the documentation (<a href="https://scipopt.org/doc-7.0.0/html/REOPT.php">https://scipopt.org/doc-7.0.0/html/REOPT.php</a>) one needs to call model.freeReoptSolve() after the model is solved and before changing the objective.</div><div><br></div><div>Best,</div><div>Felipe</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 28, 2020 at 5:49 PM Victor Miller <<a href="mailto:victorsmiller@gmail.com">victorsmiller@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">At the request of Ambros I'm posting the python program below which<br>
forbids me from reoptimizing. I'm using the scip version 7.0.0 with<br>
the pyscipopt from the github.<br>
<br>
In python I do<br>
<br>
foo = list(bug(5,5, ntimes=2, vtype='B')<br>
<br>
which gives the run time error at the second iteration<br>
<br>
[scip_var.c:4546] ERROR: invalid SCIP stage <10><br>
[scip_prob.c:1150] ERROR: Error <-8> in function call<br>
Traceback (most recent call last):<br>
 File "<stdin>", line 1, in <module><br>
 File "/Users/victorsmiller/Programming/Optimization/Reopt/scip_bug.py",<br>
line 20, in bug<br>
  model.chgReoptObjective(quicksum(obj_vec[_] * vars[_] for _ in<br>
range(ndim)), "minimize")<br>
 File "src/pyscipopt/scip.pyx", line 4536, in<br>
pyscipopt.scip.Model.chgReoptObjective<br>
 File "src/pyscipopt/scip.pyx", line 245, in pyscipopt.scip.PY_SCIP_CALL<br>
Exception: SCIP: method cannot be called at this time in solution process!<br>
<br>
----------<br>
import numpy as np<br>
from pyscipopt import Model, quicksum<br>
<br>
def bug(mdim, ndim, ntimes=1, vtype='B'):<br>
<br>
  model = Model()<br>
  amat = np.random.randn(mdim, ndim)<br>
  xvec = np.random.randint(0, 2, ndim) if vtype == 'B' else<br>
np.random.randn(ndim)<br>
  bvec = amat @ xvec<br>
  vars = [model.addVar(vtype=vtype, name="x_%d" % _) for _ in range(ndim)]<br>
<br>
  for ind in range(mdim):<br>
    model.addCons(quicksum(amat[ind, _] * vars[_] for _ in<br>
range(ndim)) == bvec[ind])<br>
<br>
  model.enableReoptimization()<br>
<br>
  for ind in range(ntimes):<br>
<br>
    obj_vec = np.random.randn(ndim)<br>
    model.chgReoptObjective(quicksum(obj_vec[_] * vars[_] for _ in<br>
range(ndim)), "minimize")<br>
    model.optimize()<br>
<br>
    status = model.getStatus()<br>
<br>
    if status == "infeasible":<br>
      raise ValueError("The problem is infeasible")<br>
<br>
    soln = np.array([model.getVal(vars[_]) for _ in range(ndim)])<br>
    if vtype == 'B':<br>
      yield soln.round().astype(np.int8)<br>
    else:<br>
      yield soln<br>
<br>
On Thu, May 28, 2020 at 2:09 AM Ambros Gleixner <<a href="mailto:gleixner@zib.de" target="_blank">gleixner@zib.de</a>> wrote:<br>
><br>
> Hi Victor,<br>
><br>
> Please have a look at<br>
><br>
>Â Â Â <a href="https://www.scipopt.org/doc/html/REOPT.php" rel="noreferrer" target="_blank">https://www.scipopt.org/doc/html/REOPT.php</a><br>
><br>
> SCIP actually provides an intricate mechanism to do what exactly you<br>
> want and reuse information from the previous solving process. Whether<br>
> this performs better than solving from scratch depends on how large the<br>
> changes between different objective functions are. Here is a scientific<br>
> publication that gives more details:<br>
><br>
>Â Â Â <a href="http://dx.doi.org/10.1007/978-3-319-20086-6_14" rel="noreferrer" target="_blank">http://dx.doi.org/10.1007/978-3-319-20086-6_14</a><br>
><br>
> To achieve the more plain version of simply solving again from scratch,<br>
> you have to call SCIPfreeTransform(); then you are allowed to modified<br>
> the problem.<br>
><br>
> Best,<br>
> Ambros<br>
><br>
><br>
><br>
><br>
> Am 27.05.20 um 23:07 schrieb Victor Miller:<br>
> > I have a MIP which I want to solve a number of times with different<br>
> > objective functions. Just trying to change the objective after a<br>
> > previous solution doesn't work, so how do I do this? Do I copy the<br>
> > model, and solve the copy? If so, is there a standard way of finding<br>
> > out which variables in the copy correspond to the variable in the<br>
> > original?<br>
> ><br>
> > Victor Miller<br>
> > _______________________________________________<br>
> > Scip mailing list<br>
> > <a href="mailto:Scip@zib.de" target="_blank">Scip@zib.de</a><br>
> > <a href="https://listserv.zib.de/mailman/listinfo/scip" rel="noreferrer" target="_blank">https://listserv.zib.de/mailman/listinfo/scip</a><br>
> ><br>
><br>
> --<br>
> Ambros Gleixner, Research Group Mathematical Optimization Methods at<br>
> Zuse Institute Berlin, <a href="http://www.zib.de/gleixner" rel="noreferrer" target="_blank">http://www.zib.de/gleixner</a><br>
> _______________________________________________<br>
> Scip mailing list<br>
> <a href="mailto:Scip@zib.de" target="_blank">Scip@zib.de</a><br>
> <a href="https://listserv.zib.de/mailman/listinfo/scip" rel="noreferrer" target="_blank">https://listserv.zib.de/mailman/listinfo/scip</a><br>
_______________________________________________<br>
Scip mailing list<br>
<a href="mailto:Scip@zib.de" target="_blank">Scip@zib.de</a><br>
<a href="https://listserv.zib.de/mailman/listinfo/scip" rel="noreferrer" target="_blank">https://listserv.zib.de/mailman/listinfo/scip</a><br>
</blockquote></div>