Skip to content

Commit be5e698

Browse files
authored
Add missing numerical access functions (#996)
* Add missing numerical access functions * Add test cases for numerical access functions
1 parent 6452ea6 commit be5e698

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/pyscipopt/scip.pxi

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,6 +3148,52 @@ cdef class Model:
31483148
"""
31493149
return SCIPisGT(self._scip, val1, val2)
31503150

3151+
def isHugeValue(self, val):
3152+
"""
3153+
Checks if value is huge and should be
3154+
handled separately (e.g., in activity computation).
3155+
3156+
Parameters
3157+
----------
3158+
val : float
3159+
3160+
Returns
3161+
-------
3162+
bool
3163+
3164+
"""
3165+
return SCIPisHugeValue(self._scip, val)
3166+
3167+
def isPositive(self, val):
3168+
"""
3169+
Returns whether val > eps.
3170+
3171+
Parameters
3172+
----------
3173+
val : float
3174+
3175+
Returns
3176+
-------
3177+
bool
3178+
3179+
"""
3180+
return SCIPisPositive(self._scip, val)
3181+
3182+
def isNegative(self, val):
3183+
"""
3184+
Returns whether val < -eps.
3185+
3186+
Parameters
3187+
----------
3188+
val : float
3189+
3190+
Returns
3191+
-------
3192+
bool
3193+
3194+
"""
3195+
return SCIPisNegative(self._scip, val)
3196+
31513197
def getCondition(self, exact=False):
31523198
"""
31533199
Get the current LP's condition number.

tests/test_model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,15 @@ def test_redirection():
518518

519519
# compare objective values
520520
assert original.isEQ(redirect.getObjVal(), original.getObjVal())
521+
522+
def test_comparisons():
523+
from math import inf
524+
model = Model()
525+
526+
assert model.isPositive(1.)
527+
assert model.isNegative(-1.)
528+
529+
assert not model.isPositive(0.)
530+
assert not model.isNegative(0.)
531+
532+
assert model.isHugeValue(inf)

0 commit comments

Comments
 (0)