Minotaur 0.4.1
Docs for developers
Constraint.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 MINOTAURCONSTRAINT_H
14#define MINOTAURCONSTRAINT_H
15
16#include <string>
17
18#include "Function.h"
19#include "Types.h"
20#include "Variable.h"
21
22namespace Minotaur
23{
24typedef std::set<std::pair<VariablePtr, FunctionType>>::const_iterator
25 VariableFunIterator;
26
61{
62public:
65 friend class Problem;
66 friend class PerspCon;
67 friend class TransSep;
68 friend class QGHandler;
69
71 Constraint();
72
87 Constraint(UInt id, UInt index, FunctionPtr f, double lb, double ub,
88 std::string name);
89
91 virtual ~Constraint();
92
94 double getActivity(const double* x, int* error) const;
95
97 bool getBFlag() const
98 {
99 return bTemp_;
100 }
101
102 int getITemp() const
103 {
104 return iTemp_;
105 }
106
107 void setITemp(int i)
108 {
109 iTemp_ = i;
110 }
111
112
115 {
116 return f_;
117 }
118
121
123 UInt getId() const
124 {
125 return id_;
126 }
127
130 {
131 return index_;
132 }
133
135 double getLb() const
136 {
137 return lb_;
138 }
139
142
143 // Get the name of the constraint.
144 const std::string getName() const;
145
148
151
154 {
155 return state_;
156 }
157
160 {
161 return src_;
162 }
163
164 ConsType getType() const
165 {
166 return type_;
167 }
168
170 double getUb() const
171 {
172 return ub_;
173 }
174
175 void setpId(UInt n)
176 {
177 pid_ = n;
178 }
179
180 int getpId()
181 {
182 return pid_;
183 }
184
185 void setUB(double newub)
186 {
187 ub_ = newub;
188 }
189
190 Convexity getConvexity()
191 {
192 return convex_;
193 }
194
195 void setConvexity(Convexity convex)
196 {
197 convex_ = convex;
198 }
199
200 void incrAct()
201 {
202 numAct_++;
203 }
204
206 void setBFlag(bool b)
207 {
208 bTemp_ = b;
209 }
210
213 {
214 src_ = src;
215 }
216
217 void setType(ConsType type)
218 {
219 type_ = type;
220 }
221
223 void write(std::ostream& out) const;
224
225protected:
227 void add_(double cb);
228
230 void changeLf_(LinearFunctionPtr lf);
231
233 void changeNlf_(NonlinearFunctionPtr nlf);
234
236 void delFixedVar_(VariablePtr v, double val);
237
246 void reverseSense_();
247
249 void setId_(UInt n)
250 {
251 id_ = n;
252 }
253
256 {
257 index_ = n;
258 }
259
266 void setLb_(double newlb)
267 {
268 lb_ = newlb;
269 }
270
272 void setName_(std::string name);
273
276 {
277 state_ = state;
278 return;
279 }
280
287 void setUb_(double newub)
288 {
289 ub_ = newub;
290 }
291
293 void subst_(VariablePtr out, VariablePtr in, double rat, bool* instay);
294
295private:
297 FunctionPtr f_;
298
299 UInt numAct_;
301 UInt id_;
302
304 //linearization (-1 for objective)
305 int pid_;
306
308 UInt index_;
309
311 double lb_;
312
314 std::string name_;
315
317 ConsSrcType src_;
318
320 ConsState state_;
321
323 ConsType type_;
324
326 bool bTemp_;
327
329 int iTemp_;
330
332 double ub_;
333
335 Convexity convex_;
336};
337} // namespace Minotaur
338#endif
339
Get information about a Function.
Declare important 'types' used in Minotaur.
Define the Variable class.
The Constraint class is used to manage a constraint.
Definition: Constraint.h:61
NonlinearFunctionPtr getNonlinearFunction() const
Get the nonlinear part of the constraint function 'f'.
Definition: Constraint.cpp:111
void setBFlag(bool b)
Set the value of the bool flag.
Definition: Constraint.h:206
ConsSrcType getSrcType() const
Get the src type of the constraint.
Definition: Constraint.h:159
void setIndex_(UInt n)
Set the index.
Definition: Constraint.h:255
FunctionPtr getFunction() const
Return a pointer to the function.
Definition: Constraint.h:114
void setUb_(double newub)
Set a new upper bound.
Definition: Constraint.h:287
ConsState getState() const
Get the current state of the constraint: freed, fixed etc.
Definition: Constraint.h:153
void subst_(VariablePtr out, VariablePtr in, double rat, bool *instay)
Substitute a variable by .
Definition: Constraint.cpp:134
double getLb() const
Get the 'l' value. or the lower bound constraint on 'f'.
Definition: Constraint.h:135
void changeNlf_(NonlinearFunctionPtr nlf)
Change the nonlinear part of constraint.
Definition: Constraint.cpp:70
LinearFunctionPtr getLinearFunction() const
Get the linear part of the constraint function 'f'.
Definition: Constraint.cpp:101
void write(std::ostream &out) const
display the constraint
Definition: Constraint.cpp:144
void setId_(UInt n)
Set the id.
Definition: Constraint.h:249
double getActivity(const double *x, int *error) const
Get the value or activity at a given point.
Definition: Constraint.cpp:91
bool getBFlag() const
Get the value of the bool flag.
Definition: Constraint.h:97
FunctionType getFunctionType() const
Get the function type.
Definition: Constraint.cpp:96
void setSrcType(ConsSrcType src)
Set src type.
Definition: Constraint.h:212
UInt getIndex() const
Return the index of the constraint.
Definition: Constraint.h:129
void delFixedVar_(VariablePtr v, double val)
Delete variables fixed at value val.
Definition: Constraint.cpp:75
Constraint()
Default constructor.
Definition: Constraint.cpp:23
double getUb() const
Get the 'u' value. or the upper bound constraint on 'f'.
Definition: Constraint.h:170
void setName_(std::string name)
Set name of the constraint.
Definition: Constraint.cpp:129
void setLb_(double newlb)
Set a new lower bound.
Definition: Constraint.h:266
UInt getId() const
Return the unique id of the constraint.
Definition: Constraint.h:123
void add_(double cb)
Add a constant to the constraint function. lb - c <= f <= ub - c.
Definition: Constraint.cpp:59
void reverseSense_()
Negate the constraint.
Definition: Constraint.cpp:121
void changeLf_(LinearFunctionPtr lf)
Change the linear part of constraint.
Definition: Constraint.cpp:65
QuadraticFunctionPtr getQuadraticFunction() const
Get the quadratic part of the constraint function 'f'.
Definition: Constraint.cpp:116
virtual ~Constraint()
Destroy.
Definition: Constraint.cpp:52
void setState_(ConsState state)
Set state of the constraint.
Definition: Constraint.h:275
Definition: Function.h:37
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: PerspCon.h:81
Definition: Problem.h:74
Handler for convex constraints, based on quesada-grossmann algorithm.
Definition: QGHandler.h:45
Definition: QuadraticFunction.h:38
Definition: TransSep.h:40
Definition: Variable.h:31
Definition: ActiveNodeStore.h:20
ConsSrcType
Where did the constraint originate from?
Definition: Types.h:94
unsigned int UInt
Unsigned integer.
Definition: Types.h:30
Convexity
Convexity of a function or a constraint.
Definition: Types.h:244
ConsType
Definition: Types.h:104
FunctionType
Different types of functions in Minotaur.
Definition: Types.h:65
ConsState
Different states a constraint can be in.
Definition: Types.h:145

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