/home/coin/SVN-release/CoinAll-1.1.0/Bcp/src/include/BCP_matrix.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef _BCP_MATRIX_H
00004 #define _BCP_MATRIX_H
00005 
00006 // This file is fully docified.
00007 
00008 // #include <cmath>
00009 // #include <cfloat>
00010 
00011 #include "CoinPackedVector.hpp"
00012 #include "CoinPackedMatrix.hpp"
00013 
00014 #include "BCP_math.hpp"
00015 #include "BCP_vector.hpp"
00016 
00017 //#############################################################################
00018 
00019 class BCP_buffer;
00020 
00021 //#############################################################################
00022 
00026 class BCP_col : public CoinPackedVector {
00027    
00028 protected:
00032    double _Objective;
00034    double _LowerBound;
00036    double _UpperBound;
00038    //--------------------------------------------------------------------------
00039 
00040 public:
00044    inline double Objective()  const { return _Objective; }
00046    inline double LowerBound() const { return _LowerBound; }
00048    inline double UpperBound() const { return _UpperBound; }
00050    //--------------------------------------------------------------------------
00051 
00055    inline void Objective(const double obj) { _Objective = obj; }
00057    inline void LowerBound(const double lb) { _LowerBound = lb; }
00059    inline void UpperBound(const double ub) { _UpperBound = ub; }
00060 
00062    BCP_col& operator=(const BCP_col& x) {
00063       CoinPackedVector::operator=(x);
00064       _Objective = x.Objective();
00065       _LowerBound = x.LowerBound();
00066       _UpperBound = x.UpperBound();
00067       return *this;
00068    }
00072    inline void
00073    assign(const int size, int*& ElementIndices, double*& ElementValues,
00074           const double Obj, const double LB, const double UB) {
00075       CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
00076                                     false /* no test for duplicate index */);
00077       _Objective = Obj;
00078       _LowerBound = LB;
00079       _UpperBound = UB;
00080    }
00082    inline void
00083    copy(const int size, const int* ElementIndices, const double* ElementValues,
00084         const double Obj, const double LB, const double UB) {
00085       CoinPackedVector::setVector(size, ElementIndices, ElementValues,
00086                                  false /* no test for duplicate index */);
00087       _Objective = Obj;
00088       _LowerBound = LB;
00089       _UpperBound = UB;
00090    }
00094    inline void
00095    copy(BCP_vec<int>::const_iterator firstind,
00096         BCP_vec<int>::const_iterator lastind,
00097         BCP_vec<double>::const_iterator firstval,
00098         BCP_vec<double>::const_iterator lastval,
00099         const double Obj, const double LB, const double UB) {
00100       CoinPackedVector::setVector(lastind - firstind, firstind, firstval,
00101                                  false /* no test for duplicate index */);
00102       _Objective = Obj;
00103       _LowerBound = LB;
00104       _UpperBound = UB;
00105    }
00107    //--------------------------------------------------------------------------
00108 
00113    BCP_col() : CoinPackedVector(false /* no test for duplicate index */),
00114                _Objective(0), _LowerBound(0.0), _UpperBound(BCP_DBL_MAX) {}
00116    BCP_col(const BCP_col& x) :
00117       CoinPackedVector(x), _Objective(x.Objective()),
00118       _LowerBound(x.LowerBound()), _UpperBound(x.UpperBound()) {}
00121    BCP_col(BCP_vec<int>::const_iterator firstind,
00122            BCP_vec<int>::const_iterator lastind,
00123            BCP_vec<double>::const_iterator firstval,
00124            BCP_vec<double>::const_iterator lastval,
00125            const double Obj, const double LB, const double UB) :
00126       CoinPackedVector(lastind - firstind, firstind, firstval,
00127                       false /* no test for duplicate index */),
00128       _Objective(Obj), _LowerBound(LB), _UpperBound(UB) {}
00131    BCP_col(const int size, int*& ElementIndices, double*& ElementValues,
00132            const double Obj, const double LB, const double UB) :
00133       CoinPackedVector(), _Objective(Obj), _LowerBound(LB), _UpperBound(UB) {
00134       CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
00135                                     false /* no test for duplicate index */);
00136    }
00137    BCP_col(const CoinPackedVectorBase& vec,
00138            const double Obj, const double LB, const double UB) :
00139       CoinPackedVector(vec.getNumElements(),
00140                       vec.getIndices(), vec.getElements()),
00141       _Objective(Obj), _LowerBound(LB), _UpperBound(UB) {}
00143    ~BCP_col() {}
00145 };
00146 
00147 //#############################################################################
00148 
00152 class BCP_row : public CoinPackedVector {
00153 protected:
00157    double _LowerBound;
00159    double _UpperBound;
00161    //--------------------------------------------------------------------------
00162 
00163 public:
00167    inline double LowerBound() const { return _LowerBound; }
00169    inline double UpperBound() const { return _UpperBound; }
00171    //--------------------------------------------------------------------------
00172 
00176    inline void LowerBound(double lb) { _LowerBound = lb; }
00178    inline void UpperBound(double ub) { _UpperBound = ub; }
00179 
00181    BCP_row& operator=(const BCP_row& x) {
00182       CoinPackedVector::operator=(x);
00183       _LowerBound = x.LowerBound();
00184       _UpperBound = x.UpperBound();
00185       return *this;
00186    }
00187 
00190    void
00191    assign(const int size, int*& ElementIndices, double*& ElementValues,
00192           const double LB, const double UB) {
00193       CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
00194                                     false /* no test for duplicate index */);
00195       _LowerBound = LB;
00196       _UpperBound = UB;
00197    }
00199    void
00200    copy(const int size, const int* ElementIndices, const double* ElementValues,
00201         const double LB, const double UB) {
00202       CoinPackedVector::setVector(size, ElementIndices, ElementValues,
00203                                  false /* no test for duplicate index */);
00204       _LowerBound = LB;
00205       _UpperBound = UB;
00206    }
00210    void
00211    copy(BCP_vec<int>::const_iterator firstind,
00212         BCP_vec<int>::const_iterator lastind,
00213         BCP_vec<double>::const_iterator firstval,
00214         BCP_vec<double>::const_iterator lastval,
00215         const double LB, const double UB) {
00216       CoinPackedVector::setVector(lastind - firstind, firstind, firstval,
00217                                  false /* no test for duplicate index */);
00218       _LowerBound = LB;
00219       _UpperBound = UB;
00220    }
00222    //--------------------------------------------------------------------------
00223 
00228    BCP_row() : CoinPackedVector(false /* no test for duplicate index */),
00229                _LowerBound(-BCP_DBL_MAX), _UpperBound(BCP_DBL_MAX) {}
00231    BCP_row(const BCP_row& x) :
00232       CoinPackedVector(x),
00233       _LowerBound(x.LowerBound()), _UpperBound(x.UpperBound()) {}
00236    BCP_row(BCP_vec<int>::const_iterator firstind,
00237            BCP_vec<int>::const_iterator lastind,
00238            BCP_vec<double>::const_iterator firstval,
00239            BCP_vec<double>::const_iterator lastval,
00240            const double LB, const double UB) :
00241       CoinPackedVector(lastind - firstind, firstind, firstval,
00242                       false /* no test for duplicate index */),
00243       _LowerBound(LB), _UpperBound(UB) {}
00246    BCP_row(const int size, int*& ElementIndices, double*& ElementValues,
00247            const double LB, const double UB) :
00248       CoinPackedVector(), _LowerBound(LB), _UpperBound(UB) {
00249       CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
00250                                     false /* no test for duplicate index */);
00251    }
00252    BCP_row(const CoinPackedVectorBase& vec, const double LB, const double UB) :
00253       CoinPackedVector(vec.getNumElements(),
00254                       vec.getIndices(), vec.getElements()),
00255       _LowerBound(LB), _UpperBound(UB) {}
00257    ~BCP_row() {}
00259 };
00260 
00261 //#############################################################################
00262 //#############################################################################
00263 
00267 class BCP_lp_relax : public CoinPackedMatrix {
00268 private:
00272    BCP_vec<double> _Objective;
00274    BCP_vec<double> _ColLowerBound;
00276    BCP_vec<double> _ColUpperBound;
00278    BCP_vec<double> _RowLowerBound;
00280    BCP_vec<double> _RowUpperBound;
00282    //--------------------------------------------------------------------------
00283 
00284 public:
00288    inline size_t colnum() const       { return _ColLowerBound.size(); }
00290    inline size_t rownum() const       { return _RowLowerBound.size(); }
00292    inline const BCP_vec<double>& Objective()     const {return _Objective;}
00294    inline const BCP_vec<double>& ColLowerBound() const {return _ColLowerBound;}
00296    inline const BCP_vec<double>& ColUpperBound() const {return _ColUpperBound;}
00298    inline const BCP_vec<double>& RowLowerBound() const {return _RowLowerBound;}
00300    inline const BCP_vec<double>& RowUpperBound() const {return _RowUpperBound;}
00302    //--------------------------------------------------------------------------
00303 
00307    BCP_lp_relax& operator=(const BCP_lp_relax& mat);
00313    void reserve(const int MaxColNum, const int MaxRowNum,
00314                 const int MaxNonzeros);
00316    void clear();
00318    void copyOf(const CoinPackedMatrix& m,
00319                const double* OBJ, const double* CLB, const double* CUB,
00320                const double* RLB, const double* RUB);
00322    void assign(CoinPackedMatrix& m,
00323                double*& OBJ, double*& CLB, double*& CUB,
00324                double*& RLB, double*& RUB);
00326    //--------------------------------------------------------------------------
00327 
00330 #if 0
00331 
00333    void add_col_set(const BCP_col_set& Cols);
00336    void add_row_set(const BCP_row_set& Rows);
00337 #endif
00338 
00340    void erase_col_set(const BCP_vec<int>& pos);
00343    void erase_row_set(const BCP_vec<int>& pos);
00345    //--------------------------------------------------------------------------
00346 #if 0
00347 
00351    double dot_product_col(const int index, const BCP_vec<double>& col) const;
00354    double dot_product_row(const int index, const BCP_vec<double>& row) const;
00357    double dot_product_col(const int index, const double* col) const;
00360    double dot_product_row(const int index, const double* row) const;
00362 #endif
00363    //--------------------------------------------------------------------------
00364 
00368    void pack(BCP_buffer& buf) const;
00370    void unpack(BCP_buffer& buf);
00372    //--------------------------------------------------------------------------
00373 
00377    BCP_lp_relax(const bool colordered = true) :
00378       CoinPackedMatrix(colordered, 0, 0, 0, NULL, NULL, NULL, NULL),
00379       _Objective(), _ColLowerBound(), _ColUpperBound(),
00380       _RowLowerBound(), _RowUpperBound() {}
00381 
00383    BCP_lp_relax(const BCP_lp_relax& mat);
00384 
00389    BCP_lp_relax(BCP_vec<BCP_row*>& rows,
00390                 BCP_vec<double>& CLB, BCP_vec<double>& CUB,
00391                 BCP_vec<double>& OBJ);
00392 
00397    BCP_lp_relax(BCP_vec<BCP_row*>& rows,
00398                 BCP_vec<double>& CLB, BCP_vec<double>& CUB,
00399                 BCP_vec<double>& OBJ,
00400                 double extra_gap, double extra_major);
00401 
00406    BCP_lp_relax(BCP_vec<BCP_col*>& cols,
00407                 BCP_vec<double>& RLB, BCP_vec<double>& RUB);
00408 
00413    BCP_lp_relax(BCP_vec<BCP_col*>& cols,
00414                 BCP_vec<double>& RLB, BCP_vec<double>& RUB,
00415                 double extra_gap, double extra_major);
00416 
00419    BCP_lp_relax(const bool colordered,
00420                 const BCP_vec<int>& VB, const BCP_vec<int>& EI,
00421                 const BCP_vec<double>& EV, const BCP_vec<double>& OBJ,
00422                 const BCP_vec<double>& CLB, const BCP_vec<double>& CUB,
00423                 const BCP_vec<double>& RLB, const BCP_vec<double>& RUB);
00428    BCP_lp_relax(const bool colordered,
00429                 const int rownum, const int colnum, const int nznum,
00430                 int*& VB, int*& EI, double*& EV,
00431                 double*& OBJ, double*& CLB, double*& CUB,
00432                 double*& RLB, double*& RUB);
00433 
00435    ~BCP_lp_relax() {}
00437 private:
00440 
00441   void BCP_createColumnOrderedMatrix(BCP_vec<BCP_row*>& rows,
00442                                      BCP_vec<double>& CLB,
00443                                      BCP_vec<double>& CUB,
00444                                      BCP_vec<double>& OBJ);
00446   void BCP_createRowOrderedMatrix(BCP_vec<BCP_col*>& cols,
00447                                   BCP_vec<double>& RLB,
00448                                   BCP_vec<double>& RUB);
00450 };
00451 
00452 #endif

Generated on Sun Nov 14 14:06:29 2010 for Coin-All by  doxygen 1.4.7