Dip  0.92.4
DecompConstraintSet.h
Go to the documentation of this file.
1 //===========================================================================//
2 // This file is part of the DIP Solver Framework. //
3 // //
4 // DIP is distributed under the Eclipse Public License as part of the //
5 // COIN-OR repository (http://www.coin-or.org). //
6 // //
7 // Authors: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) //
8 // Ted Ralphs, Lehigh University (ted@lehigh.edu) //
9 // Jiadong Wang, Lehigh University (jiw408@lehigh.edu) //
10 // //
11 // Copyright (C) 2002-2019, Lehigh University, Matthew Galati, and Ted Ralphs//
12 // All Rights Reserved. //
13 //===========================================================================//
14 
15 #ifndef DECOMP_CONSTRAINTSET_INCLUDED
16 #define DECOMP_CONSTRAINTSET_INCLUDED
17 
18 // --------------------------------------------------------------------- //
19 #include "Decomp.h"
20 #include "UtilMacros.h"
21 
22 // --------------------------------------------------------------------- //
27 };
28 
29 // --------------------------------------------------------------------- //
31 public:
34  int nBaseRows;
35  std::vector<std::string> rowHash;
36  std::vector<char> rowSense;
37  std::vector<double> rowRhs;
38  std::vector<double> rowLB;
39  std::vector<double> rowUB;
40  std::vector<double> colLB;
41  std::vector<double> colUB;
42  std::vector<int> integerVars;
43  std::vector<char> integerMark; //'C' = continuous, 'I' = integral
44  std::vector<std::string> colNames;
45  std::vector<std::string> rowNames;
46  std::vector<int> activeColumns; //if block, define the active columns
47  std::set<int> activeColumnsS;//if block, define the active columns
48  std::vector<int> masterOnlyCols;
49  bool prepHasRun;
50 
51  //for storage of several rows of row-majored sparse matrix
52  // to be used with appendRows
53  std::vector<CoinBigIndex> m_rowBeg;
54  std::vector<int > m_rowInd;
55  std::vector<double > m_rowVal;
56 
57  //for special case of sparse representation
58  bool m_isSparse;
60  std::map<int, int> m_origToSparse;
61  std::map<int, int> m_sparseToOrig;
62  double m_infinity;
63 
64 public:
65  inline void setSparse(const int numColsOrig) {
66  m_numColsOrig = numColsOrig;
67  m_isSparse = true;
68  }
69  inline const bool isSparse() const {
70  return m_origToSparse.size() ? true : false;
71  };
72  inline const CoinPackedMatrix* getMatrix() const {
73  return M;
74  };
75  inline const int getNumRows() const {
76  return M ? M->getNumRows() : static_cast<int>(rowLB.size());
77  }
78  inline const int getNumCols() const {
79  return M ? M->getNumCols() : static_cast<int>(colLB.size());
80  }
81  inline const int getNumColsOrig() const {
82  return isSparse() ? m_numColsOrig : getNumCols();
83  };
84  inline const int getNumInts() const {
85  return static_cast<int>(integerVars.size());
86  }
87  inline const std::vector<int>& getActiveColumns() const {
88  return activeColumns;
89  }
90  inline const std::vector<std::string>& getRowNames() const {
91  return rowNames;
92  }
93  inline const std::vector<std::string>& getColNames() const {
94  return colNames;
95  }
96  inline std::vector<std::string>& getRowNamesMutable() {
97  return rowNames;
98  }
99  inline std::vector<std::string>& getColNamesMutable() {
100  return colNames;
101  }
102  inline const char* getIntegerMark() {
103  return &integerMark[0];
104  }
105  inline const int* getIntegerVars() {
106  return &integerVars[0];
107  }
108  inline const double* getColLB() const {
109  return &colLB[0];
110  };
111  inline const double* getColUB() const {
112  return &colUB[0];
113  };
114  inline const double* getRowLB() const {
115  return &rowLB[0];
116  };
117  inline const double* getRowUB() const {
118  return &rowUB[0];
119  };
120  inline const bool hasPrepRun() const {
121  return prepHasRun;
122  };
123  inline const std::map<int, int>& getMapOrigToSparse() const {
124  return m_origToSparse;
125  };
126  inline const std::map<int, int>& getMapSparseToOrig() const {
127  return m_sparseToOrig;
128  };
129  inline const std::vector<int>& getMasterOnlyCols() const {
130  return masterOnlyCols;
131  }
132 
133 
134 public:
135  void prepareModel(double infinity, bool modelIsCore = false);
136  void createRowHash(double infinity);
137  void checkSenseAndBound(double infinity);
138  void sensesToBounds(double infinity);
139  void boundsToSenses(double infinity);
140  void fixNonActiveColumns();
142 
143  inline void appendRow(CoinPackedVector& row,
144  double loBound,
145  double upBound) {
146  M->appendRow(row);
147  rowLB.push_back(loBound);
148  rowUB.push_back(upBound);
149  }
150  //inline void appendRow(CoinPackedVector & row,
151  // double loBound,
152  // double upBound,
153  // std::string & rowName){
154  // appendRow(row, loBound, upBound);
155  // rowNames.push_back(rowName);
156  //}
157  inline void appendRow(CoinPackedVector& row,
158  double loBound,
159  double upBound,
160  std::string rowName) {
161  appendRow(row, loBound, upBound);
162  rowNames.push_back(rowName);
163  }
164 
165  inline void pushCol(const double loBound,
166  const double upBound,
167  const bool isInteger = false,
168  const int origIndex = -1) {
169  int index = static_cast<int>(colLB.size());
170  colLB.push_back(loBound);
171  colUB.push_back(upBound);
172 
173  if (isInteger) {
174  if (std::find(integerVars.begin(), integerVars.end(), index)
175  == integerVars.end()) {
176  integerVars.push_back(index);
177  }
178  }
179 
180  assert(!(origIndex == -1 && m_isSparse));
181 
182  if (origIndex >= 0) {
183  m_origToSparse.insert(std::make_pair(origIndex, index));
184  m_sparseToOrig.insert(std::make_pair(index, origIndex));
185  }
186  }
187 
188  inline void reserve(const int nCols,
189  const int nRows) {
190  M->reserve(nRows, nCols);
191  rowLB.reserve(nRows);
192  rowUB.reserve(nRows);
193  colLB.reserve(nCols);
194  colUB.reserve(nCols);
195  }
196 public:
198  M (0),
199  nBaseRowsOrig (0),
200  nBaseRows (0),
201  prepHasRun (false),
202  m_isSparse (false),
203  m_numColsOrig (0),
204  m_infinity (){
205  };
206 
208  UTIL_DELPTR(M);
209  };
210 };
211 
212 #endif
std::vector< double > colLB
void reserve(const int newMaxMajorDim, const CoinBigIndex newMaxSize, bool create=false)
Reserve sufficient space for appending major-ordered vectors.
std::vector< double > rowLB
std::vector< std::string > rowNames
const std::vector< int > & getMasterOnlyCols() const
std::vector< CoinBigIndex > m_rowBeg
std::set< int > activeColumnsS
std::vector< double > colUB
std::vector< double > rowUB
const std::map< int, int > & getMapSparseToOrig() const
std::vector< int > activeColumns
void setSparse(const int numColsOrig)
int getNumRows() const
Number of rows.
Sparse Matrix Base Class.
CoinPackedMatrix * sparseToOrigMatrix()
const char * getIntegerMark()
const bool isSparse() const
const double * getColUB() const
const int getNumRows() const
std::vector< int > integerVars
void appendRow(const CoinPackedVectorBase &vec)
std::vector< std::string > & getColNamesMutable()
const double * getRowLB() const
const std::vector< int > & getActiveColumns() const
void appendRow(CoinPackedVector &row, double loBound, double upBound)
std::map< int, int > m_sparseToOrig
std::vector< std::string > colNames
CoinPackedMatrix * M
const std::map< int, int > & getMapOrigToSparse() const
int getNumCols() const
Number of columns.
void appendRow(CoinPackedVector &row, double loBound, double upBound, std::string rowName)
std::map< int, int > m_origToSparse
const std::vector< std::string > & getRowNames() const
void pushCol(const double loBound, const double upBound, const bool isInteger=false, const int origIndex=-1)
const int getNumInts() const
std::vector< double > m_rowVal
std::vector< double > rowRhs
const std::vector< std::string > & getColNames() const
#define UTIL_DELPTR(x)
Definition: UtilMacros.h:28
std::vector< std::string > rowHash
Sparse Vector.
ColMarkerType
const double * getRowUB() const
const double * getColLB() const
const int getNumCols() const
void prepareModel(double infinity, bool modelIsCore=false)
const int * getIntegerVars()
const int getNumColsOrig() const
std::vector< int > masterOnlyCols
std::vector< char > integerMark
const bool hasPrepRun() const
std::vector< char > rowSense
std::vector< std::string > & getRowNamesMutable()
const CoinPackedMatrix * getMatrix() const
std::vector< int > m_rowInd
void reserve(const int nCols, const int nRows)