Petter T
Petter T

Reputation: 3627

Getting results from Cplex presolve in C#

Is there a way to obtain the results of the presolve analysis that Cplex does when starting to solve an LP? In particular, I am looking for information about redundant rows. If possible, it would be useful to run only the presolve, without solving the LP. I am using Cplex 12.5 from a C# application.

Upvotes: 1

Views: 489

Answers (1)

David Nehme
David Nehme

Reputation: 21572

You can generate the cplex presolved model by using the ExportModelon the Cplex object with the a file extension ".pre". That will cause presolve to run and make cplex write the presolved model to a file. The format of the output is a "sav" format, which is a lossless, but not human-readable. You can convert it to a readable ".lp" format, but importing it back into another fresh Cplex object, then exporting that model as a .lp file.

cplex.ExportModel("myModel.pre");

// convert to .lp file  
// Could also do this with interactive cplex
Cplex lp_converter = new Cplex();
lp_converter.ImportModel("myModel.pre");
lp_converter.ExportModel("myModelPresolved.lp");

Then you can read the presolved lp file and get an idea of what cplex does to your model at that stage. You will likely be surprised by the extent of what cplex does and you may even have a hard time reconciling the presolved model with your original. You can experiment with changing the extent of presolve by setting parameters. For example, setting the parameter PreLinear to 1 will likely make the model more recognizable.

Upvotes: 3

Related Questions