Skip to content

Commit 2102eaf

Browse files
committed
Merge remote-tracking branch 'rael/wecc' into improv_hydro
2 parents 2e36a83 + d84a114 commit 2102eaf

File tree

5 files changed

+377
-239
lines changed

5 files changed

+377
-239
lines changed

switch_model/solve.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def define_arguments(argparser):
527527
# whether that does the same thing as --solver-options-string so we don't reuse the same name.
528528
argparser.add_argument(
529529
"--solver-options-string",
530-
default=None,
530+
default="",
531531
help="A quoted string of options to pass to the model solver. Each option must be of the form option=value. "
532532
"(e.g., --solver-options-string \"mipgap=0.001 primalopt='' advance=2 threads=1\")",
533533
)
@@ -715,6 +715,14 @@ def define_arguments(argparser):
715715
" that all variables must be the same between the previous and current scenario.",
716716
)
717717

718+
argparser.add_argument(
719+
"--gurobi-make-mps",
720+
default=False,
721+
action="store_true",
722+
help="Instead of solving just output a Gurobi .mps file that can be used for debugging numerical properties."
723+
" See https://github.com/staadecker/lp-analyzer/ for details.",
724+
)
725+
718726

719727
def add_recommended_args(argparser):
720728
"""
@@ -898,27 +906,25 @@ def solve(model):
898906
# Note previously solver was saved in model however this is very memory inefficient.
899907
solver = SolverFactory(model.options.solver, solver_io=model.options.solver_io)
900908

901-
# If this option is enabled, gurobi will output an IIS to outputs\iis.ilp.
902-
if model.options.gurobi_find_iis:
903-
# Enable symbolic labels since otherwise we can't debug the .ilp file.
904-
model.options.symbolic_solver_labels = True
909+
if model.options.gurobi_find_iis and model.options.gurobi_make_mps:
910+
raise Exception("Can't use --gurobi-find-iis with --gurobi-make-mps.")
905911

906-
# If no string is passed make the string empty so we can add to it
907-
if model.options.solver_options_string is None:
908-
model.options.solver_options_string = ""
912+
if model.options.gurobi_find_iis or model.options.gurobi_make_mps:
913+
# If we are outputting a file we want to enable symbolic labels to help debugging
914+
model.options.symbolic_solver_labels = True
909915

916+
# If this option is enabled, gurobi will output an IIS to outputs\iis.ilp.
917+
if model.options.gurobi_find_iis:
910918
# Add to the solver options 'ResultFile=iis.ilp'
911919
# https://stackoverflow.com/a/51994135/5864903
912-
iis_file_path = os.path.join(model.options.outputs_dir, "iis.ilp")
913-
model.options.solver_options_string += " ResultFile={}".format(
914-
iis_file_path
920+
model.options.solver_options_string += " ResultFile=iis.ilp"
921+
if model.options.gurobi_make_mps:
922+
# Output the input file and set time limit to zero to ensure it doesn't actually solve
923+
model.options.solver_options_string += (
924+
f" ResultFile=problem.mps TimeLimit=0"
915925
)
916926

917927
if model.options.threads:
918-
# If no string is passed make the string empty so we can add to it
919-
if model.options.solver_options_string is None:
920-
model.options.solver_options_string = ""
921-
922928
model.options.solver_options_string += f" Threads={model.options.threads}"
923929

924930
if model.options.solver_method is not None:

0 commit comments

Comments
 (0)