How to use the pyscipopt.SCIP_RESULT.CUTOFF 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
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}
github SCIP-Interfaces / PySCIPOpt / tests / test_gmi.py View on Github external
#print(" -> gomory cut for <%s>:  rhs=%f, eff=%f"%(cols[c].getVar() if c >= 0 else rows[-c-1].getName(),
                        #cutrhs, scip.getCutEfficacy(None, cut)))

                    #SCIPdebugMessage(" -> found gomory cut <%s>: act=%f, rhs=%f, norm=%f, eff=%f, min=%f, max=%f (range=%f)\n",
                    #   cutname, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
                    #   SCIPgetCutEfficacy(scip, NULL, cut),
                    #   SCIPgetRowMinCoef(scip, cut), SCIPgetRowMaxCoef(scip, cut),
                    #   SCIPgetRowMaxCoef(scip, cut)/SCIPgetRowMinCoef(scip, cut))

                    # flush all changes before adding the cut
                    scip.flushRowExtensions(cut)

                    infeasible = scip.addCut(cut, forcecut=True)

                    if infeasible:
                       result = SCIP_RESULT.CUTOFF
                    else:
                       result = SCIP_RESULT.SEPARATED
                scip.releaseRow(cut)

        return {"result": result}
github SCIP-Interfaces / PySCIPOpt / tests / test_gmi.py View on Github external
# so that then one can ask stuff about it, like its efficacy, etc. This function would receive all coefficients
                # and basically do what we do here: cacheRowExtension etc
                cut = scip.createEmptyRowSepa(self, "gmi%d_x%d"%(scip.getNLPs(),c if c >= 0 else -c-1), lhs = None, rhs = cutrhs)
                scip.cacheRowExtensions(cut)

                for j in range(len(cutcoefs)):
                    if scip.isZero(cutcoefs[j]): # maybe here we need isFeasZero
                        continue
                    #print("var : ", cols[j].getVar(), " coef: ", cutcoefs[j])
                    #print("cut.lhs : ", cut.getLhs(), " cut.rhs: ", cut.getRhs())
                    scip.addVarToRow(cut, cols[j].getVar(), cutcoefs[j])

                if cut.getNNonz() == 0:
                    assert scip.isFeasNegative(cutrhs)
                    #print("Gomory cut is infeasible: 0 <= ", cutrhs)
                    return {"result": SCIP_RESULT.CUTOFF}


                # Only take efficacious cuts, except for cuts with one non-zero coefficient (= bound changes)
                # the latter cuts will be handeled internally in sepastore.
                if cut.getNNonz() == 1 or scip.isCutEfficacious(cut):
                    #print(" -> gomory cut for <%s>:  rhs=%f, eff=%f"%(cols[c].getVar() if c >= 0 else rows[-c-1].getName(),
                        #cutrhs, scip.getCutEfficacy(None, cut)))

                    #SCIPdebugMessage(" -> found gomory cut <%s>: act=%f, rhs=%f, norm=%f, eff=%f, min=%f, max=%f (range=%f)\n",
                    #   cutname, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
                    #   SCIPgetCutEfficacy(scip, NULL, cut),
                    #   SCIPgetRowMinCoef(scip, cut), SCIPgetRowMaxCoef(scip, cut),
                    #   SCIPgetRowMaxCoef(scip, cut)/SCIPgetRowMinCoef(scip, cut))

                    # flush all changes before adding the cut
                    scip.flushRowExtensions(cut)
github SCIP-Interfaces / PySCIPOpt / tests / test_alldiff.py View on Github external
# We would need an event handler to let us know whenever a variable of our constraint changed its domain
        # Currently we can't write event handlers in python.

        G, vals = self.build_value_graph(vars, domains)
        try:
            M = networkx.bipartite.maximum_matching(G) # returns dict between nodes in matching
        except:
            top_nodes = {n for n, d in G.nodes(data=True) if d['bipartite'] == 0}
            bottom_nodes = set(G) - top_nodes
            M = networkx.bipartite.maximum_matching(G, top_nodes) # returns dict between nodes in matching

        if( len(M)/2 < len(vars) ):
            #print("it is infeasible: max matching of card ", len(M), " M: ", M)
            #print("Its value graph:\nV = ", G.nodes(), "\nE = ", G.edges())
            plot_graph(G)
            return SCIP_RESULT.CUTOFF

        # build auxiliary directed graph: direct var -> val if [var, val] is in matching, otherwise var <- val
        # note that all vars are matched
        D = networkx.DiGraph()
        D.add_nodes_from(G) ## this seems to work
        for var in vars:
            D.add_edge(var.name, M[var.name])
            for val in domains[var.ptr()]:
                if val != M[var.name]:
                    D.add_edge(val, var.name)

        # find arcs that *do not* need to be removed and *remove* them from G. All remaining edges of G
        # should be use to remove values from the domain of variables
        # get all free vertices
        V = set(G.nodes())
        V_matched = set(M)
