Minotaur 0.4.1
Docs for developers
SimplexQuadCutGen.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
14#ifndef MINOTAURSIMPLEXQUADCUTGEN_H
15#define MINOTAURSIMPLEXQUADCUTGEN_H
16
17#include "Constraint.h"
18#include "Environment.h"
19#include "LPEngine.h"
20#include "Problem.h"
21#include "Types.h"
22
23namespace Minotaur
24{
25class Relaxation;
26class Timer;
27typedef Relaxation* RelaxationPtr;
31 int ncol; // Number of columns in the simplex
32 int nrow; // Number of rows in the simplex
33 const double* colLower; // Lower bounds of the variables
34 const double* colUpper; // Upper bounds of the variables
35 const double* rowLower; // Lower bounds of the constraints
36 const double* rowUpper; // Upper bounds of the constraints
37 const double* rowRhs; // Right hand side of constraints
38 const double* origTab; // Original simplex tableau
39 const int* rowStart; // Vector of row starts
40 const int* indices; // Vector of indices
41 const int* rowLen; // Vector of row lengths
42};
43
44struct CutStats {
45 UInt gencuts; // Number of cuts generated
46 UInt cutsadded; // Number of cuts added
47 UInt numrounds; // Number of rounds of cutting
48 double time; // Time taken in cut generation
49};
50
51struct SimplexCut {
52 double* coef; // The linear function of the cut
53 double lb; // Lower Bound
54 double ub; // Upper Bound
55 double depth; // Depth of cut
56 SimplexCut() { }
58 {
59 if(coef) {
60 delete[] coef;
61 }
62 }
63 bool operator<(const SimplexCut& cut) const
64 {
65 return depth < cut.depth;
66 }
67 bool operator>(const SimplexCut& cut) const
68 {
69 return depth > cut.depth;
70 }
71};
72
73typedef std::map<int, std::pair<double, double>> SlackBound;
75typedef std::vector<SimplexCutPtr> SimplexCutVector;
76
78{
79public:
80 // Default Constructor
82
83 // Constructor
84 SimplexQuadCutGen(EnvPtr env, ProblemPtr p, LPEnginePtr lpe, double ub);
85
86 // Destructor
88
89 // disable factorization
90 void disableFactorization();
91
92 // Check whether cutting needs to be done or not
93 bool doCutting(double curlb);
94
95 // Generate the cuts that violate the given point
96 int generateCuts(RelaxationPtr rel, ConstSolutionPtr sol,
97 ConstraintVector& added);
98
99 // get preprocessing info from the simplex tableau
100 void preprocessSimplexTab();
101
102 void writeStats(std::ostream& out) const;
103
104private:
105 // Average sparsity of the relaxation. This is computed as the total number of
106 // nonzeros in the coefficient matrix divided by the number of constraints.
107 double avgSparsity_;
108
109 // Bounds after each round of cutting, will have max size of nrounds_
110 std::vector<int> bounds_;
111
112 // Environment pointer
113 EnvPtr env_;
114
115 // Feasibility Tolerance
116 double eTol_;
117
118 // Problem for which the cuts are generated
119 ProblemPtr p_;
120
121 // LP Engine to access the Simplex tableau
122 LPEnginePtr lpe_;
123
124 // max number of terms allowed in the cut
125 UInt maxTerms_;
126
127 // For printing msgs
128 static const std::string me_;
129
130 // Number of cuts generated
131 UInt ncuts_;
132
133 // Number of rounds after which improvement is checked
134 UInt nrounds_;
135
136 // Maximum cuts to add during an iteration
137 UInt maxCuts_;
138
139 // Maximum rounds after which not cutting will be done
140 UInt maxrounds_;
141
142 // Minimum allowed depth of cut for a cut to be added
143 double minDepth_;
144
145 // Minimum change in the bound for more cuts to be added
146 double minChangeFrac_;
147
148 // Cut statistics
149 CutStats stats_;
150
151 // To keep track of time
152 const Timer* timer_;
153
154 // Basic Tableau Info
155 TableauInfo* tabInfo_;
156
157 // Row index of the basic original variables in the tableau
158 // Key - index of the original variable which is basic
159 // Value - Row index of the corresponding variable
160 std::map<int, int> basicInd_;
161
162 // A vector of indices of non-basic original variables
163 std::vector<int> nbOrig_;
164
165 // Number of non-basic original variables
166 int nnbOrig_;
167
168 // A vector of indices of non-basic slack variables
169 std::vector<int> nbSlack_;
170
171 // Number of non-basic slack variables
172 int nnbSlack_;
173
174 // Lower and Upper bounds of the slack variables
175 SlackBound sb_;
176
177 // Upper bound at the current node
178 double ub_;
179
180 // variant we are solving
181 int variant_;
182
183 // \brief Add the generated cuts to the relaxation
184 // \param[in] cuts - The vector of cuts to be added to relaxation
185 // \param[in] rel - Relaxation to which the cuts needs to be added
186 // \param[in] x - The current LP solution
187 void addCutsToRel_(SimplexCutVector cuts, RelaxationPtr rel, const double* x,
188 UInt& ncuts, ConstraintVector& added);
189
190 // Calculate the depth of cut from the current point
191 void calcDepth_(SimplexCutVector cuts, const double* x);
192
193 // Delete tabInfo_. Called in the destructor.
194 void delTabInfo_();
195
196 // get basic info of the simplex tableau from the lp solver
197 void getBasicInfo_();
198
199 double getMin_(SimplexCutPtr cut, double rhs);
200
201 // get the bounds on the slack variables
202 void getSlackBounds_();
203
204 // get bounds on the linear terms. Called for calculating slack bounds.
205 void getTermBounds_(double coef, double vlb, double vub, double& lb,
206 double& ub);
207
208 void relaxConsBNB_(SimplexCutVector& cuts, ConstraintPtr c, const double* x,
209 RelaxationPtr rel);
210
211 int relaxTermBNB_(double coef, bool lower, double bl, double bu, double nl,
212 double nu, double& cb, double& cn, double& cnst,
213 bool under);
214
215 void slackSubstitute_(int slackInd, double coef, std::map<int, double>& row,
216 double& rhs);
217
218 void substituteAndRelax_(RelaxationPtr rel, const double* x,
219 VariablePtr bkeep, VariablePtr bsubst, double beta,
220 double* coefs, double& cutConst, bool under);
221
222 void sortVariables_();
223};
225} // namespace Minotaur
226#endif
227
Get information about a constraint in a given Problem.
Define the Environment class.
Declare the class LPEngine for solving LPs and getting solution.
Declare the base class Modification.
Declare important 'types' used in Minotaur.
The Constraint class is used to manage a constraint.
Definition: Constraint.h:61
Definition: Environment.h:28
Definition: LPEngine.h:29
Definition: Problem.h:74
Definition: Relaxation.h:53
Definition: SimplexQuadCutGen.h:78
Definition: Solution.h:30
Definition: Timer.h:40
Definition: Variable.h:31
Definition: ActiveNodeStore.h:20
unsigned int UInt
Unsigned integer.
Definition: Types.h:30
Definition: SimplexQuadCutGen.h:44
Definition: SimplexQuadCutGen.h:51
A structure to store info from the simplex tableau.
Definition: SimplexQuadCutGen.h:30

Minotaur source code documented by Doxygen 1.9.4 on Thu Apr 24 2025