Skip to content

Commit d31337a

Browse files
committed
pyscipopt style
1 parent ace9ec3 commit d31337a

File tree

2 files changed

+58
-19
lines changed

2 files changed

+58
-19
lines changed

src/pyscipopt/scip.pxi

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,20 +2665,55 @@ cdef class _VarArray:
26652665

26662666
cdef class IIS:
26672667
cdef SCIP_IIS* _iis
2668-
cdef SCIP* subscip
2669-
cdef public object time
2670-
cdef public object irreducible
2671-
cdef public object nodes
2672-
cdef public object model
26732668

26742669
def __init__(self, Model model):
26752670
self._iis = SCIPgetIIS(model._scip)
2676-
self.time = SCIPiisGetTime(self._iis)
2677-
self.irreducible = SCIPiisIsSubscipIrreducible(self._iis)
2678-
self.nodes = SCIPiisGetNNodes(self._iis)
2679-
subscip = SCIPiisGetSubscip(self._iis)
2680-
self.model = Model.create(subscip)
26812671
model._iis = self._iis
2672+
2673+
def getTime(self):
2674+
"""
2675+
Retrieve the solving time of the IIS.
2676+
2677+
Returns
2678+
-------
2679+
float
2680+
"""
2681+
return SCIPiisGetTime(self._iis)
2682+
2683+
def isSubscipIrreducible(self):
2684+
"""
2685+
Returns whether the IIS is irreducible.
2686+
2687+
Returns
2688+
-------
2689+
bool
2690+
"""
2691+
return SCIPiisIsSubscipIrreducible(self._iis)
2692+
2693+
def getNNodes(self):
2694+
"""
2695+
Gets number of nodes in the IIS solve.
2696+
2697+
Returns
2698+
-------
2699+
int
2700+
2701+
"""
2702+
return SCIPiisGetNNodes(self._iis)
2703+
2704+
def getSubscip(self):
2705+
"""
2706+
Get the subscip of an IIS.
2707+
2708+
Returns
2709+
-------
2710+
Model
2711+
"""
2712+
cdef SCIP* subscip
2713+
2714+
subscip = SCIPiisGetSubscip(self._iis)
2715+
model = Model.create(subscip)
2716+
return model
26822717

26832718
# - remove create(), includeDefaultPlugins(), createProbBasic() methods
26842719
# - replace free() by "destructor"

tests/test_iis.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ def infeasible_model():
1919
def test_generate_iis():
2020
m = infeasible_model()
2121

22+
m.optimize()
23+
2224
# make sure IIS generation doesn't raise any exceptions
2325
iis = m.generateIIS()
24-
assert iis.irreducible
25-
assert iis.model.getNConss() == 2
26-
assert iis.nodes == 0
27-
iis.time
26+
subscip = iis.getSubscip()
27+
assert iis.isSubscipIrreducible()
28+
assert subscip.getNConss() == 2
29+
assert iis.getNNodes() == 0
30+
assert iis.getTime() > 0
2831

2932
class myIIS(IISfinder):
3033
def __init__(self, model, skip=False):
@@ -50,21 +53,22 @@ def test_custom_iis_finder():
5053
m = infeasible_model()
5154
my_iis = myIIS(m)
5255

56+
m.setParam("iis/greedy/priority", -1)
5357
m.includeIISfinder(my_iis, "", "")
5458

5559
m.generateIIS()
5660
iis = m.getIIS()
57-
assert iis.model.getNConss() == my_iis.size
61+
subscip = iis.getSubscip()
62+
assert subscip.getNConss() == my_iis.size
5863

5964
def test_iisGreddyMakeIrreducible():
6065
m = infeasible_model()
6166

62-
m.setParam("iis/greedy/priority", -1)
6367
my_iis = myIIS(m, skip=True)
64-
m.includeIISfinder(my_iis, "", "")
68+
m.includeIISfinder(my_iis, "", "", priority=9999999)
6569
iis = m.generateIIS()
6670
with pytest.raises(AssertionError):
67-
assert not iis.irreducible # currently breaking. do SCIP IIS methods enter after custom iisfinder?
71+
assert not iis.isSubscipIrreducible() # currently breaking. do SCIP IIS methods enter after custom iisfinder?
6872

6973
m.iisGreedyMakeIrreducible(iis)
70-
assert iis.irreducible
74+
assert iis.isSubscipIrreducible()

0 commit comments

Comments
 (0)