This repository was archived by the owner on Jan 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_installed_solvers.py
More file actions
57 lines (48 loc) · 1.73 KB
/
check_installed_solvers.py
File metadata and controls
57 lines (48 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pulp
import pytest
@pytest.fixture
def ilp():
"""Generate a simple ILP with 5 as an optimal solution."""
prob = pulp.LpProblem("Example", pulp.LpMinimize)
x1 = pulp.LpVariable("x1", 0, 10, pulp.LpInteger)
x2 = pulp.LpVariable("x2", 5, 10, pulp.LpInteger)
prob += x1 + x2, "obj"
prob += x1 + x2 <= 6, "c1"
return prob
class TestSolver(object):
"""Test Installed Solvers."""
def test_glpk(self, ilp):
"""Test method for GLPK."""
try:
ilp.solve(pulp.GLPK())
assert round(pulp.value(ilp.objective), 0) == 5
except pulp.solvers.PulpSolverError:
pytest.fail(f"Solver not installed")
def test_cbc(self, ilp):
"""Test method for CBC."""
try:
ilp.solve(pulp.COIN())
assert round(pulp.value(ilp.objective), 0) == 5
except pulp.solvers.PulpSolverError:
pytest.fail(f"Solver not installed")
def test_cplex(self, ilp):
"""Test method for CPLEX."""
try:
ilp.solve(pulp.CPLEX_PY())
assert round(pulp.value(ilp.objective), 0) == 5
except pulp.solvers.PulpSolverError:
pytest.fail(f"Solver not installed")
def test_gurobi(self, ilp):
"""Test method for GUROBI."""
try:
ilp.solve(pulp.GUROBI())
assert round(pulp.value(ilp.objective), 0) == 5
except pulp.solvers.PulpSolverError:
pytest.fail(f"Solver not installed")
def test_scip(self, ilp):
"""Test method for SCIP."""
try:
ilp.solve(pulp.SCIP())
assert round(pulp.value(ilp.objective), 0) == 5
except pulp.solvers.PulpSolverError:
pytest.fail(f"Solver not installed")