Skip to content

Commit 378f111

Browse files
Merge branch 'master' into add-requests-to-README
2 parents c333b1a + b94dbb7 commit 378f111

File tree

9 files changed

+44
-11
lines changed

9 files changed

+44
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
### Added
5+
- Added cutoffNode and test
56
### Fixed
67
### Changed
78
### Removed

src/pyscipopt/scip.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ cdef extern from "scip/scip.h":
877877
SCIP_Real SCIPgetPrimalbound(SCIP* scip)
878878
SCIP_Real SCIPgetGap(SCIP* scip)
879879
int SCIPgetDepth(SCIP* scip)
880+
SCIP_RETCODE SCIPcutoffNode(SCIP* scip, SCIP_NODE* node)
880881
SCIP_Bool SCIPhasPrimalRay(SCIP * scip)
881882
SCIP_Real SCIPgetPrimalRayVal(SCIP * scip, SCIP_VAR * var)
882883
SCIP_RETCODE SCIPaddSolFree(SCIP* scip, SCIP_SOL** sol, SCIP_Bool* stored)

src/pyscipopt/scip.pxi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ cdef class Node:
13131313
13141314
"""
13151315
return SCIPnodeIsActive(self.scip_node)
1316-
1316+
13171317
def isPropagatedAgain(self):
13181318
"""
13191319
Is the node marked to be propagated again?
@@ -2335,6 +2335,16 @@ cdef class Model:
23352335
"""
23362336
return SCIPgetDepth(self._scip)
23372337

2338+
def cutoffNode(self, Node node):
2339+
"""
2340+
marks node and whole subtree to be cut off from the branch and bound tree.
2341+
2342+
Parameters
2343+
----------
2344+
node : Node
2345+
"""
2346+
PY_SCIP_CALL( SCIPcutoffNode(self._scip, node.scip_node) )
2347+
23382348
def infinity(self):
23392349
"""
23402350
Retrieve SCIP's infinity value.

tests/helpers/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pyscipopt import Model, quicksum, SCIP_PARAMSETTING, exp, log, sqrt, sin
22
from typing import List
33

4-
def random_mip_1(disable_sepa=True, disable_huer=True, disable_presolve=True, node_lim=2000, small=False):
4+
def random_mip_1(disable_sepa=True, disable_heur=True, disable_presolve=True, node_lim=2000, small=False):
55
model = Model()
66

77
x0 = model.addVar(lb=-2, ub=4)
@@ -41,7 +41,7 @@ def random_mip_1(disable_sepa=True, disable_huer=True, disable_presolve=True, no
4141

4242
if disable_sepa:
4343
model.setSeparating(SCIP_PARAMSETTING.OFF)
44-
if disable_huer:
44+
if disable_heur:
4545
model.setHeuristics(SCIP_PARAMSETTING.OFF)
4646
if disable_presolve:
4747
model.setPresolve(SCIP_PARAMSETTING.OFF)

tests/test_heur.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def inner():
124124

125125
def test_simple_round_heur():
126126
# create solver instance
127-
s = random_mip_1(disable_sepa=False, disable_huer=False, node_lim=1)
127+
s = random_mip_1(disable_sepa=False, disable_heur=False, node_lim=1)
128128
heuristic = SimpleRoundingHeuristic()
129129
s.includeHeur(heuristic, "SimpleRounding", "simple rounding heuristic implemented in python", "Y",
130130
timingmask=SCIP_HEURTIMING.DURINGLPLOOP)

tests/test_node.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from pyscipopt import SCIP_RESULT, Eventhdlr, SCIP_EVENTTYPE
2+
from helpers.utils import random_mip_1
3+
4+
class cutoffEventHdlr(Eventhdlr):
5+
def eventinit(self):
6+
self.model.catchEvent(SCIP_EVENTTYPE.NODEFOCUSED, self)
7+
8+
def eventexec(self, event):
9+
self.model.cutoffNode(self.model.getCurrentNode())
10+
return {'result': SCIP_RESULT.SUCCESS}
11+
12+
def test_cutoffNode():
13+
m = random_mip_1(disable_heur=True, disable_presolve=True, disable_sepa=True)
14+
15+
hdlr = cutoffEventHdlr()
16+
17+
m.includeEventhdlr(hdlr, "test", "test")
18+
19+
m.optimize()
20+
21+
assert m.getNSols() == 0

tests/test_nogil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def test_optimalNogil():
9-
ori_model = random_mip_1(disable_sepa=False, disable_huer=False, disable_presolve=False, node_lim=2000, small=True)
9+
ori_model = random_mip_1(disable_sepa=False, disable_heur=False, disable_presolve=False, node_lim=2000, small=True)
1010
models = [Model(sourceModel=ori_model) for _ in range(N_Threads)]
1111
for i in range(N_Threads):
1212
models[i].setParam("randomization/permutationseed", i)

tests/test_solution.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def test_getSols():
197197

198198

199199
def test_getOrigin_retrasform():
200-
m = random_mip_1(disable_sepa=False, disable_huer=False, disable_presolve=False, small=True)
200+
m = random_mip_1(disable_sepa=False, disable_heur=False, disable_presolve=False, small=True)
201201
m.optimize()
202202

203203
sol = m.getBestSol()
@@ -208,11 +208,11 @@ def test_getOrigin_retrasform():
208208

209209

210210
def test_translate():
211-
m = random_mip_1(disable_sepa=False, disable_huer=False, disable_presolve=False, small=True)
211+
m = random_mip_1(disable_sepa=False, disable_heur=False, disable_presolve=False, small=True)
212212
m.optimize()
213213
sol = m.getBestSol()
214214

215-
m1 = random_mip_1(disable_sepa=False, disable_huer=False, disable_presolve=False, small=True)
215+
m1 = random_mip_1(disable_sepa=False, disable_heur=False, disable_presolve=False, small=True)
216216
sol1 = sol.translate(m1)
217217
assert m1.addSol(sol1) == True
218218
assert m1.getNSols() == 1

tests/test_strong_branching.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def branchexeclp(self, allowaddcons):
140140

141141

142142
def test_strong_branching():
143-
scip = random_mip_1(disable_presolve=False, disable_huer=False, small=True, node_lim=500)
143+
scip = random_mip_1(disable_presolve=False, disable_heur=False, small=True, node_lim=500)
144144

145145
strong_branch_rule = StrongBranchingRule(scip, idempotent=False)
146146
scip.includeBranchrule(strong_branch_rule, "strong branch rule", "custom strong branching rule",
@@ -155,7 +155,7 @@ def test_strong_branching():
155155

156156

157157
def test_strong_branching_idempotent():
158-
scip = random_mip_1(disable_presolve=False, disable_huer=False, small=True, node_lim=500)
158+
scip = random_mip_1(disable_presolve=False, disable_heur=False, small=True, node_lim=500)
159159

160160
strong_branch_rule = StrongBranchingRule(scip, idempotent=True)
161161
scip.includeBranchrule(strong_branch_rule, "strong branch rule", "custom strong branching rule",
@@ -170,7 +170,7 @@ def test_strong_branching_idempotent():
170170

171171

172172
def test_dummy_feature_selector():
173-
scip = random_mip_1(disable_presolve=False, disable_huer=False, small=True, node_lim=300)
173+
scip = random_mip_1(disable_presolve=False, disable_heur=False, small=True, node_lim=300)
174174

175175
feature_dummy_branch_rule = FeatureSelectorBranchingRule(scip)
176176
scip.includeBranchrule(feature_dummy_branch_rule, "dummy branch rule", "custom feature creation branching rule",

0 commit comments

Comments
 (0)