mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Make tests compatible with Python 3.7+
This commit is contained in:
@@ -2,23 +2,29 @@
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
from inspect import isclass
|
||||
from miplearn import BasePyomoSolver, GurobiSolver, GurobiPyomoSolver
|
||||
from miplearn.problems.knapsack import KnapsackInstance, GurobiKnapsackInstance
|
||||
|
||||
|
||||
def _get_instance(solver):
|
||||
if issubclass(solver, BasePyomoSolver) or isinstance(solver, BasePyomoSolver):
|
||||
def _is_subclass_or_instance(solver, parentClass):
|
||||
return isinstance(solver, parentClass) or (isclass(solver) and issubclass(solver, parentClass))
|
||||
|
||||
if _is_subclass_or_instance(solver, BasePyomoSolver):
|
||||
return KnapsackInstance(
|
||||
weights=[23., 26., 20., 18.],
|
||||
prices=[505., 352., 458., 220.],
|
||||
capacity=67.,
|
||||
)
|
||||
if issubclass(solver, GurobiSolver) or isinstance(solver, GurobiSolver):
|
||||
|
||||
if _is_subclass_or_instance(solver, GurobiSolver):
|
||||
return GurobiKnapsackInstance(
|
||||
weights=[23., 26., 20., 18.],
|
||||
prices=[505., 352., 458., 220.],
|
||||
capacity=67.,
|
||||
)
|
||||
|
||||
assert False
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user