ampl / mp

An open-source library for mathematical programming
https://mp.ampl.com
Other
229 stars 42 forks source link

Issues with writeprob in Gurobi #218

Closed 4er4er4er closed 1 year ago

4er4er4er commented 1 year ago

Several cases of the Gurobi writeprob option are handled incorrectly by the MP interface. The following examples also show the ASL results, which are as intended.

  1. MP rejects quotes around a filename, with an "Unknown file type" error:
    
    ampl: model multmip3.mod;
    ampl: data multmip3.dat;
    ampl: option gurobi_options 'writeprob="..\multmip3.lp"';

ampl: option solver gurobiasl; ampl: solve; Gurobi 10.0.1: writeprob="..\multmip3.lp" Gurobi 10.0.1: optimal solution; objective 235625 282 simplex iterations 32 branch-and-cut nodes plus 34 simplex iterations for intbasis

ampl: option solver gurobi; ampl: solve; Gurobi 10.0.1: tech:exportfile=..\multmip3.lp" Unknown file type for file '..\multmip3.lp"' ampl:

2. MP fails to write a Gurobi `.sol` file:

ampl: option gurobi_options 'writeprob=..\multmip3.sol';

ampl: option solver gurobiasl; ampl: solve; Gurobi 10.0.1: writeprob=..\multmip3.sol Gurobi 10.0.1: optimal solution; objective 235625 282 simplex iterations 32 branch-and-cut nodes plus 34 simplex iterations for intbasis

ampl: option solver gurobi; ampl: solve; Gurobi 10.0.1: tech:exportfile=..\multmip3.sol Unable to retrieve attribute 'X' ampl:

3. An LP file written with `option gurobi_auxfiles rc;` contains the AMPL names for variables, but generic names for constraints. Consider the following example:

ampl: option gurobi_options 'writeprob=..\multmip3.lp';

ampl: option solver gurobiasl; ampl: option gurobiasl_auxfiles rc; ampl: solve; Gurobi 10.0.1: writeprob=..\multmip3asl.lp Gurobi 10.0.1: optimal solution; objective 235625 282 simplex iterations 32 branch-and-cut nodes plus 34 simplex iterations for intbasis

ampl: option solver gurobi; ampl: option gurobi_auxfiles rc; ampl: solve; Gurobi 10.0.1: tech:exportfile=..\multmip3.lp Gurobi 10.0.1: optimal solution; objective 235625 108 simplex iterations 1 branching nodes ampl:

File multmip3asl.lp contains, for instance,

Supply['PITT','plate']: Trans['PITT','FRA','plate']

glebbelov commented 1 year ago

Task 2: added option writesol for solution/basis/IIS etc. Note that writeprob existed as synonym for tech:exportfile (which is now tech:writemodel.) All file writing options in Gurobi are now:

tech:writegraph (writegraph, exportgraph)
      File to export conversion graph. Format: JSON Lines.

tech:writemodel (writeprob, writemodel)
      Specifies the name of a file where to export the model before solving
      it. This file name can have extension ".lp[.7zip]", ".mps", etc. Default
      = "" (don't export the model).

tech:writemodelonly (justwriteprob, justwritemodel)
      Specifies the name of a file where to export the model, do not solve it.
      This file name can have extension ".dlp", ".mps", etc. Default = ""
      (don't export the model).

tech:writepresolved (writepresolved, writepresolvedmodel, exportpresolvedfile)
      Specifies the name of a file where to export the presolved model before
      solving it. This file name can have extension ".lp", ".mps", etc.
      Default = "" (don't export the model).

tech:writesolution (writesol, writesolution)
      Specifies the name of a file where to export the solution or other
      result file. This file name can have extension ".sol[.tar.gz]", ".json",
      ".bas", ".ilp", etc. Default = "" (don't export results).

Task 3 was solved in #209.

glebbelov commented 1 year ago

For compatibility with ASL, allow ".sol", ".mst", ".bas" etc with the writeprob option. Their writing is delayed to after solving. However this is not documented.

Moreover now allowing repeated use of writeprob and writesol; tech:exportfile restored as synonym. Current docu:

tech:writemodel (writeprob, writemodel, tech:exportfile)
      Specifies files where to export the model before solving (repeat the
      option for several files.) File name extensions can be ".lp[.7z]",
      ".mps", etc.

tech:writemodelonly (justwriteprob, justwritemodel)
      Specifies files where to export the model, no solving (option can be
      repeated.) File extensions can be ".dlp", ".mps", etc.

tech:writepresolved (writepresolved, writepresolvedmodel, exportpresolvedfile)
      Specifies the name of a file where to export the presolved model before
      solving it. This file name can have extension ".lp", ".mps", etc.
      Default = "" (don't export the model).

tech:writesolution (writesol, writesolution)
      Specifies the names of files where to export the solution and/or other
      result files in solver's native formats. Option can be repeated. File
      name extensions can be ".sol[.tar.gz]", ".json", ".bas", ".ilp", etc.

To be released next week, unless any remarks.

glebbelov commented 1 year ago

Released, also works in Highs and Xpress.