Minotaur 0.4.1
Docs for developers
CplexMILPEngine.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 MINOTAURCPLEXMILPENGINE_H
14#define MINOTAURCPLEXMILPENGINE_H
15//#include <ilcplex/ilocplex.h>
16#include <ilcplex/cplexx.h>
17#include <string.h>
18#include "MILPEngine.h"
19#include "STOAHandler.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
36 UInt calls;
37 double time;
38 };
39
41 class CplexMILPEngine : public MILPEngine {
42 public:
43
44 //static int lazycallback(CPXCENVptr env, void *cbdata, int wherefrom,
45 //void *cbhandle, int *useraction_p);
46
47 void doNothing();
48
51
54
55 // Implement Engine::addConstraint().
57
58 // Change bounds on a constraint.
59 void changeBound(ConstraintPtr cons, BoundType lu, double new_val);
60
61 // Implement Engine::changeBound(VariablePtr, BoundType, double).
62 void changeBound(VariablePtr var, BoundType lu, double new_val);
63
64 // Implement Engine::changeBound(VariablePtr, double, double).
65 void changeBound(VariablePtr var, double new_lb, double new_ub);
66
67 // Implement Engine::changeConstraint().
69 double lb, double ub);
70
71 // Implement Engine::changeConstraint().
73
74 // change the objective function.
75 void changeObj(FunctionPtr f, double cb);
76
78 void clear();
79
81
84
86
89
91 double getSolutionValue();
92
93 // Implement Engine::getSolution().
95
96 // Get a particular solution from solution pool (-1 fetches incumbent).
98
99 // Implement Engine::getStatus().
101
102 // get name.
103 std::string getName() const;
104
106
108
114 void load(ProblemPtr problem);
115
117
118 // Convert 'min f' to 'min -f'.
119 void negateObj();
120
121 // Print a point x
122 void printx(double *x, UInt size);
123
124 // base class method.
125 void removeCons(std::vector<ConstraintPtr> &delcons);
126
127 // Implement Engine::resetIterationLimit().
128 void resetIterationLimit();
129
130 // Implement Engine::setIterationLimit().
131 void setIterationLimit(int);
132
133 // Implement Engine::setDualObjLimit().
134 int setDualObjLimit(double) {return 1;};
135
136 // Implement Engine::setTimeLimit().
137 void setTimeLimit(double);
138
139 // Implement Engine::setUpperCutoff().
140 void setUpperCutoff(double);
141
142 // Implement the solve() function of Cplex
144
145 // Implement the solve() function for single tree OA with general
146 // callbacks
147 EngineStatus solveST(double* objLb, SolutionPtr* sol,
148 STOAHandlerPtr stoa_hand,
149 SolveStatus* solveStatus);
150
151 // Implement the solve() function for single tree OA with lazy cuts
152 // callback
153 EngineStatus solveSTLazy(double* objLb, SolutionPtr* sol,
154 STOAHandlerPtr stoa_hand,
155 SolveStatus* solveStatus);
156
158 void writeLP(const char *filename) const;
159
161 void writeLP();
162
164 void writeStats(std::ostream &out) const;
165
166 private:
167 /* This simple (CPLEX) routine frees up the pointer *ptr, and sets *ptr to NULL */
168 void free_(char **ptr);
169
171 CPXENVptr cpxenv_;
172
174 CPXLPptr cpxlp_;
175
177 int cpxstatus_;
178
180 double timeLimit_;
181
183 double upperCutoff_;
184
187 bool bndChanged_;
188
190 bool consChanged_;
191
193 EnvPtr env_;
194
196 int maxIterLimit_;
197
199 std::string mipStartFile_;
200
202 static const std::string me_;
203
205 bool objChanged_;
206
208 ProblemPtr problem_;
209
211 SolutionPtr sol_;
212
214 CplexMILPStats *stats_;
215
217 Timer *timer_;
218
220 bool writeMipStarts_;
221
223 void load_();
224 };
225
226 typedef CplexMILPEngine* CplexMILPEnginePtr;
227}
228
229#endif
Declare the class MILPEngine for solving MILPs and getting solution.
The Constraint class is used to manage a constraint.
Definition: Constraint.h:61
The CplexMILPEngine class can be called to solve MILP problems.
Definition: CplexMILPEngine.h:41
WarmStartPtr getWarmStartCopy()
Definition: CplexMILPEngine.h:107
void loadFromWarmStart(const WarmStartPtr)
Definition: CplexMILPEngine.h:116
ConstWarmStartPtr getWarmStart()
Definition: CplexMILPEngine.h:105
void setIterationLimit(int)
Definition: CplexMILPEngine.cpp:607
std::string getName() const
Get the name.
Definition: CplexMILPEngine.cpp:226
ConstSolutionPtr getSolutionFromPool(int index)
Get a particular solution from solution pool.
Definition: CplexMILPEngine.cpp:250
void resetIterationLimit()
Reset the iteration limit to maximum possible.
Definition: CplexMILPEngine.cpp:602
EnginePtr emptyCopy()
Return an empty CplexMILPEngine pointer.
Definition: CplexMILPEngine.cpp:220
void writeLP()
Writes an LP file in the directory of problem file.
Definition: CplexMILPEngine.cpp:1504
CplexMILPEngine(EnvPtr env)
Constructor with an environment.
Definition: CplexMILPEngine.cpp:50
void clear()
Clear the problem.
Definition: CplexMILPEngine.cpp:214
void load(ProblemPtr problem)
Definition: CplexMILPEngine.cpp:285
void setUpperCutoff(double)
Set upper cutoff for an iteration.
Definition: CplexMILPEngine.cpp:618
ConstSolutionPtr getSolution()
Get the solution obtained after solving the problem.
Definition: CplexMILPEngine.cpp:244
void writeStats(std::ostream &out) const
Write statistics.
Definition: CplexMILPEngine.cpp:1514
void enableStrBrSetup()
Make settings for strong branching.
Definition: CplexMILPEngine.h:85
void changeBound(ConstraintPtr cons, BoundType lu, double new_val)
Change a bound of a constraint.
Definition: CplexMILPEngine.cpp:154
void negateObj()
Negate the objective function. Min f is changed to Min -f.
Definition: CplexMILPEngine.cpp:591
~CplexMILPEngine()
Destroy.
Definition: CplexMILPEngine.cpp:69
void removeCons(std::vector< ConstraintPtr > &delcons)
Delete constraints from the engine.
Definition: CplexMILPEngine.cpp:596
void changeObj(FunctionPtr f, double cb)
Change objective function.
Definition: CplexMILPEngine.cpp:208
UInt getNumSols()
Get the number of solutions in solution pool after recent solve.
Definition: CplexMILPEngine.cpp:232
double getSolutionValue()
Return the solution value of the objective after solving the LP.
Definition: CplexMILPEngine.cpp:238
int setDualObjLimit(double)
Set the dual objective limit.
Definition: CplexMILPEngine.h:134
void addConstraint(ConstraintPtr)
Add a new constraint to the engine.
Definition: CplexMILPEngine.cpp:114
void changeConstraint(ConstraintPtr con, LinearFunctionPtr lf, double lb, double ub)
Change the linear function, and the bounds of a constraint.
Definition: CplexMILPEngine.cpp:195
void disableStrBrSetup()
Restore settings after strong branching.
Definition: CplexMILPEngine.h:80
void setTimeLimit(double)
Set time limit for an iteration.
Definition: CplexMILPEngine.cpp:612
EngineStatus getStatus()
Get the status of the last solve command.
Definition: CplexMILPEngine.cpp:274
EngineStatus solve()
Solve the problem that was loaded previously.
Definition: CplexMILPEngine.cpp:624
Definition: Engine.h:34
Definition: Environment.h:28
Definition: Function.h:37
The base class linear function is of the form c'x.
Definition: LinearFunction.h:31
Definition: MILPEngine.h:28
Base class for nonlinear functions.
Definition: NonlinearFunction.h:31
Definition: Problem.h:74
Handler for convex constraints, based on quesada-grossmann algorithm.
Definition: STOAHandler.h:44
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
SolveStatus
Different states an algorithm like branch-and-bound can be in.
Definition: Types.h:158
Statistics.
Definition: CplexMILPEngine.h:35
double time
Total number of calls to solve.
Definition: CplexMILPEngine.h:37

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