github SCIP-Interfaces / PySCIPOpt / tests / test_gomory.py View on Github external
# so that then one can ask stuff about it, like its efficacy, etc. This function would receive all coefficients
                # and basically do what we do here: cacheRowExtension etc up to releaseRow
                cut = scip.createEmptyRowSepa(self, "gmi%d_x%d"%(self.ncuts,c if c >= 0 else -c-1), lhs = None, rhs = cutrhs)
                scip.cacheRowExtensions(cut)

                for j in range(len(cutcoefs)):
                    if scip.isZero(cutcoefs[j]): # maybe here we need isFeasZero
                        continue
                    #print("var : ", cols[j].getVar(), " coef: ", cutcoefs[j])
                    #print("cut.lhs : ", cut.getLhs(), " cut.rhs: ", cut.getRhs())
                    scip.addVarToRow(cut, cols[j].getVar(), cutcoefs[j])

                if cut.getNNonz() == 0:
                    assert scip.isFeasNegative(cutrhs)
                    #print("Gomory cut is infeasible: 0 <= ", cutrhs)
                    return {"result": SCIP_RESULT.CUTOFF}


                # Only take efficacious cuts, except for cuts with one non-zero coefficient (= bound changes)
                # the latter cuts will be handeled internally in sepastore.
                if cut.getNNonz() == 1 or scip.isCutEfficacious(cut):
                    #print(" -> gomory cut for <%s>:  rhs=%f, eff=%f"%(cols[c].getVar() if c >= 0 else rows[-c-1].getName(),
                     #   cutrhs, scip.getCutEfficacy(cut)))

                    #SCIPdebugMessage(" -> found gomory cut <%s>: act=%f, rhs=%f, norm=%f, eff=%f, min=%f, max=%f (range=%f)\n",
                    #   cutname, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
                    #   SCIPgetCutEfficacy(scip, NULL, cut),
                    #   SCIPgetRowMinCoef(scip, cut), SCIPgetRowMaxCoef(scip, cut),
                    #   SCIPgetRowMaxCoef(scip, cut)/SCIPgetRowMinCoef(scip, cut))

                    # flush all changes before adding the cut
                    scip.flushRowExtensions(cut)
github SCIP-Interfaces / PySCIPOpt / tests / test_gomory.py View on Github external
#   cutrhs, scip.getCutEfficacy(cut)))

                    #SCIPdebugMessage(" -> found gomory cut <%s>: act=%f, rhs=%f, norm=%f, eff=%f, min=%f, max=%f (range=%f)\n",
                    #   cutname, SCIPgetRowLPActivity(scip, cut), SCIProwGetRhs(cut), SCIProwGetNorm(cut),
                    #   SCIPgetCutEfficacy(scip, NULL, cut),
                    #   SCIPgetRowMinCoef(scip, cut), SCIPgetRowMaxCoef(scip, cut),
                    #   SCIPgetRowMaxCoef(scip, cut)/SCIPgetRowMinCoef(scip, cut))

                    # flush all changes before adding the cut
                    scip.flushRowExtensions(cut)

                    infeasible = scip.addCut(cut, forcecut=True)
                    self.ncuts += 1

                    if infeasible:
                       result = SCIP_RESULT.CUTOFF
                    else:
                       result = SCIP_RESULT.SEPARATED
                scip.releaseRow(cut)

        return {"result": result}
github ds4dm / learn2branch / 05_evaluate.py View on Github external
# feature normalization
                candidate_states =  (candidate_states - self.feat_shift) / self.feat_scale

                candidate_scores = self.policy.predict(candidate_states)
                best_var = candidate_vars[candidate_scores.argmax()]

            else:
                raise NotImplementedError

            self.model.branchVar(best_var)
            result = scip.SCIP_RESULT.BRANCHED

        # fair node counting
        if result == scip.SCIP_RESULT.REDUCEDDOM:
            self.ndomchgs += 1
        elif result == scip.SCIP_RESULT.CUTOFF:
            self.ncutoffs += 1

        return {'result': result}