Skip to content

Commit a3a9fdc

Browse files
use new event in primal dual recipe (#1160)
* use new event in primal dual recipe * typo * Supress warning from expecetd-to-fail test * remove forgotten assert
1 parent 9bf2d9b commit a3a9fdc

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/pyscipopt/recipes/primal_dual_evolution.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,24 @@ class GapEventhdlr(Eventhdlr):
1515

1616
def eventinit(self): # we want to collect best primal solutions and best dual solutions
1717
self.model.catchEvent(SCIP_EVENTTYPE.BESTSOLFOUND, self)
18-
self.model.catchEvent(SCIP_EVENTTYPE.LPSOLVED, self)
19-
self.model.catchEvent(SCIP_EVENTTYPE.NODESOLVED, self)
20-
18+
self.model.catchEvent(SCIP_EVENTTYPE.DUALBOUNDIMPROVED, self)
2119

2220
def eventexec(self, event):
2321
# if a new best primal solution was found, we save when it was found and also its objective
2422
if event.getType() == SCIP_EVENTTYPE.BESTSOLFOUND:
2523
self.model.data["primal_log"].append([self.model.getSolvingTime(), self.model.getPrimalbound()])
2624

27-
if not self.model.data["dual_log"]:
28-
self.model.data["dual_log"].append([self.model.getSolvingTime(), self.model.getDualbound()])
29-
30-
if self.model.getObjectiveSense() == "minimize":
31-
if self.model.isGT(self.model.getDualbound(), self.model.data["dual_log"][-1][1]):
32-
self.model.data["dual_log"].append([self.model.getSolvingTime(), self.model.getDualbound()])
33-
else:
34-
if self.model.isLT(self.model.getDualbound(), self.model.data["dual_log"][-1][1]):
35-
self.model.data["dual_log"].append([self.model.getSolvingTime(), self.model.getDualbound()])
36-
25+
if event.getType() == SCIP_EVENTTYPE.DUALBOUNDIMPROVED:
26+
self.model.data["dual_log"].append([self.model.getSolvingTime(), self.model.getDualbound()])
3727

3828
if not hasattr(model, "data") or model.data==None:
3929
model.data = {}
4030

41-
model.data["primal_log"] = []
42-
model.data["dual_log"] = []
31+
model.data.update({
32+
'primal_log': [],
33+
'dual_log': []
34+
})
35+
4336
hdlr = GapEventhdlr()
4437
model.includeEventhdlr(hdlr, "gapEventHandler", "Event handler which collects primal and dual solution evolution")
4538

tests/test_relax.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def test_relaxator():
4747
class EmptyRelaxator(Relax):
4848
pass
4949

50+
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
5051
def test_empty_relaxator():
5152
m = Model()
5253
m.setPresolve(SCIP_PARAMSETTING.OFF)
@@ -64,9 +65,8 @@ def test_empty_relaxator():
6465

6566
m.setObjective(x1 + x0)
6667

67-
with pytest.raises(Exception):
68-
with pytest.raises(AssertionError):
69-
m.optimize()
68+
with pytest.raises(Exception, match="SCIP"):
69+
m.optimize()
7070

7171
def test_relax():
7272
model = random_mip_1()

0 commit comments

Comments
 (0)