[SCIP] Resolving with a different objective function

Victor Miller victorsmiller at gmail.com
Thu May 28 17:45:54 CEST 2020


At the request of Ambros I'm posting the python program below which
forbids me from reoptimizing.  I'm using the scip version 7.0.0 with
the pyscipopt from the github.

In python I do

foo = list(bug(5,5, ntimes=2, vtype='B')

which gives the run time error at the second iteration

[scip_var.c:4546] ERROR: invalid SCIP stage <10>
[scip_prob.c:1150] ERROR: Error <-8> in function call
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/victorsmiller/Programming/Optimization/Reopt/scip_bug.py",
line 20, in bug
    model.chgReoptObjective(quicksum(obj_vec[_] * vars[_] for _ in
range(ndim)), "minimize")
  File "src/pyscipopt/scip.pyx", line 4536, in
pyscipopt.scip.Model.chgReoptObjective
  File "src/pyscipopt/scip.pyx", line 245, in pyscipopt.scip.PY_SCIP_CALL
Exception: SCIP: method cannot be called at this time in solution process!

----------
import numpy as np
from pyscipopt import Model, quicksum

def bug(mdim, ndim, ntimes=1, vtype='B'):

    model = Model()
    amat = np.random.randn(mdim, ndim)
    xvec = np.random.randint(0, 2, ndim) if vtype == 'B' else
np.random.randn(ndim)
    bvec = amat @ xvec
    vars = [model.addVar(vtype=vtype, name="x_%d" % _) for _ in range(ndim)]

    for ind in range(mdim):
        model.addCons(quicksum(amat[ind, _] * vars[_] for _ in
range(ndim)) == bvec[ind])

    model.enableReoptimization()

    for ind in range(ntimes):

        obj_vec = np.random.randn(ndim)
        model.chgReoptObjective(quicksum(obj_vec[_] * vars[_] for _ in
range(ndim)), "minimize")
        model.optimize()

        status = model.getStatus()

        if status == "infeasible":
            raise ValueError("The problem is infeasible")

        soln = np.array([model.getVal(vars[_]) for _ in range(ndim)])
        if vtype == 'B':
            yield soln.round().astype(np.int8)
        else:
            yield soln

On Thu, May 28, 2020 at 2:09 AM Ambros Gleixner <gleixner at zib.de> wrote:
>
> Hi Victor,
>
> Please have a look at
>
>     https://www.scipopt.org/doc/html/REOPT.php
>
> SCIP actually provides an intricate mechanism to do what exactly you
> want and reuse information from the previous solving process.  Whether
> this performs better than solving from scratch depends on how large the
> changes between different objective functions are.  Here is a scientific
> publication that gives more details:
>
>     http://dx.doi.org/10.1007/978-3-319-20086-6_14
>
> To achieve the more plain version of simply solving again from scratch,
> you have to call SCIPfreeTransform(); then you are allowed to modified
> the problem.
>
> Best,
> Ambros
>
>
>
>
> Am 27.05.20 um 23:07 schrieb Victor Miller:
> > I have a MIP which I want to solve a number of times with different
> > objective functions.  Just trying to change the objective after a
> > previous solution doesn't work, so how do I do this?  Do I copy the
> > model, and solve the copy?  If so, is there a standard way of finding
> > out which variables in the copy correspond to the variable in the
> > original?
> >
> > Victor Miller
> > _______________________________________________
> > Scip mailing list
> > Scip at zib.de
> > https://listserv.zib.de/mailman/listinfo/scip
> >
>
> --
> Ambros Gleixner, Research Group Mathematical Optimization Methods at
> Zuse Institute Berlin, http://www.zib.de/gleixner
> _______________________________________________
> Scip mailing list
> Scip at zib.de
> https://listserv.zib.de/mailman/listinfo/scip


More information about the Scip mailing list