diff -r 473c71baff72 -r 490d89913a17 lemon/lp_base.h --- a/lemon/lp_base.h Thu Feb 28 23:45:39 2013 +0100 +++ b/lemon/lp_base.h Mon Jul 15 08:33:08 2013 +0200 @@ -1007,6 +1007,36 @@ public: + ///\e + class UnsupportedFormatError : public Exception + { + std::string _format; + mutable std::string _what; + public: + explicit UnsupportedFormatError(std::string format) throw() + : _format(format) { } + virtual ~UnsupportedFormatError() throw() {} + virtual const char* what() const throw() { + try { + _what.clear(); + std::ostringstream oss; + oss << "lemon::UnsupportedFormatError: " << _format; + _what = oss.str(); + } + catch (...) {} + if (!_what.empty()) return _what.c_str(); + else return "lemon::UnsupportedFormatError"; + } + }; + + protected: + virtual void _write(std::string, std::string format) const + { + throw UnsupportedFormatError(format); + } + + public: + /// Virtual destructor virtual ~LpBase() {} @@ -1555,12 +1585,27 @@ ///Set the sense to maximization void min() { _setSense(MIN); } - ///Clears the problem + ///Clear the problem void clear() { _clear(); rows.clear(); cols.clear(); } - /// Sets the message level of the solver + /// Set the message level of the solver void messageLevel(MessageLevel level) { _messageLevel(level); } + /// Write the problem to a file in the given format + + /// This function writes the problem to a file in the given format. + /// Different solver backends may support different formats. + /// Trying to write in an unsupported format will trigger + /// \ref UnsupportedFormatError. For the supported formats, + /// visit the documentation of the base class of the related backends + /// (\ref CplexBase, \ref GlpkBase etc.) + /// \param file The file path + /// \param format The output file format. + void write(std::string file, std::string format = "MPS") const + { + _write(file.c_str(),format.c_str()); + } + ///@} };