Add types to InternalSolver

This commit is contained in:
2021-01-20 10:07:28 -06:00
parent 69a82172b9
commit 1971389a57
10 changed files with 267 additions and 174 deletions

View File

@@ -3,7 +3,9 @@
# Released under the modified BSD license. See COPYING.md for more details.
from inspect import isclass
from miplearn import BasePyomoSolver, GurobiSolver, GurobiPyomoSolver
from typing import List, Callable
from miplearn import BasePyomoSolver, GurobiSolver, GurobiPyomoSolver, InternalSolver
from miplearn.problems.knapsack import KnapsackInstance, GurobiKnapsackInstance
from miplearn.solvers.pyomo.xpress import XpressPyomoSolver
@@ -31,5 +33,5 @@ def _get_instance(solver):
assert False
def _get_internal_solvers():
def _get_internal_solvers() -> List[Callable[[], InternalSolver]]:
return [GurobiPyomoSolver, GurobiSolver, XpressPyomoSolver]

View File

@@ -4,6 +4,7 @@
import logging
from io import StringIO
from warnings import warn
import pyomo.environ as pe
@@ -45,6 +46,8 @@ def test_internal_solver_warm_starts():
stats = solver.solve(tee=True)
if "Warm start value" in stats:
assert stats["Warm start value"] == 725.0
else:
warn(f"{solver_class.__name__} should set warm start value")
solver.set_warm_start(
{
@@ -57,8 +60,7 @@ def test_internal_solver_warm_starts():
}
)
stats = solver.solve(tee=True)
if "Warm start value" in stats:
assert stats["Warm start value"] is None
assert "Warm start value" not in stats
solver.fix(
{
@@ -86,6 +88,7 @@ def test_internal_solver():
stats = solver.solve_lp()
assert round(stats["Optimal value"], 3) == 1287.923
assert len(stats["Log"]) > 100
solution = solver.get_solution()
assert round(solution["x"][0], 3) == 1.000