coin-Bcp
BCP_matrix.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef _BCP_MATRIX_H
4 #define _BCP_MATRIX_H
5 
6 // This file is fully docified.
7 
8 // #include <cmath>
9 // #include <cfloat>
10 
11 #include "CoinPackedVector.hpp"
12 #include "CoinPackedMatrix.hpp"
13 
14 #include "BCP_math.hpp"
15 #include "BCP_vector.hpp"
16 
17 //#############################################################################
18 
19 class BCP_buffer;
20 
21 //#############################################################################
22 
26 class BCP_col : public CoinPackedVector {
27 
28 protected:
32  double _Objective;
34  double _LowerBound;
36  double _UpperBound;
38  //--------------------------------------------------------------------------
39 
40 public:
44  inline double Objective() const { return _Objective; }
46  inline double LowerBound() const { return _LowerBound; }
48  inline double UpperBound() const { return _UpperBound; }
50  //--------------------------------------------------------------------------
51 
55  inline void Objective(const double obj) { _Objective = obj; }
57  inline void LowerBound(const double lb) { _LowerBound = lb; }
59  inline void UpperBound(const double ub) { _UpperBound = ub; }
60 
62  BCP_col& operator=(const BCP_col& x) {
64  _Objective = x.Objective();
65  _LowerBound = x.LowerBound();
66  _UpperBound = x.UpperBound();
67  return *this;
68  }
72  inline void
73  assign(const int size, int*& ElementIndices, double*& ElementValues,
74  const double Obj, const double LB, const double UB) {
75  CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
76  false /* no test for duplicate index */);
77  _Objective = Obj;
78  _LowerBound = LB;
79  _UpperBound = UB;
80  }
82  inline void
83  copy(const int size, const int* ElementIndices, const double* ElementValues,
84  const double Obj, const double LB, const double UB) {
85  CoinPackedVector::setVector(size, ElementIndices, ElementValues,
86  false /* no test for duplicate index */);
87  _Objective = Obj;
88  _LowerBound = LB;
89  _UpperBound = UB;
90  }
94  inline void
99  const double Obj, const double LB, const double UB) {
100  CoinPackedVector::setVector(lastind - firstind, firstind, firstval,
101  false /* no test for duplicate index */);
102  _Objective = Obj;
103  _LowerBound = LB;
104  _UpperBound = UB;
105  }
107  //--------------------------------------------------------------------------
108 
113  BCP_col() : CoinPackedVector(false /* no test for duplicate index */),
116  BCP_col(const BCP_col& x) :
125  const double Obj, const double LB, const double UB) :
126  CoinPackedVector(lastind - firstind, firstind, firstval,
127  false /* no test for duplicate index */),
128  _Objective(Obj), _LowerBound(LB), _UpperBound(UB) {}
131  BCP_col(const int size, int*& ElementIndices, double*& ElementValues,
132  const double Obj, const double LB, const double UB) :
134  CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
135  false /* no test for duplicate index */);
136  }
138  const double Obj, const double LB, const double UB) :
140  vec.getIndices(), vec.getElements()),
141  _Objective(Obj), _LowerBound(LB), _UpperBound(UB) {}
143  ~BCP_col() {}
145 };
146 
147 //#############################################################################
148 
152 class BCP_row : public CoinPackedVector {
153 protected:
157  double _LowerBound;
159  double _UpperBound;
161  //--------------------------------------------------------------------------
162 
163 public:
167  inline double LowerBound() const { return _LowerBound; }
169  inline double UpperBound() const { return _UpperBound; }
171  //--------------------------------------------------------------------------
172 
176  inline void LowerBound(double lb) { _LowerBound = lb; }
178  inline void UpperBound(double ub) { _UpperBound = ub; }
179 
181  BCP_row& operator=(const BCP_row& x) {
183  _LowerBound = x.LowerBound();
184  _UpperBound = x.UpperBound();
185  return *this;
186  }
187 
190  void
191  assign(const int size, int*& ElementIndices, double*& ElementValues,
192  const double LB, const double UB) {
193  CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
194  false /* no test for duplicate index */);
195  _LowerBound = LB;
196  _UpperBound = UB;
197  }
199  void
200  copy(const int size, const int* ElementIndices, const double* ElementValues,
201  const double LB, const double UB) {
202  CoinPackedVector::setVector(size, ElementIndices, ElementValues,
203  false /* no test for duplicate index */);
204  _LowerBound = LB;
205  _UpperBound = UB;
206  }
210  void
215  const double LB, const double UB) {
216  CoinPackedVector::setVector(lastind - firstind, firstind, firstval,
217  false /* no test for duplicate index */);
218  _LowerBound = LB;
219  _UpperBound = UB;
220  }
222  //--------------------------------------------------------------------------
223 
228  BCP_row() : CoinPackedVector(false /* no test for duplicate index */),
231  BCP_row(const BCP_row& x) :
232  CoinPackedVector(x),
240  const double LB, const double UB) :
241  CoinPackedVector(lastind - firstind, firstind, firstval,
242  false /* no test for duplicate index */),
243  _LowerBound(LB), _UpperBound(UB) {}
246  BCP_row(const int size, int*& ElementIndices, double*& ElementValues,
247  const double LB, const double UB) :
249  CoinPackedVector::assignVector(size, ElementIndices, ElementValues,
250  false /* no test for duplicate index */);
251  }
252  BCP_row(const CoinPackedVectorBase& vec, const double LB, const double UB) :
254  vec.getIndices(), vec.getElements()),
255  _LowerBound(LB), _UpperBound(UB) {}
257  ~BCP_row() {}
259 };
260 
261 //#############################################################################
262 //#############################################################################
263 
268 private:
282  //--------------------------------------------------------------------------
283 
284 public:
288  inline size_t colnum() const { return _ColLowerBound.size(); }
290  inline size_t rownum() const { return _RowLowerBound.size(); }
292  inline const BCP_vec<double>& Objective() const {return _Objective;}
294  inline const BCP_vec<double>& ColLowerBound() const {return _ColLowerBound;}
296  inline const BCP_vec<double>& ColUpperBound() const {return _ColUpperBound;}
298  inline const BCP_vec<double>& RowLowerBound() const {return _RowLowerBound;}
300  inline const BCP_vec<double>& RowUpperBound() const {return _RowUpperBound;}
302  //--------------------------------------------------------------------------
303 
307  BCP_lp_relax& operator=(const BCP_lp_relax& mat);
313  void reserve(const int MaxColNum, const int MaxRowNum,
314  const int MaxNonzeros);
316  void clear();
318  void copyOf(const CoinPackedMatrix& m,
319  const double* OBJ, const double* CLB, const double* CUB,
320  const double* RLB, const double* RUB);
322  void assign(CoinPackedMatrix& m,
323  double*& OBJ, double*& CLB, double*& CUB,
324  double*& RLB, double*& RUB);
326  //--------------------------------------------------------------------------
327 
330 #if 0
331 
333  void add_col_set(const BCP_col_set& Cols);
336  void add_row_set(const BCP_row_set& Rows);
337 #endif
338 
340  void erase_col_set(const BCP_vec<int>& pos);
343  void erase_row_set(const BCP_vec<int>& pos);
345  //--------------------------------------------------------------------------
346 #if 0
347 
351  double dot_product_col(const int index, const BCP_vec<double>& col) const;
354  double dot_product_row(const int index, const BCP_vec<double>& row) const;
357  double dot_product_col(const int index, const double* col) const;
360  double dot_product_row(const int index, const double* row) const;
362 #endif
363  //--------------------------------------------------------------------------
364 
368  void pack(BCP_buffer& buf) const;
370  void unpack(BCP_buffer& buf);
372  //--------------------------------------------------------------------------
373 
377  BCP_lp_relax(const bool colordered = true) :
378  CoinPackedMatrix(colordered, 0, 0, 0, NULL, NULL, NULL, NULL),
381 
383  BCP_lp_relax(const BCP_lp_relax& mat);
384 
390  BCP_vec<double>& CLB, BCP_vec<double>& CUB,
391  BCP_vec<double>& OBJ);
392 
398  BCP_vec<double>& CLB, BCP_vec<double>& CUB,
399  BCP_vec<double>& OBJ,
400  double extra_gap, double extra_major);
401 
407  BCP_vec<double>& RLB, BCP_vec<double>& RUB);
408 
414  BCP_vec<double>& RLB, BCP_vec<double>& RUB,
415  double extra_gap, double extra_major);
416 
419  BCP_lp_relax(const bool colordered,
420  const BCP_vec<int>& VB, const BCP_vec<int>& EI,
421  const BCP_vec<double>& EV, const BCP_vec<double>& OBJ,
422  const BCP_vec<double>& CLB, const BCP_vec<double>& CUB,
423  const BCP_vec<double>& RLB, const BCP_vec<double>& RUB);
428  BCP_lp_relax(const bool colordered,
429  const int rownum, const int colnum, const int nznum,
430  int*& VB, int*& EI, double*& EV,
431  double*& OBJ, double*& CLB, double*& CUB,
432  double*& RLB, double*& RUB);
433 
437 private:
442  BCP_vec<double>& CLB,
443  BCP_vec<double>& CUB,
444  BCP_vec<double>& OBJ);
447  BCP_vec<double>& RLB,
448  BCP_vec<double>& RUB);
450 };
451 
452 #endif
double LowerBound() const
Return the lower bound.
Definition: BCP_matrix.hpp:167
const BCP_vec< double > & RowLowerBound() const
A const reference to the vector of lower bounds on the cuts.
Definition: BCP_matrix.hpp:298
BCP_row(const int size, int *&ElementIndices, double *&ElementValues, const double LB, const double UB)
This constructor acts exactly like the assign method with the same argument list. ...
Definition: BCP_matrix.hpp:246
BCP_vec< double > _ColUpperBound
The upper bounds on the variables.
Definition: BCP_matrix.hpp:276
This class holds a column in a compressed form.
Definition: BCP_matrix.hpp:26
void erase_row_set(const BCP_vec< int > &pos)
Remove the rows whose indices are listed in pos from the LP relaxation.
BCP_vec< double > _RowUpperBound
The upper bounds on the cuts.
Definition: BCP_matrix.hpp:280
double LowerBound() const
Return the lower bound.
Definition: BCP_matrix.hpp:46
size_t rownum() const
The number of rows.
Definition: BCP_matrix.hpp:290
void LowerBound(double lb)
Set the lower bound to the given value.
Definition: BCP_matrix.hpp:176
double UpperBound() const
Return the upper bound.
Definition: BCP_matrix.hpp:48
BCP_col(const int size, int *&ElementIndices, double *&ElementValues, const double Obj, const double LB, const double UB)
This constructor acts exactly like the assign method with the same argument list. ...
Definition: BCP_matrix.hpp:131
void clear()
Clear the LP relaxation.
BCP_col(const BCP_col &x)
The copy constructor makes a copy of x.
Definition: BCP_matrix.hpp:116
~BCP_col()
The destructor deletes all data members.
Definition: BCP_matrix.hpp:143
void assign(const int size, int *&ElementIndices, double *&ElementValues, const double Obj, const double LB, const double UB)
Set the objective coefficient, lower and upper bounds to the given values.
Definition: BCP_matrix.hpp:73
virtual const int * getIndices() const
Get indices of elements.
virtual const double * getElements() const
Get element values.
BCP_row(BCP_vec< int >::const_iterator firstind, BCP_vec< int >::const_iterator lastind, BCP_vec< double >::const_iterator firstval, BCP_vec< double >::const_iterator lastval, const double LB, const double UB)
This constructor acts exactly like the copy method with the same argument list.
Definition: BCP_matrix.hpp:236
void setVector(int size, const int *inds, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Set vector size, indices, and elements.
size_t colnum() const
The number of columns.
Definition: BCP_matrix.hpp:288
CoinPackedVector & operator=(const CoinPackedVector &)
Assignment operator.
BCP_lp_relax(const bool colordered=true)
Create an empty LP relaxation with given ordering.
Definition: BCP_matrix.hpp:377
void BCP_createRowOrderedMatrix(BCP_vec< BCP_col * > &cols, BCP_vec< double > &RLB, BCP_vec< double > &RUB)
Sparse Matrix Base Class.
void copy(BCP_vec< int >::const_iterator firstind, BCP_vec< int >::const_iterator lastind, BCP_vec< double >::const_iterator firstval, BCP_vec< double >::const_iterator lastval, const double LB, const double UB)
Same as the other copy() method, except that instead of using vectors the indices (values) are given ...
Definition: BCP_matrix.hpp:211
const BCP_vec< double > & ColUpperBound() const
A const reference to the vector of upper bounds on the variables.
Definition: BCP_matrix.hpp:296
void erase_col_set(const BCP_vec< int > &pos)
Remove the columns whose indices are listed in pos from the LP relaxation.
BCP_col(BCP_vec< int >::const_iterator firstind, BCP_vec< int >::const_iterator lastind, BCP_vec< double >::const_iterator firstval, BCP_vec< double >::const_iterator lastval, const double Obj, const double LB, const double UB)
This constructor acts exactly like the copy method with the same argument list.
Definition: BCP_matrix.hpp:121
void assign(const int size, int *&ElementIndices, double *&ElementValues, const double LB, const double UB)
Set the lower and upper bounds to the given values.
Definition: BCP_matrix.hpp:191
double _UpperBound
The upper bound corresponding to the column.
Definition: BCP_matrix.hpp:36
Abstract base class for various sparse vectors.
virtual int getNumElements() const
Get the size.
void copyOf(const CoinPackedMatrix &m, const double *OBJ, const double *CLB, const double *CUB, const double *RLB, const double *RUB)
Set up the LP relaxation by making a copy of the arguments.
#define BCP_DBL_MAX
Definition: BCP_math.hpp:6
void unpack(BCP_buffer &buf)
Unpack the LP relaxation from the buffer.
BCP_vec< double > _ColLowerBound
The lower bounds on the variables.
Definition: BCP_matrix.hpp:274
double _Objective
The objective function coefficient corresponding to the column.
Definition: BCP_matrix.hpp:32
void UpperBound(const double ub)
Set the upper bound to the given value.
Definition: BCP_matrix.hpp:59
double Objective() const
Return the objective coefficient.
Definition: BCP_matrix.hpp:44
const BCP_vec< double > & Objective() const
A const reference to the vector of objective coefficients.
Definition: BCP_matrix.hpp:292
double _LowerBound
The lower bound corresponding to the column.
Definition: BCP_matrix.hpp:34
const BCP_vec< double > & ColLowerBound() const
A const reference to the vector of lower bounds on the variables.
Definition: BCP_matrix.hpp:294
void assign(CoinPackedMatrix &m, double *&OBJ, double *&CLB, double *&CUB, double *&RLB, double *&RUB)
Set up the LP relaxation by taking over the pointers in the arguments.
void pack(BCP_buffer &buf) const
Pack the LP relaxation into the buffer.
BCP_vec< double > _Objective
The objective coefficients of the variables.
Definition: BCP_matrix.hpp:272
~BCP_lp_relax()
The destructor deletes the data members.
Definition: BCP_matrix.hpp:435
double UpperBound() const
Return the upper bound.
Definition: BCP_matrix.hpp:169
BCP_col()
The default constructor creates an empty column with 0 as objective coefficient, 0.0 as lower and +infinity as upper bound.
Definition: BCP_matrix.hpp:113
size_t size() const
Return the current number of entries.
Definition: BCP_vector.hpp:116
void Objective(const double obj)
Set the objective coefficient to the given value.
Definition: BCP_matrix.hpp:55
Sparse Vector.
The class BCP_vec serves the same purpose as the vector class in the standard template library...
Definition: BCP_vector.hpp:24
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
void copy(BCP_vec< int >::const_iterator firstind, BCP_vec< int >::const_iterator lastind, BCP_vec< double >::const_iterator firstval, BCP_vec< double >::const_iterator lastval, const double Obj, const double LB, const double UB)
Same as the other copy() method, except that instead of using vectors the indices (values) are given ...
Definition: BCP_matrix.hpp:95
~BCP_row()
The destructor deletes all data members.
Definition: BCP_matrix.hpp:257
double _UpperBound
The upper bound corresponding to the row.
Definition: BCP_matrix.hpp:159
void copy(const int size, const int *ElementIndices, const double *ElementValues, const double LB, const double UB)
Copy the arguments into the appropriate data members.
Definition: BCP_matrix.hpp:200
BCP_row(const BCP_row &x)
The copy constructor makes a copy of x.
Definition: BCP_matrix.hpp:231
void UpperBound(double ub)
Set the upper bound to the given value.
Definition: BCP_matrix.hpp:178
BCP_row()
The default constructor creates an empty row with -infinity as lower and +infinity as upper bound...
Definition: BCP_matrix.hpp:228
BCP_col & operator=(const BCP_col &x)
Assignment operator: copy over the contents of x.
Definition: BCP_matrix.hpp:62
void copy(const int size, const int *ElementIndices, const double *ElementValues, const double Obj, const double LB, const double UB)
Copy the arguments into the appropriate data members.
Definition: BCP_matrix.hpp:83
BCP_lp_relax & operator=(const BCP_lp_relax &mat)
Copy the content of x into the LP relaxation.
BCP_vec< double > _RowLowerBound
The lower bounds on the cuts.
Definition: BCP_matrix.hpp:278
void assignVector(int size, int *&inds, double *&elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Assign the ownership of the arguments to this vector.
const BCP_vec< double > & RowUpperBound() const
A const reference to the vector of upper bounds on the cuts.
Definition: BCP_matrix.hpp:300
void reserve(const int MaxColNum, const int MaxRowNum, const int MaxNonzeros)
Reserve space in the LP relaxation for at least MaxColNum columns, MaxRowNum rows and MaxNonzeros non...
BCP_row & operator=(const BCP_row &x)
Assignment operator: copy over the contents of x.
Definition: BCP_matrix.hpp:181
An object of type BCP_lp_relax holds the description of an lp relaxation.
Definition: BCP_matrix.hpp:267
BCP_row(const CoinPackedVectorBase &vec, const double LB, const double UB)
The default constructor creates an empty row with -infinity as lower and +infinity as upper bound...
Definition: BCP_matrix.hpp:252
void BCP_createColumnOrderedMatrix(BCP_vec< BCP_row * > &rows, BCP_vec< double > &CLB, BCP_vec< double > &CUB, BCP_vec< double > &OBJ)
BCP_col(const CoinPackedVectorBase &vec, const double Obj, const double LB, const double UB)
The default constructor creates an empty column with 0 as objective coefficient, 0.0 as lower and +infinity as upper bound.
Definition: BCP_matrix.hpp:137
void LowerBound(const double lb)
Set the lower bound to the given value.
Definition: BCP_matrix.hpp:57
This class holds a row in a compressed form.
Definition: BCP_matrix.hpp:152
double _LowerBound
The lower bound corresponding to the row.
Definition: BCP_matrix.hpp:157