How to use the pyscipopt.SCIP_RESULT.DIDNOTFIND function in PySCIPOpt

To help you get started, we’ve selected a few PySCIPOpt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SCIP-Interfaces / PySCIPOpt / tests / test_alldiff.py View on Github external
# compute strongly connected components of D and mark edges on the cc as useful
        for g in networkx.strongly_connected_components(D):
            for e in D.subgraph(g).edges():
                if G.has_edge(*e):
                    G.remove_edge(*e)

        # cannot remove edges in matching!
        for var in vars:
            e = (var.name, M[var.name])
            if G.has_edge(*e):
                G.remove_edge(*e)

        # check that there is something to remove
        if G.size() == 0:
            return SCIP_RESULT.DIDNOTFIND

        #print("Edges to remove!", G.edges())
        # remove values
        for var in vars:
            for val in domains[var.ptr()].copy():
                if G.has_edge(var.name, val):
                    domains[var.ptr()].remove(val) # this asserts if value is not there and we shouldn't delete two times the same value

        # "fix" variable when possible
        for var in vars:
            #print("domain of var ", var.name, "is ", domains[var])
            minval = min(domains[var.ptr()])
            maxval = max(domains[var.ptr()])
            if var.getLbLocal() <  minval:
                self.model.chgVarLb(var, minval)
            if var.getUbLocal() > maxval:
github SCIP-Interfaces / PySCIPOpt / tests / test_gomory.py View on Github external
if not scip.isLPSolBasic():
            return {"result": result}

        #TODO: add SCIPgetNLPBranchCands
        # get var data ---> this is the same as getVars!
        vars = scip.getVars(transformed = True)

        # get LP data
        cols = scip.getLPColsData()
        rows = scip.getLPRowsData()

        # exit if LP is trivial
        if len(cols) == 0 or len(rows) == 0:
            return {"result": result}

        result = SCIP_RESULT.DIDNOTFIND

        # get basis indices
        basisind = scip.getLPBasisInd()

        # For all basic columns (not slacks) belonging to integer variables, try to generate a gomory cut
        for i in range(len(rows)):
            tryrow = False
            c = basisind[i]
            #primsol = SCIP_INVALID

            #print("Row %d/%d basic index: %d"%(i, len(rows),c))
            #print("Row %d with value %f"%(i, cols[c].getPrimsol() if c >=0 else scip.getRowActivity(rows[-c-1])))
            if c >= 0:
                assert c < len(cols)
                var = cols[c].getVar()
github SCIP-Interfaces / PySCIPOpt / tests / test_gmi.py View on Github external
if not scip.isLPSolBasic():
            return {"result": result}

        #TODO: add SCIPgetNLPBranchCands
        # get var data ---> this is the same as getVars!
        vars,_,_,_,_ = scip.getVarsData()

        # get LP data
        cols = scip.getLPColsData()
        rows = scip.getLPRowsData()

        # exit if LP is trivial
        if len(cols) == 0 or len(rows) == 0:
            return {"result": result}

        result = SCIP_RESULT.DIDNOTFIND

        # get basis indices
        basisind = scip.getLPBasisInd()

        # For all basic columns (not slacks) belonging to integer variables, try to generate a gomory cut
        ncuts = 0
        for i in range(len(rows)):
            tryrow = False
            c = basisind[i]
            #primsol = SCIP_INVALID

            #print("Row %d/%d basic index: %d"%(i, len(rows),c))
            #print("Row %d with value %f"%(i, cols[c].getPrimsol() if c >=0 else scip.getRowActivity(rows[-c-1])))
            if c >= 0:
                assert c < len(cols)
                var = cols[c].getVar()
github SCIP-Interfaces / PySCIPOpt / tests / test_nlrow.py View on Github external
def heurexec(self, heurtiming, nodeinfeasible):
        self.model.interruptSolve()
        return {"result": SCIP_RESULT.DIDNOTFIND}
github SCIP-Interfaces / PySCIPOpt / tests / test_coloring.py View on Github external
# TODO assert stuff
        # get the only constraint we care about
        consdata = self.stack[-1].data
        if consdata["type"] == "diff":
            for var in self.model.vars:
                if var.isInLP() and var.getUbLocal() > 0.5:
                    if consdata["node1"] in var.stable_set and consdata["node2"] in var.stable_set:
                        self.model.chgVarUb(var, 0.0)
        if consdata["type"] == "same":
            for var in self.model.vars:
                if var.isInLP() and var.getUbLocal() > 0.5:
                    if len(var.stable_set.intersection(set([consdata["node1"], consdata["node2"]]))) == 1:
                        self.model.chgVarUb(var, 0.0)
        consdata["npropagatedvars"] = len(self.model.vars)
        leaving()
        return {"result": SCIP_RESULT.DIDNOTFIND}
github SCIP-Interfaces / PySCIPOpt / tests / test_heur.py View on Github external
def heurexec(self, heurtiming, nodeinfeasible):

        sol = self.model.createSol(self)
        vars = self.model.getVars()

        sol[vars[0]] = 5.0
        sol[vars[1]] = 0.0

        accepted = self.model.trySol(sol)

        if accepted:
            return {"result": SCIP_RESULT.FOUNDSOL}
        else:
            return {"result": SCIP_RESULT.DIDNOTFIND}
github SCIP-Interfaces / PySCIPOpt / tests / test_alldiff.py View on Github external
def consprop(self, constraints, nusefulconss, nmarkedconss, proptiming): # I have no idea what to return, documentation?
        result = SCIP_RESULT.DIDNOTFIND
        for cons in constraints:
            prop_result = self.propagate_cons(cons)
            if prop_result == SCIP_RESULT.CUTOFF:
                result = prop_result
                break
            if prop_result == SCIP_RESULT.REDUCEDDOM:
                result = prop_result

        return {"result": result}