Skip to content

Commit 25c5ca4

Browse files
committed
Add check for inputs sooner in process
1 parent 4a45222 commit 25c5ca4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

switch_model/solve.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ def debug(type, value, tb):
131131
# get a list of modules to iterate through
132132
iterate_modules = get_iteration_list(model)
133133

134+
# Very that the proper modules are installed
135+
if model.options.solver == "cplex_direct":
136+
import cplex
137+
elif model.options.solver in ("gurobi_direct", "gurobi_aug"):
138+
import gurobipy
139+
134140
if model.options.verbose:
135141
print(
136142
"\n======================================================================="
@@ -887,6 +893,8 @@ def solve(model):
887893
# If we need warm start switch the solver to our augmented version that supports warm starting
888894
solver_type = model.options.solver
889895
gurobi_types = ("gurobi", "gurobi_direct", "gurobi_aug")
896+
cplex_types = ("cplex", "cplex_direct")
897+
890898
if model.options.warm_start is not None or model.options.save_warm_start:
891899
if solver_type not in gurobi_types:
892900
raise NotImplementedError(
@@ -925,7 +933,7 @@ def solve(model):
925933
if model.options.no_crossover:
926934
if solver_type in gurobi_types:
927935
options_string += " crossover=0"
928-
elif solver_type == "cplex":
936+
elif solver_type in cplex_types:
929937
options_string = " solutiontype=2"
930938
else:
931939
raise NotImplementedError(
@@ -940,7 +948,7 @@ def solve(model):
940948
if method == "barrier":
941949
method = 2
942950
options_string += f" method={method}"
943-
elif solver_type == "cplex":
951+
elif solver_type in cplex_types:
944952
if method == "barrier":
945953
method = 4
946954
options_string += f" LPMethod={method}"

0 commit comments

Comments
 (0)