Minotaur 0.4.1
Docs for developers
CplexLPEngine.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 MINOTAURCPLEXLPENGINE_H
14#define MINOTAURCPLEXLPENGINE_H
15#include <ilcplex/cplexx.h>
16#include <string.h>
17#include "LPEngine.h"
18#include "STOAHandler.h"
19#include "WarmStart.h"
20
21
22namespace Minotaur {
23
24 class Timer;
25 class Environment;
26 class Problem;
27 class Solution;
28 class WarmStart;
29 typedef Environment* EnvPtr;
30 typedef Problem* ProblemPtr;
31 typedef Solution* SolutionPtr;
32 typedef WarmStart* WarmStartPtr;
33
35 struct CplexLPStats {
36 UInt calls;
38 double time;
39 double strTime;
42 };
43
44 class CpxLPWarmStart;
47
49 class CpxLPWarmStart : public WarmStart {
50
51 public:
54
57
59 //CpxLPSolPtr getPoint();
60
61 // Implement WarmStart::hasInfo().
62 bool hasInfo();
63
64 /*
65 Overwrite the primal and dual values of warm-start. Sometimes, the
66 warm-start data is initialized and needs to be updated. This
67 should be called in place of deleting and creating a new warm-start
68 object. */
69 //void setPoint(CpxLPSolPtr sol);
70
71 // Implement WarmStart::write().
72 void write(std::ostream &) const {};
73
74 // Return varstat array from warmstart
75 //int *getVarStat() const { return varstat_;}
76
77 // Return constat array from warmstart
78 //int *getConStat() const { return constat_;}
79
80 // Return the size of constat_ (number of constraints)
81 //int getNumCons() const { return numCons_;}
82
83 // Return solution from warmstart
84 SolutionPtr getSolution() const { return sol_;}
85
86 // Return the size of constat_ (number of constraints)
87 //void setNumCons(int num) { numCons_ = num;}
88
89 // Set varstat array for warmstart
90 //void setVarStat(int *varstat, int numvars);
91
92 // Set constat array for warmstart
93 //void setConStat(int *constat, int numrows);
94
95 private:
100 bool mustDelete_;
101
103 SolutionPtr sol_;
104
106 //int * constat_;
107
109 //int * varstat_;
110
112 int numCons_;
113 };
114
115
116// ----------------------------------------------------------------------- //
117// ----------------------------------------------------------------------- //
118
119
121 class CplexLPEngine : public LPEngine {
122 public:
123
124 //static int lazycallback(CPXCENVptr env, void *cbdata, int wherefrom,
125 //void *cbhandle, int *useraction_p);
126
127 void doNothing();
128
131
134
135 // Implement Engine::addConstraint().
137
138 // Change bounds on a constraint.
139 void changeBound(ConstraintPtr cons, BoundType lu, double new_val);
140
141 // Implement Engine::changeBound(VariablePtr, BoundType, double).
142 void changeBound(VariablePtr var, BoundType lu, double new_val);
143
144 // Implement Engine::changeBound(VariablePtr, double, double).
145 void changeBound(VariablePtr var, double new_lb, double new_ub);
146
147 // Implement Engine::changeConstraint().
149 double lb, double ub);
150
151 // Implement Engine::changeConstraint().
153
154 // change the objective function.
155 void changeObj(FunctionPtr f, double cb);
156
158 void clear();
159
160 void disableStrBrSetup();
161
164
165 void enableStrBrSetup();
166
167 // Implement Engine::fillStats()
168 void fillStats(std::vector<double> &);
169
171 double getSolutionValue();
172
173 // Implement Engine::getSolution().
175
176 // Implement Engine::getStatus().
178
179 // Return name of the solver.
180 std::string getName() const;
181
183
184 // Implement Engine::getWarmStartCopy().
186
192 void load(ProblemPtr problem);
193
195
196 // Convert 'min f' to 'min -f'.
197 void negateObj();
198
199 // Print a point x
200 void printx(double *, UInt );
201
202 // Print a point x
203 void printx(const int *, UInt );
204
205 // base class method.
206 void removeCons(std::vector<ConstraintPtr> &delcons);
207
208 // Implement Engine::resetIterationLimit().
209 void resetIterationLimit();
210
211 // Implement Engine::setIterationLimit().
212 void setIterationLimit(int);
213
214 // Implement Engine::setDualObjLimit().
215 int setDualObjLimit(double);
216
217 // Implement Engine::setTimeLimit().
218 void setTimeLimit(double);
219
220 // Implement the LP solve() function of Cplex
222
224 void writeLP(const char *filename) const;
225
227 void writeLP();
228
230 void writeStats(std::ostream &out) const;
231
232 private:
233
235 CPXENVptr cpxenv_;
236
238 CPXLPptr cpxlp_;
239
241 int cpxstatus_;
242
244 double timeLimit_;
245
248 bool bndChanged_;
249
251 bool consChanged_;
252
254 EnvPtr env_;
255
257 int maxIterLimit_;
258
260 static const std::string me_;
261
263 bool objChanged_;
264
266 double dualObjLimit_;
267
269 ProblemPtr problem_;
270
272 SolutionPtr sol_;
273
275 CplexLPStats *stats_;
276
278 bool strBr_;
279
282
284 Timer *timer_;
285
287 void load_();
288 };
289
290 typedef CplexLPEngine* CplexLPEnginePtr;
291}
292
293#endif
Declare the class LPEngine for solving LPs and getting solution.
The Constraint class is used to manage a constraint.
Definition: Constraint.h:61
The CplexLPEngine class can be called to solve LP problems.
Definition: CplexLPEngine.h:121
std::string getName() const
Get the name.
Definition: CplexLPEngine.cpp:304
~CplexLPEngine()
Destroy.
Definition: CplexLPEngine.cpp:128
void resetIterationLimit()
Reset the iteration limit to maximum possible.
Definition: CplexLPEngine.cpp:679
double getSolutionValue()
Return the solution value of the objective after solving the LP.
Definition: CplexLPEngine.cpp:310
void negateObj()
Negate the objective function. Min f is changed to Min -f.
Definition: CplexLPEngine.cpp:656
void clear()
Clear the problem.
Definition: CplexLPEngine.cpp:260
EngineStatus solve()
Solve the problem that was loaded previously.
Definition: CplexLPEngine.cpp:704
ConstSolutionPtr getSolution()
Get the solution obtained after solving the problem.
Definition: CplexLPEngine.cpp:316
WarmStartPtr getWarmStartCopy()
Definition: CplexLPEngine.cpp:328
void fillStats(std::vector< double > &)
Accumulate statistics from different threads in a common data.
Definition: CplexLPEngine.cpp:292
void changeBound(ConstraintPtr cons, BoundType lu, double new_val)
Change a bound of a constraint.
Definition: CplexLPEngine.cpp:200
CplexLPEngine(EnvPtr env)
Constructor with an environment.
Definition: CplexLPEngine.cpp:102
void load(ProblemPtr problem)
Definition: CplexLPEngine.cpp:357
int setDualObjLimit(double)
Set the dual objective limit.
Definition: CplexLPEngine.cpp:691
void removeCons(std::vector< ConstraintPtr > &delcons)
Delete constraints from the engine.
Definition: CplexLPEngine.cpp:662
EnginePtr emptyCopy()
Return an empty CplexLPEngine pointer.
Definition: CplexLPEngine.cpp:276
void loadFromWarmStart(const WarmStartPtr)
Definition: CplexLPEngine.h:194
EngineStatus getStatus()
Get the status of the last solve command.
Definition: CplexLPEngine.cpp:322
void enableStrBrSetup()
Make settings for strong branching.
Definition: CplexLPEngine.cpp:282
void addConstraint(ConstraintPtr)
Add a new constraint to the engine.
Definition: CplexLPEngine.cpp:160
void setIterationLimit(int)
Definition: CplexLPEngine.cpp:685
void writeStats(std::ostream &out) const
Write statistics.
Definition: CplexLPEngine.cpp:860
void changeConstraint(ConstraintPtr con, LinearFunctionPtr lf, double lb, double ub)
Change the linear function, and the bounds of a constraint.
Definition: CplexLPEngine.cpp:241
ConstWarmStartPtr getWarmStart()
Definition: CplexLPEngine.h:182
void disableStrBrSetup()
Restore settings after strong branching.
Definition: CplexLPEngine.cpp:266
void changeObj(FunctionPtr f, double cb)
Change objective function.
Definition: CplexLPEngine.cpp:254
void writeLP()
Writes an LP file in the directory of problem file.
Definition: CplexLPEngine.cpp:850
Class for saving and using Warm-start information in Cplex LP engine.
Definition: CplexLPEngine.h:49
~CpxLPWarmStart()
Destroy.
Definition: CplexLPEngine.cpp:51
void write(std::ostream &) const
Write to an output stream.
Definition: CplexLPEngine.h:72
bool hasInfo()
Return the soluton that can be used as starting point.
Definition: CplexLPEngine.cpp:65
CpxLPWarmStart()
Default constructor.
Definition: CplexLPEngine.cpp:42
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
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: CplexLPEngine.h:35
UInt strIters
Sum of number of iterations in all calls.
Definition: CplexLPEngine.h:41
UInt strCalls
Total number of calls to solve.
Definition: CplexLPEngine.h:37
UInt iters
time taken in strong branching alone.
Definition: CplexLPEngine.h:40
double time
Calls to solve while strong branching.
Definition: CplexLPEngine.h:38
double strTime
Sum of time taken in all calls to solve.
Definition: CplexLPEngine.h:39

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