@@ -505,7 +505,7 @@ def define_arguments(argparser):
505505 argparser .add_argument ("--solver-io" , default = None , help = "Method for Pyomo to use to communicate with solver" )
506506 # note: pyomo has a --solver-options option but it is not clear
507507 # whether that does the same thing as --solver-options-string so we don't reuse the same name.
508- argparser .add_argument ("--solver-options-string" , default = None ,
508+ argparser .add_argument ("--solver-options-string" , default = "" ,
509509 help = 'A quoted string of options to pass to the model solver. Each option must be of the form option=value. '
510510 '(e.g., --solver-options-string "mipgap=0.001 primalopt=\' \' advance=2 threads=1")' )
511511 argparser .add_argument ("--keepfiles" , action = 'store_true' , default = None ,
@@ -604,6 +604,12 @@ def define_arguments(argparser):
604604 help = "Path to folder of directory to use for warm start"
605605 )
606606
607+ argparser .add_argument (
608+ "--gurobi-make-mps" , default = False , action = "store_true" ,
609+ help = "Instead of solving just output a Gurobi .mps file that can be used for debugging numerical properties."
610+ " See https://github.com/staadecker/lp-analyzer/ for details."
611+ )
612+
607613
608614def add_recommended_args (argparser ):
609615 """
@@ -746,25 +752,23 @@ def solve(model):
746752 # Note previously solver was saved in model however this is very memory inefficient.
747753 solver = SolverFactory (model .options .solver , solver_io = model .options .solver_io )
748754
749- # If this option is enabled, gurobi will output an IIS to outputs\iis.ilp.
750- if model .options .gurobi_find_iis :
751- # Enable symbolic labels since otherwise we can't debug the .ilp file.
752- model .options .symbolic_solver_labels = True
755+ if model .options .gurobi_find_iis and model .options .gurobi_make_mps :
756+ raise Exception ("Can't use --gurobi-find-iis with --gurobi-make-mps." )
753757
754- # If no string is passed make the string empty so we can add to it
755- if model . options . solver_options_string is None :
756- model .options .solver_options_string = ""
758+ if model . options . gurobi_find_iis or model . options . gurobi_make_mps :
759+ # If we are outputting a file we want to enable symbolic labels to help debugging
760+ model .options .symbolic_solver_labels = True
757761
762+ # If this option is enabled, gurobi will output an IIS to outputs\iis.ilp.
763+ if model .options .gurobi_find_iis :
758764 # Add to the solver options 'ResultFile=iis.ilp'
759765 # https://stackoverflow.com/a/51994135/5864903
760- iis_file_path = os .path .join (model .options .outputs_dir , "iis.ilp" )
761- model .options .solver_options_string += " ResultFile={}" .format (iis_file_path )
766+ model .options .solver_options_string += " ResultFile=iis.ilp"
767+ if model .options .gurobi_make_mps :
768+ # Output the input file and set time limit to zero to ensure it doesn't actually solve
769+ model .options .solver_options_string += f" ResultFile=problem.mps TimeLimit=0"
762770
763771 if model .options .threads :
764- # If no string is passed make the string empty so we can add to it
765- if model .options .solver_options_string is None :
766- model .options .solver_options_string = ""
767-
768772 model .options .solver_options_string += f" Threads={ model .options .threads } "
769773
770774 solver_manager = SolverManagerFactory (model .options .solver_manager )
0 commit comments