Skip to content

Commit faa9dec

Browse files
committed
Add check for inputs sooner in process
1 parent e1a9f50 commit faa9dec

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
@@ -113,6 +113,12 @@ def debug(type, value, tb):
113113
# get a list of modules to iterate through
114114
iterate_modules = get_iteration_list(model)
115115

116+
# Very that the proper modules are installed
117+
if model.options.solver == "cplex_direct":
118+
import cplex
119+
elif model.options.solver in ("gurobi_direct", "gurobi_aug"):
120+
import gurobipy
121+
116122
if model.options.verbose:
117123
print("\n=======================================================================")
118124
print("Switch {}, http://switch-model.org".format(switch_model.__version__))
@@ -694,6 +700,8 @@ def solve(model):
694700
# If we need warm start switch the solver to our augmented version that supports warm starting
695701
solver_type = model.options.solver
696702
gurobi_types = ("gurobi", "gurobi_direct", "gurobi_aug")
703+
cplex_types = ("cplex", "cplex_direct")
704+
697705
if model.options.warm_start is not None or model.options.save_warm_start:
698706
if solver_type not in gurobi_types:
699707
raise NotImplementedError("Warm start functionality requires --solver gurobi")
@@ -730,7 +738,7 @@ def solve(model):
730738
if model.options.no_crossover:
731739
if solver_type in gurobi_types:
732740
options_string += " crossover=0"
733-
elif solver_type == "cplex":
741+
elif solver_type in cplex_types:
734742
options_string = " solutiontype=2"
735743
else:
736744
raise NotImplementedError(f"--no-crossover not implemented for solver {solver}")
@@ -743,7 +751,7 @@ def solve(model):
743751
if method == "barrier":
744752
method = 2
745753
options_string += f" method={method}"
746-
elif solver_type == "cplex":
754+
elif solver_type in cplex_types:
747755
if method == "barrier":
748756
method = 4
749757
options_string += f" LPMethod={method}"

0 commit comments

Comments
 (0)