Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- Added stage checks to presolve, freereoptsolve, freetransform
- Added primal_dual_evolution recipe and a plot recipe
### Fixed
- Only redirect stdout and stderr in redirectOutput() so that file output still works afterwards
- Added default names to indicator constraints
### Changed
- GitHub actions using Mac now use precompiled SCIP from latest release
### Removed
Expand Down
7 changes: 5 additions & 2 deletions src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
if rc == SCIP_OKAY:
pass
elif rc == SCIP_ERROR:
raise Exception('SCIP: unspecified error!')

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.8)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / test-coverage (3.11)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.8)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.9)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.9)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.10)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.11)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.10)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.12)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.11)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.12)

SCIP: unspecified error!
elif rc == SCIP_NOMEMORY:
raise MemoryError('SCIP: insufficient memory error!')
elif rc == SCIP_READERROR:
Expand Down Expand Up @@ -5339,7 +5339,7 @@

return pyCons

def addConsIndicator(self, cons, binvar=None, activeone=True, name="IndicatorCons",
def addConsIndicator(self, cons, binvar=None, activeone=True, name="",
initial=True, separate=True, enforce=True, check=True,
propagate=True, local=False, dynamic=False,
removable=False, stickingatnode=False):
Expand All @@ -5357,7 +5357,7 @@
activeone : bool, optional
constraint should active if binvar is 1 (0 if activeone = False)
name : str, optional
name of the constraint (Default value = "IndicatorCons")
name of the constraint (Default value = "")
initial : bool, optional
should the LP relaxation of constraint be in the initial LP? (Default value = True)
separate : bool, optional
Expand Down Expand Up @@ -5390,6 +5390,9 @@
if cons._lhs is not None and cons._rhs is not None:
raise ValueError("expected inequality that has either only a left or right hand side")

if name == '':
name = 'c'+str(SCIPgetNConss(self._scip)+1)

if cons.expr.degree() > 1:
raise ValueError("expected linear inequality, expression has degree %d" % cons.expr.degree())

Expand Down
20 changes: 15 additions & 5 deletions tests/test_cons.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,30 @@ def test_SOScons():

def test_cons_indicator():
m = Model()
x = m.addVar(lb=0)
x = m.addVar(lb=0, obj=1)
binvar = m.addVar(vtype="B", lb=1)

c = m.addConsIndicator(x >= 1, binvar)
c1 = m.addConsIndicator(x >= 1, binvar)

slack = m.getSlackVarIndicator(c)
assert c1.name == "c1"

c2 = m.addCons(x <= 3)

c3 = m.addConsIndicator(x >= 0, binvar)
assert c3.name == "c4"

# because addConsIndicator actually adds two constraints
assert m.getNConss() == 5

slack = m.getSlackVarIndicator(c1)

m.optimize()

assert m.getNConss(transformed=False) == 5
assert m.isEQ(m.getVal(slack), 0)
assert m.isEQ(m.getVal(binvar), 1)
assert m.isEQ(m.getVal(x), 1)
assert c.getConshdlrName() == "indicator"

assert c1.getConshdlrName() == "indicator"

@pytest.mark.xfail(
reason="addConsIndicator doesn't behave as expected when binary variable is False. See Issue #717."
Expand Down
Loading