COIN-OR::LEMON - Graph Library

Changeset 1063:1782aa72495a in lemon-main


Ignore:
Timestamp:
07/20/12 17:09:01 (7 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

Add file export funcionality to LpBase? (#457)

Location:
lemon
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • lemon/cplex.cc

    r1016 r1063  
    492492                   _message_enabled ? CPX_ON : CPX_OFF);
    493493  }
     494
     495  void CplexBase::_write(std::string file, std::string format) const
     496  {
     497    if(format == "MPS" || format == "LP")
     498      CPXwriteprob(cplexEnv(), cplexLp(), file.c_str(), format.c_str());
     499    else if(format == "SOL")
     500      CPXsolwrite(cplexEnv(), cplexLp(), file.c_str());
     501    else throw UnsupportedFormatError(format);
     502  }
     503
     504
    494505
    495506  // CplexLp members
  • lemon/cplex.h

    r746 r1063  
    151151    bool _message_enabled;
    152152
     153    void _write(std::string file, std::string format) const;
     154
    153155  public:
    154156
     
    171173    const cpxlp* cplexLp() const { return _prob; }
    172174
     175#ifdef DOXYGEN
     176    /// Write the problem or the solution to a file in the given format
     177
     178    /// This function writes the problem or the solution
     179    /// to a file in the given format.
     180    /// Trying to write in an unsupported format will trigger
     181    /// \ref UnsupportedFormatError.
     182    /// \param file The file path
     183    /// \param format The output file format.
     184    /// Supportted formats are "MPS", "LP" and "SOL".
     185    void write(std::string file, std::string format = "MPS") const {}
     186#endif
     187
    173188  };
    174189
  • lemon/glpk.cc

    r989 r1063  
    581581      break;
    582582    }
     583  }
     584
     585  void GlpkBase::_write(std::string file, std::string format) const
     586  {
     587    if(format == "MPS")
     588      glp_write_mps(lp, GLP_MPS_FILE, 0, file.c_str());
     589    else if(format == "LP")
     590      glp_write_lp(lp, 0, file.c_str());
     591    else throw UnsupportedFormatError(format);
    583592  }
    584593
     
    9991008  const char* GlpkMip::_solverName() const { return "GlpkMip"; }
    10001009
     1010
     1011
    10011012} //END OF NAMESPACE LEMON
  • lemon/glpk.h

    r877 r1063  
    116116    virtual void _messageLevel(MessageLevel level);
    117117
     118    virtual void _write(std::string file, std::string format) const;
     119
    118120  private:
    119121
     
    145147    int lpxCol(Col c) const { return cols(id(c)); }
    146148
     149#ifdef DOXYGEN
     150    /// Write the problem or the solution to a file in the given format
     151   
     152    /// This function writes the problem or the solution
     153    /// to a file in the given format.
     154    /// Trying to write in an unsupported format will trigger
     155    /// \ref UnsupportedFormatError.
     156    /// \param file The file path
     157    /// \param format The output file format.
     158    /// Supportted formats are "MPS" and "LP".
     159    void write(std::string file, std::string format = "MPS") const {}
     160#endif
     161
    147162  };
    148163
  • lemon/lp_base.h

    r989 r1063  
    10081008  public:
    10091009
     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
    10101040    /// Virtual destructor
    10111041    virtual ~LpBase() {}
     
    15561586    void min() { _setSense(MIN); }
    15571587
    1558     ///Clears the problem
     1588    ///Clear the problem
    15591589    void clear() { _clear(); rows.clear(); cols.clear(); }
    15601590
    1561     /// Sets the message level of the solver
     1591    /// Set the message level of the solver
    15621592    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    }
    15631608
    15641609    ///@}
  • lemon/lp_skeleton.cc

    r877 r1063  
    9292  void SkeletonSolverBase::_messageLevel(MessageLevel) {}
    9393
     94  void SkeletonSolverBase::_write(std::string, std::string) const {}
     95
    9496  LpSkeleton::SolveExitStatus LpSkeleton::_solve() { return SOLVED; }
    9597
  • lemon/lp_skeleton.h

    r877 r1063  
    145145    ///\e
    146146    virtual void _messageLevel(MessageLevel);
     147
     148    ///\e
     149    virtual void _write(std::string file, std::string format) const;
     150
    147151  };
    148152
     
    223227    ///\e
    224228    virtual const char* _solverName() const;
     229
    225230  };
    226231
Note: See TracChangeset for help on using the changeset viewer.