Skip to content

Commit 7e1613c

Browse files
Add option for get Rhs, Lhs of nonlinear cons. Remove some mentions of quadratic cons (#935)
1 parent 7aefc8d commit 7e1613c

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
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 option to get Lhs, Rhs of nonlinear constraints
56
- Added cutoffNode and test
67
- Added getMajorVersion, getMinorVersion, and getTechVersion
78
### Fixed

src/pyscipopt/scip.pxi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4362,7 +4362,7 @@ cdef class Model:
43624362
if len(v) == 1: # linear
43634363
var = <Variable>v[0]
43644364
PY_SCIP_CALL(SCIPaddLinearVarNonlinear(self._scip, scip_cons, var.scip_var, c))
4365-
else: # quadratic
4365+
else: # nonlinear
43664366
assert len(v) == 2, 'term length must be 1 or 2 but it is %s' % len(v)
43674367

43684368
varexprs = <SCIP_EXPR**> malloc(2 * sizeof(SCIP_EXPR*))
@@ -4726,7 +4726,7 @@ cdef class Model:
47264726
enforce=True, check=True, propagate=True, local=False,
47274727
modifiable=False, dynamic=False, removable=False,
47284728
stickingatnode=False):
4729-
"""Adds multiple linear or quadratic constraints.
4729+
"""Adds multiple constraints.
47304730
47314731
Each of the constraints is added to the model using Model.addCons().
47324732
@@ -5696,7 +5696,7 @@ cdef class Model:
56965696
Parameters
56975697
----------
56985698
cons : Constraint
5699-
linear or quadratic constraint
5699+
constraint to change the right-hand side from
57005700
rhs : float or None
57015701
new right-hand side (set to None for +infinity)
57025702
@@ -5720,7 +5720,7 @@ cdef class Model:
57205720
Parameters
57215721
----------
57225722
cons : Constraint
5723-
linear or quadratic constraint
5723+
constraint to change the left-hand side from
57245724
lhs : float or None
57255725
new left-hand side (set to None for -infinity)
57265726
@@ -5744,7 +5744,7 @@ cdef class Model:
57445744
Parameters
57455745
----------
57465746
cons : Constraint
5747-
linear or quadratic constraint
5747+
constraint to get the right-hand side from
57485748
57495749
Returns
57505750
-------
@@ -5754,7 +5754,7 @@ cdef class Model:
57545754
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
57555755
if constype == 'linear':
57565756
return SCIPgetRhsLinear(self._scip, cons.scip_cons)
5757-
elif constype == 'quadratic':
5757+
elif constype == 'nonlinear':
57585758
return SCIPgetRhsNonlinear(cons.scip_cons)
57595759
else:
57605760
raise Warning("method cannot be called for constraints of type " + constype)
@@ -5766,7 +5766,7 @@ cdef class Model:
57665766
Parameters
57675767
----------
57685768
cons : Constraint
5769-
linear or quadratic constraint
5769+
linear or nonlinear constraint
57705770
57715771
Returns
57725772
-------
@@ -5776,7 +5776,7 @@ cdef class Model:
57765776
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
57775777
if constype == 'linear':
57785778
return SCIPgetLhsLinear(self._scip, cons.scip_cons)
5779-
elif constype == 'quadratic':
5779+
elif constype == 'nonlinear':
57805780
return SCIPgetLhsNonlinear(cons.scip_cons)
57815781
else:
57825782
raise Warning("method cannot be called for constraints of type " + constype)
@@ -5842,7 +5842,7 @@ cdef class Model:
58425842
Parameters
58435843
----------
58445844
cons : Constraint
5845-
linear or quadratic constraint
5845+
linear constraint
58465846
sol : Solution or None, optional
58475847
solution to compute activity of, None to use current node's solution (Default value = None)
58485848
@@ -5879,7 +5879,7 @@ cdef class Model:
58795879
Parameters
58805880
----------
58815881
cons : Constraint
5882-
linear or quadratic constraint
5882+
linear constraint
58835883
sol : Solution or None, optional
58845884
solution to compute slack of, None to use current node's solution (Default value = None)
58855885
side : str or None, optional

tests/test_nonlinear.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,14 @@ def test_addExprNonLinear():
305305
assert m.getNSols() > 0
306306
assert m.isEQ(m.getVal(y), 2)
307307
assert m.isEQ(m.getVal(z), 27)
308+
309+
def test_nonlinear_lhs_rhs():
310+
from helpers.utils import random_nlp_1
311+
312+
m = random_nlp_1()
313+
c = m.getConss()
314+
315+
m.hideOutput()
316+
m.optimize()
317+
assert m.isInfinity(-m.getLhs(c[0]))
318+
assert m.isEQ(m.getRhs(c[0]), 5)

0 commit comments

Comments
 (0)