00001
00002
00003 #ifndef _BCP_MATRIX_H
00004 #define _BCP_MATRIX_H
00005
00006
00007
00008 #include <cmath>
00009 #include <cfloat>
00010
00011 #include "CoinPackedVector.hpp"
00012 #include "CoinPackedMatrix.hpp"
00013
00014 #include "BCP_vector.hpp"
00015
00016
00017
00018 class BCP_buffer;
00019
00020
00021
00025 class BCP_col : public CoinPackedVector {
00026
00027 protected:
00031 double _Objective;
00033 double _LowerBound;
00035 double _UpperBound;
00037
00038
00039 public:
00043 inline double Objective() const { return _Objective; }
00045 inline double LowerBound() const { return _LowerBound; }
00047 inline double UpperBound() const { return _UpperBound; }
00049
00050
00054 inline void Objective(const double obj) { _Objective = obj; }
00056 inline void LowerBound(const double lb) { _LowerBound = lb; }
00058 inline void UpperBound(const double ub) { _UpperBound = ub; }
00059
00061 BCP_col& operator=(const BCP_col& x) {
00062 CoinPackedVector::operator=(x);
00063 _Objective = x.Objective();
00064 _LowerBound = x.LowerBound();
00065 _UpperBound = x.UpperBound();
00066 return *this;
00067 }
00071 inline void
00072 assign(const int size, int*& ElementIndices, double*& ElementValues,
00073 const double Obj, const double LB, const double UB) {
00074 CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
00075 false );
00076 _Objective = Obj;
00077 _LowerBound = LB;
00078 _UpperBound = UB;
00079 }
00081 inline void
00082 copy(const int size, const int* ElementIndices, const double* ElementValues,
00083 const double Obj, const double LB, const double UB) {
00084 CoinPackedVector::setVector(size, ElementIndices, ElementValues,
00085 false );
00086 _Objective = Obj;
00087 _LowerBound = LB;
00088 _UpperBound = UB;
00089 }
00093 inline void
00094 copy(BCP_vec<int>::const_iterator firstind,
00095 BCP_vec<int>::const_iterator lastind,
00096 BCP_vec<double>::const_iterator firstval,
00097 BCP_vec<double>::const_iterator lastval,
00098 const double Obj, const double LB, const double UB) {
00099 CoinPackedVector::setVector(lastind - firstind, firstind, firstval,
00100 false );
00101 _Objective = Obj;
00102 _LowerBound = LB;
00103 _UpperBound = UB;
00104 }
00106
00107
00112 BCP_col() : CoinPackedVector(false ),
00113 _Objective(0), _LowerBound(0.0), _UpperBound(1e31) {}
00115 BCP_col(const BCP_col& x) :
00116 CoinPackedVector(x), _Objective(x.Objective()),
00117 _LowerBound(x.LowerBound()), _UpperBound(x.UpperBound()) {}
00120 BCP_col(BCP_vec<int>::const_iterator firstind,
00121 BCP_vec<int>::const_iterator lastind,
00122 BCP_vec<double>::const_iterator firstval,
00123 BCP_vec<double>::const_iterator lastval,
00124 const double Obj, const double LB, const double UB) :
00125 CoinPackedVector(lastind - firstind, firstind, firstval,
00126 false ),
00127 _Objective(Obj), _LowerBound(LB), _UpperBound(UB) {}
00130 BCP_col(const int size, int*& ElementIndices, double*& ElementValues,
00131 const double Obj, const double LB, const double UB) :
00132 CoinPackedVector(), _Objective(Obj), _LowerBound(LB), _UpperBound(UB) {
00133 CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
00134 false );
00135 }
00136 BCP_col(const CoinPackedVectorBase& vec,
00137 const double Obj, const double LB, const double UB) :
00138 CoinPackedVector(vec.getNumElements(),
00139 vec.getIndices(), vec.getElements()),
00140 _Objective(Obj), _LowerBound(LB), _UpperBound(UB) {}
00142 ~BCP_col() {}
00144 };
00145
00146
00147
00151 class BCP_row : public CoinPackedVector {
00152 protected:
00156 double _LowerBound;
00158 double _UpperBound;
00160
00161
00162 public:
00166 inline double LowerBound() const { return _LowerBound; }
00168 inline double UpperBound() const { return _UpperBound; }
00170
00171
00175 inline void LowerBound(double lb) { _LowerBound = lb; }
00177 inline void UpperBound(double ub) { _UpperBound = ub; }
00178
00180 BCP_row& operator=(const BCP_row& x) {
00181 CoinPackedVector::operator=(x);
00182 _LowerBound = x.LowerBound();
00183 _UpperBound = x.UpperBound();
00184 return *this;
00185 }
00186
00189 void
00190 assign(const int size, int*& ElementIndices, double*& ElementValues,
00191 const double LB, const double UB) {
00192 CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
00193 false );
00194 _LowerBound = LB;
00195 _UpperBound = UB;
00196 }
00198 void
00199 copy(const int size, const int* ElementIndices, const double* ElementValues,
00200 const double LB, const double UB) {
00201 CoinPackedVector::setVector(size, ElementIndices, ElementValues,
00202 false );
00203 _LowerBound = LB;
00204 _UpperBound = UB;
00205 }
00209 void
00210 copy(BCP_vec<int>::const_iterator firstind,
00211 BCP_vec<int>::const_iterator lastind,
00212 BCP_vec<double>::const_iterator firstval,
00213 BCP_vec<double>::const_iterator lastval,
00214 const double LB, const double UB) {
00215 CoinPackedVector::setVector(lastind - firstind, firstind, firstval,
00216 false );
00217 _LowerBound = LB;
00218 _UpperBound = UB;
00219 }
00221
00222
00227 BCP_row() : CoinPackedVector(false ),
00228 _LowerBound(-DBL_MAX), _UpperBound(DBL_MAX) {}
00230 BCP_row(const BCP_row& x) :
00231 CoinPackedVector(x),
00232 _LowerBound(x.LowerBound()), _UpperBound(x.UpperBound()) {}
00235 BCP_row(BCP_vec<int>::const_iterator firstind,
00236 BCP_vec<int>::const_iterator lastind,
00237 BCP_vec<double>::const_iterator firstval,
00238 BCP_vec<double>::const_iterator lastval,
00239 const double LB, const double UB) :
00240 CoinPackedVector(lastind - firstind, firstind, firstval,
00241 false ),
00242 _LowerBound(LB), _UpperBound(UB) {}
00245 BCP_row(const int size, int*& ElementIndices, double*& ElementValues,
00246 const double LB, const double UB) :
00247 CoinPackedVector(), _LowerBound(LB), _UpperBound(UB) {
00248 CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
00249 false );
00250 }
00251 BCP_row(const CoinPackedVectorBase& vec, const double LB, const double UB) :
00252 CoinPackedVector(vec.getNumElements(),
00253 vec.getIndices(), vec.getElements()),
00254 _LowerBound(LB), _UpperBound(UB) {}
00256 ~BCP_row() {}
00258 };
00259
00260
00261
00262
00266 class BCP_lp_relax : public CoinPackedMatrix {
00267 private:
00271 BCP_vec<double> _Objective;
00273 BCP_vec<double> _ColLowerBound;
00275 BCP_vec<double> _ColUpperBound;
00277 BCP_vec<double> _RowLowerBound;
00279 BCP_vec<double> _RowUpperBound;
00281
00282
00283 public:
00287 inline size_t colnum() const { return _ColLowerBound.size(); }
00289 inline size_t rownum() const { return _RowLowerBound.size(); }
00291 inline const BCP_vec<double>& Objective() const {return _Objective;}
00293 inline const BCP_vec<double>& ColLowerBound() const {return _ColLowerBound;}
00295 inline const BCP_vec<double>& ColUpperBound() const {return _ColUpperBound;}
00297 inline const BCP_vec<double>& RowLowerBound() const {return _RowLowerBound;}
00299 inline const BCP_vec<double>& RowUpperBound() const {return _RowUpperBound;}
00301
00302
00306 BCP_lp_relax& operator=(const BCP_lp_relax& mat);
00312 void reserve(const int MaxColNum, const int MaxRowNum,
00313 const int MaxNonzeros);
00315 void clear();
00317 void copyOf(const CoinPackedMatrix& m,
00318 const double* OBJ, const double* CLB, const double* CUB,
00319 const double* RLB, const double* RUB);
00321 void assign(CoinPackedMatrix& m,
00322 double*& OBJ, double*& CLB, double*& CUB,
00323 double*& RLB, double*& RUB);
00325
00326
00329 #if 0
00330
00332 void add_col_set(const BCP_col_set& Cols);
00335 void add_row_set(const BCP_row_set& Rows);
00336 #endif
00337
00339 void erase_col_set(const BCP_vec<int>& pos);
00342 void erase_row_set(const BCP_vec<int>& pos);
00344
00345 #if 0
00346
00350 double dot_product_col(const int index, const BCP_vec<double>& col) const;
00353 double dot_product_row(const int index, const BCP_vec<double>& row) const;
00356 double dot_product_col(const int index, const double* col) const;
00359 double dot_product_row(const int index, const double* row) const;
00361 #endif
00362
00363
00367 void pack(BCP_buffer& buf) const;
00369 void unpack(BCP_buffer& buf);
00371
00372
00376 BCP_lp_relax(const bool colordered = true) :
00377 CoinPackedMatrix(colordered, 0, 0, 0, NULL, NULL, NULL, NULL),
00378 _Objective(), _ColLowerBound(), _ColUpperBound(),
00379 _RowLowerBound(), _RowUpperBound() {}
00380
00382 BCP_lp_relax(const BCP_lp_relax& mat);
00383
00388 BCP_lp_relax(BCP_vec<BCP_row*>& rows,
00389 BCP_vec<double>& CLB, BCP_vec<double>& CUB,
00390 BCP_vec<double>& OBJ);
00391
00396 BCP_lp_relax(BCP_vec<BCP_row*>& rows,
00397 BCP_vec<double>& CLB, BCP_vec<double>& CUB,
00398 BCP_vec<double>& OBJ,
00399 double extra_gap, double extra_major);
00400
00405 BCP_lp_relax(BCP_vec<BCP_col*>& cols,
00406 BCP_vec<double>& RLB, BCP_vec<double>& RUB);
00407
00412 BCP_lp_relax(BCP_vec<BCP_col*>& cols,
00413 BCP_vec<double>& RLB, BCP_vec<double>& RUB,
00414 double extra_gap, double extra_major);
00415
00418 BCP_lp_relax(const bool colordered,
00419 const BCP_vec<int>& VB, const BCP_vec<int>& EI,
00420 const BCP_vec<double>& EV, const BCP_vec<double>& OBJ,
00421 const BCP_vec<double>& CLB, const BCP_vec<double>& CUB,
00422 const BCP_vec<double>& RLB, const BCP_vec<double>& RUB);
00427 BCP_lp_relax(const bool colordered,
00428 const int rownum, const int colnum, const int nznum,
00429 int*& VB, int*& EI, double*& EV,
00430 double*& OBJ, double*& CLB, double*& CUB,
00431 double*& RLB, double*& RUB);
00432
00434 ~BCP_lp_relax() {}
00436 private:
00439
00440 void BCP_createColumnOrderedMatrix(BCP_vec<BCP_row*>& rows,
00441 BCP_vec<double>& CLB,
00442 BCP_vec<double>& CUB,
00443 BCP_vec<double>& OBJ);
00445 void BCP_createRowOrderedMatrix(BCP_vec<BCP_col*>& cols,
00446 BCP_vec<double>& RLB,
00447 BCP_vec<double>& RUB);
00449 };
00450
00451 #endif