Minotaur 0.4.1
Docs for developers
OsiLPEngine.h
Go to the documentation of this file.
1//
2// Minotaur -- It's only 1/2 bull
3//
4// (C)opyright 2008 - 2025 The Minotaur Team.
5//
6
13#ifndef MINOTAUROSILPENGINE_H
14#define MINOTAUROSILPENGINE_H
15
16#include "LPEngine.h"
17#include "WarmStart.h"
18
19class CoinWarmStart;
20class OsiSolverInterface;
21
22namespace Minotaur {
23
24class Timer;
25class Environment;
26class Problem;
27class Solution;
28class WarmStart;
29typedef Environment *EnvPtr;
30typedef Problem *ProblemPtr;
31typedef Solution *SolutionPtr;
32typedef WarmStart *WarmStartPtr;
33
35struct OsiLPStats {
36 UInt calls;
38 double time;
39 double strTime;
42};
43
44typedef enum {
45 OsiClpEngine,
46 OsiGlpkEngine,
47 OsiGrbEngine,
48 OsiMskEngine,
49 OsiSpxEngine,
50 OsiXprEngine,
51 OsiUndefEngine
52} OsiLPEngineName;
53
55class OsiLPWarmStart : public WarmStart {
56 public:
57 friend class Problem;
58
61
64
66 CoinWarmStart *getCoinWarmStart() const;
67
68 // Implement Engine::hasInfo().
69 bool hasInfo();
70
75 void setCoinWarmStart(CoinWarmStart *coin_ws, bool must_delete);
76
80 void setDualWarmStart(int size, const double *dual);
81
82 // Implement Engine::write().
83 void write(std::ostream &out) const;
84
85 private:
90 CoinWarmStart *coinWs_;
91
96 bool mustDelete_;
97};
100
102class OsiLPEngine : public LPEngine {
103 public:
105 OsiLPEngine(EnvPtr env);
106
108 ~OsiLPEngine();
109
110 // Implement Engine::addConstraint().
112
113 // Change bounds on a constraint.
114 void changeBound(ConstraintPtr cons, BoundType lu, double new_val);
115
116 // Implement Engine::changeBound(VariablePtr, BoundType, double).
117 void changeBound(VariablePtr var, BoundType lu, double new_val);
118
119 // Implement Engine::changeBound(VariablePtr, double, double).
120 void changeBound(VariablePtr var, double new_lb, double new_ub);
121
122 // Implement Engine::changeConstraint().
123 void changeConstraint(ConstraintPtr con, LinearFunctionPtr lf, double lb,
124 double ub);
125
126 // Implement Engine::changeConstraint().
128
129 // change the objective function.
130 void changeObj(FunctionPtr f, double cb);
131
133 void clear();
134
135 // Implement Engine::disableStrBrSetup()
136 void disableStrBrSetup();
137
140
141 void enableFactorization();
142
143 void disableFactorization();
144
145 // Implement Engine::enableStrBrSetup()
146 void enableStrBrSetup();
147
148 // Implement Engine::fillStats()
149 void fillStats(std::vector<double> &);
150
151 // Get the indices of the basic variables from the tableau
152 void getBasics(int *index);
153
154 /* Get the basic row of the corresponding row index
155 * param[in] row - Row index for which the optimal tableau row is required
156 * param[out] z - Row corresponding to original variables
157 * param[out] slack - Row corresponding to slack variables
158 */
159 void getBInvARow(int row, double *z, double *slack);
160
161 /* \brief Get basic status of the variables in the sovler
162 * param[out] cstat - A vector for column status (Variables of the problem)
163 * param[in] rstat - A vector for row status (Constraints of the problem)
164 * Output values are
165 * 0 : Free variable
166 * 1 : Basic
167 * 2 : At upper bound (Non-basic)
168 * 3 : At lower bound (Non-basic)
169 */
170 void getBasisStatus(int *cstat, int *rstat);
171
172 // Get lower bounds of the variables in the solver
173 const double *getColLower();
174
175 // Get upper bounds of the variables in the solver
176 const double *getColUpper();
177
178 // Get lower bounds of the constraints in the solver
179 const double *getRowLower();
180
181 // Get upper bounds of the constraints in the solver
182 const double *getRowUpper();
183
184 // Get right hand side of the rows in the simplex tableau
185 const double *getRightHandSide();
186
187 // Get number of columns to the solver
188 int getNumCols();
189
190 // Get number of rows to the solver
191 int getNumRows();
192
193 // Get row activity
194 const double *getRowActivity();
195
196 // To get the original tableau from the solver
197 const double *getOriginalTableau();
198
199 // Get start index for each row in the original tableau
200 const int *getRowStarts();
201
202 // Gets indices of variables in the elements of the original tableau
203 const int *getIndicesofVars();
204
205 // Get the length of each row in the original tableau
206 const int *getRowLength();
207
209 double getSolutionValue();
210
211 // Implement Engine::getSolution().
213
214 // Implement Engine::getStatus().
216
220 int getIterationCount();
221
222 // get name.
223 std::string getName() const;
224
226 // OsiSolverInterface * getSolver();
227
228 // Implement Engine::getWarmStart().
229 // See OsiLPSolver.hpp to see Osi's description of warm-start pointer.
230 // It differs from solver to solver. We just return NULL for now.
232 assert(!"not implemented!");
233 return WarmStartPtr();
234 };
235
236 // Implement Engine::getWarmStartCopy().
238
239 // Returns true if Optimal basis is available with the sovler
240 bool IsOptimalBasisAvailable();
241
247 void load(ProblemPtr problem);
248
249 // Implement Engine::loadFromWarmStart().
250 void loadFromWarmStart(const WarmStartPtr ws);
251
252 // Load dual warm start info in the solver
253 void loadDualWarmStart(int size, double *dualVec);
254
255 // Convert 'min f' to 'min -f'.
256 void negateObj();
257
258 // base class method.
259 void removeCons(std::vector<ConstraintPtr> &delcons);
260
261 // Implement Engine::resetIterationLimit().
262 void resetIterationLimit();
263
264 // Implement Engine::setIterationLimit().
265 void setIterationLimit(int limit);
266
267 // Implement Engine::setDualObjLimit().
268 int setDualObjLimit(double) { return 1; };
269
276
278 void writeLP(const char *filename) const;
279
281 void writeStats(std::ostream &out) const;
282
283 private:
286 bool bndChanged_;
287
289 bool consChanged_;
290
292 EnvPtr env_;
293
295 OsiLPEngineName eName_;
296
298 int maxIterLimit_;
299
301 static const std::string me_;
302
304 bool objChanged_;
305
310 OsiSolverInterface *osilp_;
311
313 bool pickLPMeth_;
314
316 ProblemPtr problem_;
317
319 SolutionPtr sol_;
320
322 OsiLPStats *stats_;
323
325 bool strBr_;
326
328 Timer *timer_;
329
330 // Create a new solver (cplex, or clp or ..)
331 OsiSolverInterface *newSolver_(OsiLPEngineName ename);
332};
333
334typedef OsiLPEngine *OsiLPEnginePtr;
335} // namespace Minotaur
336
337#endif
Declare the class LPEngine for solving LPs and getting solution.
The Constraint class is used to manage a constraint.
Definition: Constraint.h:61
Definition: Engine.h:34
Definition: Environment.h:28
Definition: Function.h:37
Definition: LPEngine.h:29
The base class linear function is of the form c'x.
Definition: LinearFunction.h:31
Base class for nonlinear functions.
Definition: NonlinearFunction.h:31
The OsiLPEngine engine uses the OSI interface to CLP solver.
Definition: OsiLPEngine.h:102
void addConstraint(ConstraintPtr)
Add a new constraint to the engine.
Definition: OsiLPEngine.cpp:170
int setDualObjLimit(double)
Set the dual objective limit.
Definition: OsiLPEngine.h:268
~OsiLPEngine()
Destroy.
Definition: OsiLPEngine.cpp:156
void removeCons(std::vector< ConstraintPtr > &delcons)
Delete constraints from the engine.
Definition: OsiLPEngine.cpp:642
void changeBound(ConstraintPtr cons, BoundType lu, double new_val)
Change a bound of a constraint.
Definition: OsiLPEngine.cpp:191
void loadFromWarmStart(const WarmStartPtr ws)
Definition: OsiLPEngine.cpp:587
void writeLP(const char *filename) const
Writes an LP file of the loaded LP.
Definition: OsiLPEngine.cpp:762
ConstWarmStartPtr getWarmStart()
Return the osilp interface. For hacks.
Definition: OsiLPEngine.h:231
EnginePtr emptyCopy()
Return an empty OsiLPEngine pointer.
Definition: OsiLPEngine.cpp:315
int getIterationCount()
Definition: OsiLPEngine.cpp:329
void writeStats(std::ostream &out) const
Write statistics.
Definition: OsiLPEngine.cpp:767
void changeObj(FunctionPtr f, double cb)
Change objective function.
Definition: OsiLPEngine.cpp:272
void disableStrBrSetup()
Restore settings after strong branching.
Definition: OsiLPEngine.cpp:306
double getSolutionValue()
Return the solution value of the objective after solving the LP.
Definition: OsiLPEngine.cpp:436
void fillStats(std::vector< double > &)
Accumulate statistics from different threads in a common data.
Definition: OsiLPEngine.cpp:334
OsiLPEngine(EnvPtr env)
Constructor with an environment.
Definition: OsiLPEngine.cpp:109
void resetIterationLimit()
Reset the iteration limit to maximum possible.
Definition: OsiLPEngine.cpp:653
void changeConstraint(ConstraintPtr con, LinearFunctionPtr lf, double lb, double ub)
Change the linear function, and the bounds of a constraint.
Definition: OsiLPEngine.cpp:231
EngineStatus solve()
Definition: OsiLPEngine.cpp:665
std::string getName() const
Get the name.
Definition: OsiLPEngine.cpp:431
void enableStrBrSetup()
Make settings for strong branching.
Definition: OsiLPEngine.cpp:320
void setIterationLimit(int limit)
Definition: OsiLPEngine.cpp:659
EngineStatus getStatus()
Get the status of the last solve command.
Definition: OsiLPEngine.cpp:451
void load(ProblemPtr problem)
Definition: OsiLPEngine.cpp:473
WarmStartPtr getWarmStartCopy()
Definition: OsiLPEngine.cpp:456
void clear()
Clear the problem.
Definition: OsiLPEngine.cpp:288
ConstSolutionPtr getSolution()
Get the solution obtained after solving the problem.
Definition: OsiLPEngine.cpp:441
void negateObj()
Negate the objective function. Min f is changed to Min -f.
Definition: OsiLPEngine.cpp:603
Actual implementation of warm start for OsiLP Engine.
Definition: OsiLPEngine.h:55
CoinWarmStart * getCoinWarmStart() const
Get the warm-start description.
Definition: OsiLPEngine.cpp:78
void write(std::ostream &out) const
Write to an output stream.
Definition: OsiLPEngine.cpp:101
bool hasInfo()
Definition: OsiLPEngine.cpp:69
OsiLPWarmStart()
Default constructor.
Definition: OsiLPEngine.cpp:55
void setCoinWarmStart(CoinWarmStart *coin_ws, bool must_delete)
Definition: OsiLPEngine.cpp:83
void setDualWarmStart(int size, const double *dual)
Definition: OsiLPEngine.cpp:95
~OsiLPWarmStart()
Destroy.
Definition: OsiLPEngine.cpp:61
Definition: Problem.h:74
Definition: Solution.h:30
Definition: Timer.h:40
Definition: Variable.h:31
Definition: WarmStart.h:45
Definition: ActiveNodeStore.h:20
BoundType
Different types of variable-bounds.
Definition: Types.h:131
unsigned int UInt
Unsigned integer.
Definition: Types.h:30
EngineStatus
Different status that an external engine may report.
Definition: Types.h:176
Statistics.
Definition: OsiLPEngine.h:35
double time
Calls to solve while strong branching.
Definition: OsiLPEngine.h:38
UInt strIters
Sum of number of iterations in all calls.
Definition: OsiLPEngine.h:41
UInt iters
time taken in strong branching alone.
Definition: OsiLPEngine.h:40
UInt strCalls
Total number of calls to solve.
Definition: OsiLPEngine.h:37
double strTime
Sum of time taken in all calls to solve.
Definition: OsiLPEngine.h:39

Minotaur source code documented by Doxygen 1.9.4 on Fri Apr 25 2025