Skip to content

Commit 6c42351

Browse files
committed
Add test for _createConsBasicLinear and README
1 parent b9b815a commit 6c42351

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44
### Added
5+
- Added transformProb but no test
6+
- Added _createConsBasicLinear and test
57
- Expanded Statistics class to more problems.
68
- Created Statistics class
79
- Added parser to read .stats file

src/pyscipopt/scip.pxi

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4140,14 +4140,16 @@ cdef class Model:
41404140
free(coeffs_array)
41414141
return PyCons
41424142

4143-
def _createConsBasicLinear(self, ExprCons lincons, **kwargs):
4143+
def _createConsBasicLinear(self, ExprCons lincons, name='', **kwargs):
41444144
"""
41454145
The function for creating a basic linear constraint, but not adding it to the Model.
41464146
41474147
Parameters
41484148
----------
41494149
lincons : ExprCons
4150-
kwargs : dict, optional
4150+
name : str, optional
4151+
name of constraint
4152+
kwargs : dict, optional
41514153
41524154
Returns
41534155
-------
@@ -4161,6 +4163,13 @@ cdef class Model:
41614163

41624164
cdef SCIP_CONS* scip_cons
41634165

4166+
if name == '':
4167+
name = 'c'+str(SCIPgetNConss(self._scip)+1)
4168+
4169+
kwargs = dict(name=name)
4170+
kwargs['lhs'] = -SCIPinfinity(self._scip) if lincons._lhs is None else lincons._lhs
4171+
kwargs['rhs'] = SCIPinfinity(self._scip) if lincons._rhs is None else lincons._rhs
4172+
41644173
cdef int nvars = len(terms.items())
41654174

41664175
vars_array = <SCIP_VAR**> malloc(nvars * sizeof(SCIP_VAR*))
@@ -4178,6 +4187,8 @@ cdef class Model:
41784187

41794188
free(vars_array)
41804189
free(coeffs_array)
4190+
4191+
PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
41814192
return PyCons
41824193

41834194
def _createConsQuadratic(self, ExprCons quadcons, **kwargs):
@@ -9047,7 +9058,7 @@ cdef class Model:
90479058
SCIP_STAGE_SOLVING,
90489059
SCIP_STAGE_SOLVED]:
90499060
raise Warning("method cannot be called in stage %i." % self.getStage)
9050-
9061+
90519062
PY_SCIP_CALL(SCIPfreeReoptSolve(self._scip))
90529063

90539064
def chgReoptObjective(self, coeffs, sense = 'minimize'):

tests/test_cons.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ def test_addConsDisjunction_expr_init():
204204
assert m.isEQ(m.getVal(y), 5)
205205
assert m.isEQ(m.getVal(o), 6)
206206

207+
def test__createConsBasicLinear():
208+
m = Model()
209+
x = m.addVar()
210+
y = m.addVar()
211+
212+
assert m.getNConss() == 0
213+
214+
c = m._createConsBasicLinear(x+y<=4)
215+
216+
217+
assert m.getNConss() == 0
218+
assert c.isLinear()
207219

208220
@pytest.mark.skip(reason="TODO: test getValsLinear()")
209221
def test_getValsLinear():

tests/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,4 +476,4 @@ def test_getObjVal():
476476
assert m.getVal(x) == 0
477477

478478
assert m.getObjVal() == 16
479-
assert m.getVal(x) == 0
479+
assert m.getVal(x) == 0

0 commit comments

Comments
 (0)