Dip 0.95.0
Loading...
Searching...
No Matches
DecompModel.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_MODEL_INCLUDED
16#define DECOMP_MODEL_INCLUDED
17
18//===========================================================================//
19#include "UtilMacrosDecomp.h"
20#include "DecompParam.h"
21#include "DecompConstraintSet.h"
22#include "DecompSolverResult.h"
23
24//===========================================================================//
25//naming convention - usually would do DecompModelXx, DecompModelYy
26//===========================================================================//
28protected:
30 std::string m_modelName;
33
34public:
36 return m_model;
37 }
38 const std::string& getModelName() const {
39 return m_modelName;
40 }
41 const int getBlockId() const {
42 return m_blockId;
43 }
44
45public:
47 m_model = model;
48 }
49 void setModelName(const std::string modelName) {
50 m_modelName = modelName;
51 }
52 void setBlockId (const int blockId) {
53 m_blockId = blockId;
54 }
55
56public:
57 DecompModel(const DecompModel& appModel) {
58 m_model = appModel.m_model;
59 m_modelName = appModel.m_modelName;
60 m_blockId = appModel.m_blockId;
61 m_utilParam = appModel.m_utilParam;
62 }
63
65 m_model = rhs.m_model;
67 m_blockId = rhs.m_blockId;
69 return *this;
70 }
71
73 m_model (NULL),
74 m_modelName(""),
75 m_blockId (0),
76 m_utilParam(&utilParam){};
77
79 std::string modelName,
80 int blockId,
81 UtilParameters& utilParam) :
82 m_model (model),
83 m_modelName(modelName),
84 m_blockId (blockId),
85 m_utilParam(&utilParam){};
86
87 virtual ~DecompModel() {}
88};
89
90//===========================================================================//
92private:
93 OsiSolverInterface* m_osi;
94 int m_numCols;
95 int* m_colIndices;
96 int m_counter;
97public:
98
99 inline void setCounter(const int num) {
100 m_counter = num;
101 }
102
103 inline int getCounter() {
104 return m_counter;
105 }
106
108 m_osi = osi;
109
110 if (!m_colIndices) {
111 //---
112 //--- For use with (re-)setting the objective coefficients
113 //--- setup an array of indices 0,...,n-1. This object assumes
114 //--- that the number of columns stayed constant throughout.
115 //---
116 const int numCols = m_osi->getNumCols();
117 m_numCols = numCols;
118 m_colIndices = new int[numCols];
119
120 if (!m_colIndices) {
121 UtilExceptionMemory("setOsi", "DecompSubModel");
122 }
123
124 UtilIotaN(m_colIndices, numCols, 0);
125 }
126 }
127
128 void setOsiObjCoeff(const double* objCoeff) {
129 assert(m_osi);
130 assert(m_colIndices);
131 assert(m_numCols == m_osi->getNumCols());
132
133 if (getModel()->isSparse()) {
134 const DecompConstraintSet* model = getModel();
135 const std::map<int, int>& origToSparse = model->getMapOrigToSparse();
136 std::map<int, int>::const_iterator mcit;
137
138 for (mcit = origToSparse.begin();
139 mcit != origToSparse.end(); mcit++) {
140 m_osi->setObjCoeff(mcit->second, //sparse-index
141 objCoeff[mcit->first]); //original-index
142 }
143 } else
144 m_osi->setObjCoeffSet(m_colIndices,
145 m_colIndices + m_numCols, objCoeff);
146 }
147
148
149 void setActiveColBounds(const double* colLB,
150 const double* colUB) {
151 DecompConstraintSet* model = getModel();
152 std::vector<int>& activeColumns = model->activeColumns;
153
154 //---
155 //--- if no active columns are set, assume they are all active
156 //--- for e.g., in the case of one block (or sparse)
157 //---
158 if (model->isSparse()) {
159 const std::map<int, int>& origToSparse = model->getMapOrigToSparse();
160 std::map<int, int>::const_iterator mcit;
161
162 for (mcit = origToSparse.begin();
163 mcit != origToSparse.end(); mcit++) {
164 m_osi->setColLower(mcit->second, //sparse-index
165 colLB[mcit->first]); //original-index
166 m_osi->setColUpper(mcit->second, //sparse-index
167 colUB[mcit->first]); //original-index
168 //printf("setColBounds orig:%d sparse:%d lb:%g ub:%g\n",
169 // mcit->first, mcit->second,
170 // colLB[mcit->first],
171 // colUB[mcit->first]);
172 }
173 } else {
174 if (activeColumns.size()) {
175 std::vector<int>::iterator vi;
176
177 for (vi = activeColumns.begin(); vi != activeColumns.end(); vi++) {
178 //printf("setColBounds i:%d to LB:%g UB:%g\n",
179 // *vi, colLB[*vi], colUB[*vi]);
180 m_osi->setColBounds(*vi, colLB[*vi], colUB[*vi]);
181 }
182 } else {
183 m_osi->setColLower(colLB);
184 m_osi->setColUpper(colUB);
185 }
186 }
187 }
188
190 DecompParam& param,
191 bool doExact,
192 bool doCutoff,
193 bool isRoot,
194 double cutoff,
195 double timeLimit);
196
198 DecompParam& param,
199 bool doExact,
200 bool doCutoff,
201 bool isRoot,
202 double cutoff,
203 double timeLimit);
204
206 DecompParam& param,
207 bool doExact,
208 bool doCutoff,
209 bool isRoot,
210 double cutoff,
211 double timeLimit);
212
214 DecompParam& param,
215 bool doExact,
216 bool doCutoff,
217 bool isRoot,
218 double cutoff,
219 double timeLimit);
220
221public:
223 return m_osi;
224 }
225
226public:
228 DecompParam& param,
229 bool doExact,
230 bool doCutoff,
231 bool isRoot,
232 double cutoff,
233 double timeLimit);
234
235 bool isPointFeasible(const double* x,
236 const bool isXSparse = false,
237 const int logLevel = 0,
238 const double feasVarTol = 1.0e-5,
239 const double feasConTol = 1.0e-4);
240
241public:
242 DecompSubModel(const DecompModel& appModel) :
243 DecompModel(appModel),
244 m_osi (NULL),
245 m_numCols (0 ),
246 m_colIndices (NULL),
247 m_counter ( 0 )
248 {};
249
252 return *this;
253 }
254
256 DecompModel(utilParam),
257 m_osi (NULL),
258 m_numCols (0 ),
259 m_colIndices (NULL),
260 m_counter (0)
261 {};
263 std::string modelName,
264 int blockId,
265 UtilParameters& utilParam) :
266 DecompModel(model, modelName, blockId, utilParam),
267 m_osi (NULL),
268 m_numCols (0 ),
269 m_colIndices (NULL),
270 m_counter (0)
271 {};
273 if (m_osi) {
274 delete m_osi;
275 }
276
277 if (m_colIndices) {
278 delete [] m_colIndices;
279 }
280 }
281};
282
283#endif
#define UtilExceptionMemory(methodN, classN)
void UtilIotaN(int *first, const int size, const int init)
Definition UtilMacros.h:278
const bool isSparse() const
std::vector< int > activeColumns
const std::map< int, int > & getMapOrigToSparse() const
void setModel(DecompConstraintSet *model)
Definition DecompModel.h:46
DecompModel(DecompConstraintSet *model, std::string modelName, int blockId, UtilParameters &utilParam)
Definition DecompModel.h:78
DecompConstraintSet * getModel() const
Definition DecompModel.h:35
DecompConstraintSet * m_model
Definition DecompModel.h:29
const int getBlockId() const
Definition DecompModel.h:41
const std::string & getModelName() const
Definition DecompModel.h:38
DecompModel & operator=(const DecompModel &rhs)
Definition DecompModel.h:64
void setModelName(const std::string modelName)
Definition DecompModel.h:49
virtual ~DecompModel()
Definition DecompModel.h:87
std::string m_modelName
Definition DecompModel.h:30
DecompModel(const DecompModel &appModel)
Definition DecompModel.h:57
DecompModel(UtilParameters &utilParam)
Definition DecompModel.h:72
UtilParameters * m_utilParam
Definition DecompModel.h:32
void setBlockId(const int blockId)
Definition DecompModel.h:52
Storage of solver result.
DecompSubModel(const DecompModel &appModel)
OsiSolverInterface * getOsi() const
void solveAsMIPCbc(DecompSolverResult *result, DecompParam &param, bool doExact, bool doCutoff, bool isRoot, double cutoff, double timeLimit)
DecompSubModel(UtilParameters &utilParam)
DecompSubModel(DecompConstraintSet *model, std::string modelName, int blockId, UtilParameters &utilParam)
void solveAsMIPSym(DecompSolverResult *result, DecompParam &param, bool doExact, bool doCutoff, bool isRoot, double cutoff, double timeLimit)
DecompSubModel & operator=(const DecompModel &rhs)
void solveAsMIPCpx(DecompSolverResult *result, DecompParam &param, bool doExact, bool doCutoff, bool isRoot, double cutoff, double timeLimit)
void setCounter(const int num)
Definition DecompModel.h:99
void setActiveColBounds(const double *colLB, const double *colUB)
bool isPointFeasible(const double *x, const bool isXSparse=false, const int logLevel=0, const double feasVarTol=1.0e-5, const double feasConTol=1.0e-4)
void solveAsMIPGrb(DecompSolverResult *result, DecompParam &param, bool doExact, bool doCutoff, bool isRoot, double cutoff, double timeLimit)
void setOsi(OsiSolverInterface *osi)
void solveAsMIP(DecompSolverResult *result, DecompParam &param, bool doExact, bool doCutoff, bool isRoot, double cutoff, double timeLimit)
void setOsiObjCoeff(const double *objCoeff)