@@ -443,7 +443,7 @@ def define_arguments(argparser):
443443 argparser .add_argument ("--solver-io" , default = None , help = "Method for Pyomo to use to communicate with solver" )
444444 # note: pyomo has a --solver-options option but it is not clear
445445 # whether that does the same thing as --solver-options-string so we don't reuse the same name.
446- argparser .add_argument ("--solver-options-string" , default = None ,
446+ argparser .add_argument ("--solver-options-string" , default = "" ,
447447 help = 'A quoted string of options to pass to the model solver. Each option must be of the form option=value. '
448448 '(e.g., --solver-options-string "mipgap=0.001 primalopt=\' \' advance=2 threads=1")' )
449449 argparser .add_argument ("--solver-method" , default = None , type = int ,
@@ -556,6 +556,12 @@ def define_arguments(argparser):
556556 " that all variables must be the same between the previous and current scenario."
557557 )
558558
559+ argparser .add_argument (
560+ "--gurobi-make-mps" , default = False , action = "store_true" ,
561+ help = "Instead of solving just output a Gurobi .mps file that can be used for debugging numerical properties."
562+ " See https://github.com/staadecker/lp-analyzer/ for details."
563+ )
564+
559565
560566def add_recommended_args (argparser ):
561567 """
@@ -709,25 +715,23 @@ def solve(model):
709715 # Note previously solver was saved in model however this is very memory inefficient.
710716 solver = SolverFactory (model .options .solver , solver_io = model .options .solver_io )
711717
712- # If this option is enabled, gurobi will output an IIS to outputs\iis.ilp.
713- if model .options .gurobi_find_iis :
714- # Enable symbolic labels since otherwise we can't debug the .ilp file.
715- model .options .symbolic_solver_labels = True
718+ if model .options .gurobi_find_iis and model .options .gurobi_make_mps :
719+ raise Exception ("Can't use --gurobi-find-iis with --gurobi-make-mps." )
716720
717- # If no string is passed make the string empty so we can add to it
718- if model . options . solver_options_string is None :
719- model .options .solver_options_string = ""
721+ if model . options . gurobi_find_iis or model . options . gurobi_make_mps :
722+ # If we are outputting a file we want to enable symbolic labels to help debugging
723+ model .options .symbolic_solver_labels = True
720724
725+ # If this option is enabled, gurobi will output an IIS to outputs\iis.ilp.
726+ if model .options .gurobi_find_iis :
721727 # Add to the solver options 'ResultFile=iis.ilp'
722728 # https://stackoverflow.com/a/51994135/5864903
723- iis_file_path = os .path .join (model .options .outputs_dir , "iis.ilp" )
724- model .options .solver_options_string += " ResultFile={}" .format (iis_file_path )
729+ model .options .solver_options_string += " ResultFile=iis.ilp"
730+ if model .options .gurobi_make_mps :
731+ # Output the input file and set time limit to zero to ensure it doesn't actually solve
732+ model .options .solver_options_string += f" ResultFile=problem.mps TimeLimit=0"
725733
726734 if model .options .threads :
727- # If no string is passed make the string empty so we can add to it
728- if model .options .solver_options_string is None :
729- model .options .solver_options_string = ""
730-
731735 model .options .solver_options_string += f" Threads={ model .options .threads } "
732736
733737 if model .options .solver_method is not None :
0 commit comments