[Clp] Saving an MPS file from an object of class ClpSimplex

Robin Whittle rw at firstpr.com.au
Thu May 5 02:42:35 EDT 2016


Following a tip from John Forrest on 2016-05-01  ("Solver seems to work
..."):

> First the easy part - use writeMps(char * name,2); to export mps
> file.  The 2 is a format and means that the values are written
> exactly (in hex).

I figured out how to write an MPS file from my model object "iLP", which
is of class ClpSimplex.  I am using CLP 1.16.9, as described in the
just-mentioned thread.

writeMps() is a member function of class ClpModel, but not of class
ClpSimplex.  The latter inherits from the former, but does not gain this
function.

class ClpSimplex does have a readMps member function, which calls the
same-named function from class ClpSimplex.  So I copied this pattern and
created a member function writeMps() for class ClpSimplex in the same way.

The new lines for ClpSimplex.cpp and ClpSimplex.hpp follow the lines for
writeMps().  Normally my comment lines start at column 49 and go to
column 104, but here I have moved them to the left.


/// ClpSimplex.hpp

            // For the ClpSimplex implementation of writeMPS().

     int writeMps(const char *filename,
                  int         formatType = 0,
                  int         numberAcross = 2,
                  double      objSense = 0.0
                 ) const ;

///


/// ClpSimplex.cpp

            // writeMPS(), which calls writeMps() of class ClpModel.
            //
            // This has only been tested by calling it with the
            // file name and "2" for the second argument.
            //
            // Write the problem in MPS format to the file specified
            // in the C-style string "filename".
            //
            // Row and column names may be null.
            //
            // formatType (default = 0) is:
            //
            //   0 - Normal.
            //   1 - Extra accuracy.
            //   3 - IEEE hex = full accuracy.
            //
            // numberAcross (default = 2) is passed through to
            // writeMps() in libCoinUtils CoinMpsIO.cpp/hpp, where
            // it is described as:
            //
            //     specifies whether 1 or 2 (default) values should
            //     be specified on every data line in the MPS file.
            //
            // objSense (default 0.0) is implemented in
            // ClpModel::writeMps where its value may cause the
            // coefficients of the objective function to be negated.

int ClpSimplex::writeMps(const char *filename,
                         int         formatType,
                         int         numberAcross,
                         double      objSense
                        ) const
{
    int status = ClpModel::writeMps(filename,
                                    formatType,
                                    numberAcross,
                                    objSense
                                   );
    return status;
}

///

I write the file, whose name is specified by a C++ string mpsFileName:

    int writeMpsStatus = iLP.writeMps(mpsFileName.c_str(), 2);

The resulting MPS file seems to be good, in that I can read it into an
old Windows clp.exe program from 2008:

  http://www.coin-or.org/download/binary/Clp/Clp-1.7.4-win64-icl9.0.zip

I have not yet compiled the 1.16.9 equivalent of this, which I
understand results from Clp/src/unitTest.cpp.  The MPS file was read OK
by the executable I made from Clp/examples/minimum.cpp.

  Robin


More information about the Clp mailing list