1005 |
1005 |
1006 LpBase() : rows(), cols(), obj_const_comp(0) {} |
1006 LpBase() : rows(), cols(), obj_const_comp(0) {} |
1007 |
1007 |
1008 public: |
1008 public: |
1009 |
1009 |
|
1010 ///\e |
|
1011 class UnsupportedFormatError : public Exception |
|
1012 { |
|
1013 std::string _format; |
|
1014 mutable std::string _what; |
|
1015 public: |
|
1016 explicit UnsupportedFormatError(std::string format) throw() |
|
1017 : _format(format) { } |
|
1018 virtual ~UnsupportedFormatError() throw() {} |
|
1019 virtual const char* what() const throw() { |
|
1020 try { |
|
1021 _what.clear(); |
|
1022 std::ostringstream oss; |
|
1023 oss << "lemon::UnsupportedFormatError: " << _format; |
|
1024 _what = oss.str(); |
|
1025 } |
|
1026 catch (...) {} |
|
1027 if (!_what.empty()) return _what.c_str(); |
|
1028 else return "lemon::UnsupportedFormatError"; |
|
1029 } |
|
1030 }; |
|
1031 |
|
1032 protected: |
|
1033 virtual void _write(std::string, std::string format) const |
|
1034 { |
|
1035 throw UnsupportedFormatError(format); |
|
1036 } |
|
1037 |
|
1038 public: |
|
1039 |
1010 /// Virtual destructor |
1040 /// Virtual destructor |
1011 virtual ~LpBase() {} |
1041 virtual ~LpBase() {} |
1012 |
1042 |
1013 ///Gives back the name of the solver. |
1043 ///Gives back the name of the solver. |
1014 const char* solverName() const {return _solverName();} |
1044 const char* solverName() const {return _solverName();} |
1553 void max() { _setSense(MAX); } |
1583 void max() { _setSense(MAX); } |
1554 |
1584 |
1555 ///Set the sense to maximization |
1585 ///Set the sense to maximization |
1556 void min() { _setSense(MIN); } |
1586 void min() { _setSense(MIN); } |
1557 |
1587 |
1558 ///Clears the problem |
1588 ///Clear the problem |
1559 void clear() { _clear(); rows.clear(); cols.clear(); } |
1589 void clear() { _clear(); rows.clear(); cols.clear(); } |
1560 |
1590 |
1561 /// Sets the message level of the solver |
1591 /// Set the message level of the solver |
1562 void messageLevel(MessageLevel level) { _messageLevel(level); } |
1592 void messageLevel(MessageLevel level) { _messageLevel(level); } |
|
1593 |
|
1594 /// Write the problem to a file in the given format |
|
1595 |
|
1596 /// This function writes the problem to a file in the given format. |
|
1597 /// Different solver backends may support different formats. |
|
1598 /// Trying to write in an unsupported format will trigger |
|
1599 /// \ref UnsupportedFormatError. For the supported formats, |
|
1600 /// visit the documentation of the base class of the related backends |
|
1601 /// (\ref CplexBase, \ref GlpkBase etc.) |
|
1602 /// \param file The file path |
|
1603 /// \param format The output file format. |
|
1604 void write(std::string file, std::string format = "MPS") const |
|
1605 { |
|
1606 _write(file.c_str(),format.c_str()); |
|
1607 } |
1563 |
1608 |
1564 ///@} |
1609 ///@} |
1565 |
1610 |
1566 }; |
1611 }; |
1567 |
1612 |