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