Minotaur 0.4.1
Docs for developers
PerspCon.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//
13#ifndef MINOTAURPERSPCON_H
14#define MINOTAURPERSPCON_H
15
16#include <map>
17#include <fstream>
18#include <string>
19#include <forward_list>
20#include <unordered_map>
21
22#include "Timer.h"
23#include "Types.h"
24#include "Problem.h"
25#include "Variable.h"
26#include "Relaxation.h"
27#include "Constraint.h"
28#include "Environment.h"
29
30namespace Minotaur {
31
32class PerspCon;
33typedef PerspCon* PerspConPtr;
34typedef const PerspCon* ConstPerspConPtr;
35
36typedef struct impliVarsInfo {
37 VariablePtr var;
38 std::vector<double> fixedVal;
39} impliVar;
40
41typedef struct prConsInfo {
42 UInt type; // 1 if singleton, 2 if hyperplane, 3 both
43 VariablePtr binVar;
44 ConstraintPtr cons;
45 bool binVal, bisect;
46 /* bisect = 1, if binVar in absent in cons, or present in only the linear part
47 * of cons with negative coefficient, or fixed x with z= 1 lies in the PR
48 * region
49 */
52
53} prCons;
54
55// MS: remove later.
56//struct prStats { // stats only for constraints
57 //UInt bvInLin; // # of times controlling bin var in linear part cons
58 //UInt bvInNlin; // # of times controlling bin var in nonlinear part cons
59 //UInt bvInBoth; // # of times controlling bin var in both parts of the cons
60 //UInt bvIsZ; // # of times controlling bin var is z
61 //UInt bvIsZ1; // # of times controlling bin var is 1-z
62 //UInt type1; // # of S1 type PR cons
63 //UInt type2; // # of S2 type PR cons
64 //UInt uniq; // # of unique bin vars in different PR cons;
65 //UInt varFixing0;
66 //UInt varFixing1;
67
69 //bool obvInLin, obvInNlin, obvIsZ, obvIsZ1, ouniq;
70//};
71
72typedef struct prObjInfo {
73 bool isPR = 0;
74 // type is always 2 (hyperplane)
75 VariablePtr binVar;
76 bool binVal, bisect;
79} prObj;
80
81class PerspCon {
82public:
84 PerspCon();
85
88
90 ~PerspCon();
91
93 void findPRCons();
94
96 std::vector<prCons> getPRCons() const {return prConsVec_;}
97
98 prObj getPRObj() const {return prObj_;}
99
100 bool getStatus();
101
102 void implications();
103
104 std::unordered_map<VariablePtr, std::forward_list<impliVar>> getImplications0()
105 {return impli0_;};
106
107 std::unordered_map<VariablePtr, std::forward_list<impliVar>> getImplications1()
108 {return impli1_;};
109
110private:
111 /*
112 * Checks if the variables in a constraint are bounded by given binary
113 * variable binvar.
114 */
115 bool boundBinVar_(bool &isBinFixed);
116
117 void checkBinPos_();
118
119 bool isControlled_(std::vector<VariablePtr> binaries);
120
121 /*
122 * Checks if variables in the linear part of a constraint are bounded by
123 * the given binary variable.
124 */
125
126 //void checkLVars_(bool *boundsok, VariablePtr var,
127 //std::unordered_map<UInt,double> *varsInfo);
128
129 /*
130 * Checks if variables in the nonlinear part of a constraint are bounded by
131 * a given binary variable.
132 */
133
134 //void checkNVars_(bool *boundsok, VariablePtr var,
135 //std::unordered_map<UInt,double> *varsInfo);
136
137 void removeSingleton_();
138
140 double checkVarBounds_(VariablePtr var, bool* varbounded);
141
142 /*
143 * Checks if a binary variable is present in the nonlinear part of the
144 * given constraint.
145 */
146 void findBinVarsInFunc_(std::vector<VariablePtr>* binaries);
147
149 void displayInfo_();
150
151
152 void deriveImpli_(VariablePtr var);
153
155 //void evalConstraint(ConstraintPtr cons);
156 void detect_();
157
159 //UInt getNumPersp_() const {return consVec_.size();}
160
161 /*
162 * Returns vector containing binary variables associated with constraints
163 * amenable to PR.
164 */
165 //std::vector<VariablePtr> getPRBinVar_() const {return bVarVec_;}
166
167
168
170 //std::vector<UInt> getPRStruct_() const {return sType_;}
171
172 /*
173 * Returns 1 if problem has at least one constraint amenable to PR,
174 * otherwise 0.
175 */
176
177 bool checkNVars_(double *x, VariableGroup &nVarVal);
178 bool checkLVars_(double *x, VariableGroup &lVarVal, VariableGroup &nVarVal, double &lval);
179
180 void delGUBList_();
181
182 bool twoTermsFunc_(ConstraintPtr c, VariablePtr var,
183 std::forward_list<impliVar> *varList, bool z);
184
185
186
187 bool multiTermsFunc_(ConstraintPtr c, VariablePtr var,
188 std::forward_list<impliVar> *varList,
189double val, bool z);
190
191 void fixBinaryVar_(VariablePtr var, bool z);
192
193 bool isBinary_(VariablePtr var);
194
195 void addImplications_(ConstraintPtr c, bool z0);
196
197 bool addImplications_(std::forward_list<impliVar> *varList);
198
199 void populate_(UInt type, VariableGroup nVarVal, VariableGroup lVarVal);
200
201 /* Returns a vector containing values to which variables in the
202 * linear part of the constraints amenable to PR are fixed to.
203 */
204 //std::vector<VariableGroup > getXLV() const {return lVarFixVal_;}
205
206 /* Returns a vector containing values to which variables in the
207 * nonlinear part of the constraints amenable to PR are fixed to.
208 */
209 //std::vector<VariableGroup > getXNV() const {return nlVarFixVal_;}
210
212 EnvPtr env_;
213
215 ProblemPtr p_;
216
218 LoggerPtr logger_;
219
220 double absTol_;
221
222 double relTol_;
223
225 Timer *timer_;
226
228 static const std::string me_;
229
230 ConstraintPtr cons_;
231
232 VariablePtr bVar_;
233
234 UInt sType_;
235
236 bool binVal_;
237
238 bool isObj_;
239
240 bool isInFunc_;
241
243 //std::vector<UInt> sType_;
244
246 //std::vector<ConstraintPtr> consVec_;
247
248 /* Vector of pointers to binary variables associated with constraints
249 * amenable to PR.
250 */
251 //std::vector<VariablePtr> bVarVec_;
252
254 //std::vector<VariablePtr> fixbvar_;
255
256 /* Vector containing values to which variables in the
257 * nonlinear part of a constraint amenable to PR are fixed to.
258 */
259 //std::vector<VariableGroup> nlVarFixVal_;
260
261 /* Returns a vector containing values to which variables in the
262 * linear part of a constraint amenable to PR are fixed to.
263 */
264 //std::vector<VariableGroup> lVarFixVal_;
265 //std::vector<std::unordered_map<UInt,double>> varsInfoVec_;
266
267 std::vector<prCons> prConsVec_;
268
269 prObj prObj_;
270
272 std::unordered_map<VariablePtr, std::forward_list<impliVar>> impli0_;
273 std::unordered_map<VariablePtr, std::forward_list<impliVar>> impli1_;
274
275 std::forward_list<ConstraintPtr > gubList0_;
276 std::forward_list<ConstraintPtr > gubList1_;
277
278 //prStats * stats_;
279
280 std::unordered_map<VariablePtr, std::forward_list<impliVar>>::iterator
281 iit_;
282};
283
284}
285
286#endif // MINOTAURPERSPCON_H
287
Get information about a constraint in a given Problem.
Define the Environment class.
Declare the base class Modification.
Declare the class Relaxation for storing and manipulating relaxations.
Define the TimerFactory and varios Timer classes.
Declare important 'types' used in Minotaur.
Define the Variable class.
The Constraint class is used to manage a constraint.
Definition: Constraint.h:61
Definition: Environment.h:28
Definition: PerspCon.h:81
PerspCon()
Default constructor.
Definition: PerspCon.cpp:34
~PerspCon()
Destructor.
Definition: PerspCon.cpp:87
std::vector< prCons > getPRCons() const
Returns a vector containing constraints amenable to PR.
Definition: PerspCon.h:96
void findPRCons()
Generates list of constraints amenable to PR.
Definition: PerspCon.cpp:1819
Definition: Problem.h:74
Definition: Variable.h:31
Definition: ActiveNodeStore.h:20
std::map< ConstVariablePtr, double, CompareVariablePtr > VariableGroup
Variables should always be constant within a group.
Definition: Types.h:511
unsigned int UInt
Unsigned integer.
Definition: Types.h:30
Definition: PerspCon.h:36
Definition: PerspCon.h:41
VariableGroup nNonzeroVar
Vector of variables in the nonlinear and linear parts that are fixed to non-zero values.
Definition: PerspCon.h:51
Definition: PerspCon.h:72
VariableGroup nNonzeroVar
Vector of variables in the nonlinear parts that are fixed to non-zero values.
Definition: PerspCon.h:78

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