-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add semi-continuous/semi-integer tests
- Loading branch information
1 parent
b2f5757
commit e293015
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import pytest | ||
|
||
from modeler import LPModel, LPStatus, LPVar, LPVarType | ||
|
||
|
||
def test_semicontinuos() -> None: | ||
x = LPVar( | ||
"x", | ||
lower_bound=19, | ||
upper_bound=21, | ||
variable_type=LPVarType.SEMICONTINUOUS, | ||
) | ||
|
||
y = LPVar( | ||
"y", | ||
lower_bound=18, | ||
upper_bound=20, | ||
variable_type=LPVarType.SEMICONTINUOUS, | ||
) | ||
|
||
model = LPModel() | ||
|
||
model.add_constraint(x + y >= 10) | ||
model.add_constraint(x + y <= 30) | ||
|
||
model.set_objective(-x - y) | ||
|
||
model.solve() | ||
|
||
assert model.status == LPStatus.OPTIMAL | ||
|
||
assert x.value() == pytest.approx(21) | ||
assert y.value() == pytest.approx(0) | ||
|
||
|
||
def test_semiinteger() -> None: | ||
x = LPVar( | ||
"x", | ||
lower_bound=19.5, | ||
upper_bound=21.5, | ||
variable_type=LPVarType.SEMIINTEGER, | ||
) | ||
|
||
y = LPVar( | ||
"y", | ||
lower_bound=18.5, | ||
upper_bound=20.5, | ||
variable_type=LPVarType.SEMIINTEGER, | ||
) | ||
|
||
model = LPModel() | ||
|
||
model.add_constraint(x + y >= 10) | ||
model.add_constraint(x + y <= 30) | ||
|
||
model.set_objective(-x - y) | ||
|
||
model.solve() | ||
|
||
assert model.status == LPStatus.OPTIMAL | ||
|
||
assert x.value() == pytest.approx(21) | ||
assert y.value() == pytest.approx(0) |