Skip to content

Commit

Permalink
test: add indentical variable constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNiklas committed Nov 11, 2024
1 parent 0ccb811 commit e76f1e0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/mip_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from os import environ

import networkx as nx
from mip.entities import LinExpr
import mip.gurobi
import mip.highs
from mip import Model, xsum, OptimizationStatus, MAXIMIZE, BINARY, INTEGER
Expand Down Expand Up @@ -578,6 +579,28 @@ def test_obj_const2(self, solver: str):
assert model.objective_const == 1


@skip_on(NotImplementedError)
@pytest.mark.parametrize("solver", SOLVERS)
@pytest.mark.parametrize("constraint, lb, ub", [
(lambda x: x + x >= 3, 1, 2),
(lambda x: x - x >= 0, 1, 2),
(lambda x: x == x, 1, 2),
(lambda x: x >= x, 1, 2),
(lambda x: x <= x, -2, -1),
# (lambda x: LinExpr([x, x, x], [2, -1, -1], sense="="), 1, 2),
])
def test_identical_vars(solver: str, constraint, lb, ub):
"""Try if constraints are correctly added when variables are identical"""
m = Model(solver_name=solver)
x = m.add_var(name="x", lb=lb, ub=ub, obj=1)

m.add_constr(constraint(x))

m.optimize()
assert m.status == OptimizationStatus.OPTIMAL
assert lb - TOL <= x.x <= ub + TOL


@skip_on(NotImplementedError)
@pytest.mark.parametrize("val", range(1, 4))
@pytest.mark.parametrize("solver", SOLVERS)
Expand Down

0 comments on commit e76f1e0

Please sign in to comment.