@@ -527,7 +527,7 @@ def define_arguments(argparser):
527
527
# whether that does the same thing as --solver-options-string so we don't reuse the same name.
528
528
argparser .add_argument (
529
529
"--solver-options-string" ,
530
- default = None ,
530
+ default = "" ,
531
531
help = "A quoted string of options to pass to the model solver. Each option must be of the form option=value. "
532
532
"(e.g., --solver-options-string \" mipgap=0.001 primalopt='' advance=2 threads=1\" )" ,
533
533
)
@@ -715,6 +715,14 @@ def define_arguments(argparser):
715
715
" that all variables must be the same between the previous and current scenario." ,
716
716
)
717
717
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
+
718
726
719
727
def add_recommended_args (argparser ):
720
728
"""
@@ -898,27 +906,25 @@ def solve(model):
898
906
# Note previously solver was saved in model however this is very memory inefficient.
899
907
solver = SolverFactory (model .options .solver , solver_io = model .options .solver_io )
900
908
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." )
905
911
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
909
915
916
+ # If this option is enabled, gurobi will output an IIS to outputs\iis.ilp.
917
+ if model .options .gurobi_find_iis :
910
918
# Add to the solver options 'ResultFile=iis.ilp'
911
919
# 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"
915
925
)
916
926
917
927
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
-
922
928
model .options .solver_options_string += f" Threads={ model .options .threads } "
923
929
924
930
if model .options .solver_method is not None :
0 commit comments