Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
constraint.h
Go to the documentation of this file.
1
30#pragma once
31
33
37
38
39#pragma GCC visibility push(default)
40namespace abacus {
41
42class Row;
43class Master;
44class Variable;
45class LpSub;
46
47template<class BaseType, class CoType> class Active;
48
49
51
58
59 friend class LpSub;
60
61public:
62
64
81 Master *master,
82 const Sub *sub,
83 CSense::SENSE sense,
84 double rhs,
85 bool dynamic,
86 bool local,
87 bool liftable);
88
89
91
98 Constraint (Master *master);
99
100
102
106 : ConVar(rhs), sense_(rhs.sense_), rhs_(rhs.rhs_), conClass_(nullptr), liftable_(rhs.liftable_)
107 {
108 if (rhs.conClass_) conClass_ = new ConClass(*(rhs.conClass_));
109 }
110
111
112 virtual ~Constraint() { delete conClass_; }
113
114
116 CSense *sense() { return &sense_; }
117
119 const CSense *sense() const { return &sense_; }
120
121
123
128 virtual double coeff(const Variable *v) const = 0;
129
131 virtual double rhs() const { return rhs_; }
132
133
135
141 bool liftable() const { return liftable_; }
142
143
145
154 virtual bool valid(Sub *sub) const;
155
156
158
172 Row &row) const;
173
175
181 virtual double slack(Active<Variable, Constraint> *variables,
182 double *x) const;
183
185
193 virtual bool violated(
194 Active<Variable, Constraint> *variables, double *x, double *sl = nullptr) const;
195
197
205 virtual bool violated(double slack) const;
206
208
212 void printRow(std::ostream &out, Active<Variable, Constraint> *var) const;
213
215
228 virtual double distance(double *x, Active<Variable, Constraint> *actVar) const;
229
230 //Constraint *duplicate() { return 0; }
231
233
241
242protected:
243
256 virtual InfeasCon::INFEAS voidLhsViolated(double newRhs) const;
257
262 return nullptr;
263 }
264
265
267
268 double rhs_;
269
270 mutable ConClass *conClass_; //this is just s cached-value, and hence can be set in const classify-call (it's nullptr initially, and computed upon first call
271
277
278private:
279 const Constraint &operator=(const Constraint &rhs);
280};
281
282}
283#pragma GCC visibility pop
284
285#include <ogdf/lib/abacus/sub.h>
287
288#pragma GCC visibility push(default)
289namespace abacus {
290
292 Master *master,
293 const Sub *sub,
294 CSense::SENSE sense,
295 double rhs,
296 bool dynamic,
297 bool local,
298 bool liftable)
299 : ConVar(master, sub, dynamic, local), sense_(sense), rhs_(rhs), conClass_(nullptr), liftable_(liftable)
300{
301 if (local && sub == nullptr) {
302 Logger::ifout() << "Constraint::Constraint(): subtree of local item must not be 0\n";
304 }
305}
306
307
309 : ConVar(master, nullptr, true, true), conClass_(nullptr) { }
310
311
312inline bool Constraint::valid(Sub *sub) const {
313 OGDF_ASSERT(!local_ || sub != nullptr);
314
315 return (!local_ || sub_->ancestor(sub));
316}
317
318}
319#pragma GCC visibility pop
Implements the sets of active constraints and variables which are associated with each subproblem.
Definition active.h:63
Sense of constraints.
Definition csense.h:49
Constraint classification.
Definition conclass.h:45
Common base class for constraints (Constraint) and variables (Variable).
Definition convar.h:66
const Sub * sub_
A pointer to the subproblem associated with the constraint/variable.
Definition convar.h:290
const Sub * sub() const
Returns a const pointer to the subproblem associated with the constraint/variable.
Definition convar.h:200
bool local() const
Returns true if the constraint/variable is only locally valid, false otherwise.
Definition convar.h:114
bool local_
true if the constraint/variable is only locally valid
Definition convar.h:313
Forms the virtual base class for all possible constraints given in pool format.
Definition constraint.h:57
bool liftable() const
Checks if the constraint is liftable.
Definition constraint.h:141
CSense sense_
The sense of the constraint.
Definition constraint.h:266
void printRow(std::ostream &out, Active< Variable, Constraint > *var) const
Writes the row format of the constraint associated with the variable set var to output stream out.
virtual double slack(Active< Variable, Constraint > *variables, double *x) const
Computes the slack of the vector x associated with the variable set variables.
bool liftable_
This member is true if also coefficients of variables which have been inactive at generation time can...
Definition constraint.h:276
CSense * sense()
Returns a pointer to the sense of the constraint.
Definition constraint.h:116
virtual bool violated(Active< Variable, Constraint > *variables, double *x, double *sl=nullptr) const
Checks if a constraint is violated by a vector x associated with a variable set.
Constraint(const Constraint &rhs)
Copy constructor.
Definition constraint.h:105
Constraint(Master *master, const Sub *sub, CSense::SENSE sense, double rhs, bool dynamic, bool local, bool liftable)
Initializes a constraint.
Definition constraint.h:291
virtual InfeasCon::INFEAS voidLhsViolated(double newRhs) const
Can be called if after variable elimination the left hand side of the constraint has become void and ...
ConClass * conClass_
Definition constraint.h:270
virtual ~Constraint()
Definition constraint.h:112
virtual int genRow(Active< Variable, Constraint > *var, Row &row) const
Generates the row format of the constraint associated with the variable set var.
virtual double coeff(const Variable *v) const =0
Returns the coefficient of the variable v in the constraint.
const Constraint & operator=(const Constraint &rhs)
const CSense * sense() const
Returns a const pointer to the sense of the constraint.
Definition constraint.h:119
ConClass * classification(Active< Variable, Constraint > *var=nullptr) const
Returns a pointer to the classification of the constraint.
virtual double distance(double *x, Active< Variable, Constraint > *actVar) const
Returns the Euclidean distance of x associated with variable set actVar to the hyperplane induced by ...
virtual bool valid(Sub *sub) const
Checks if the constraint is valid for the subproblem sub.
Definition constraint.h:312
double rhs_
The right hand side of the constraint.
Definition constraint.h:268
virtual ConClass * classify(Active< Variable, Constraint > *var) const
The default implementation returns a 0 pointer.
Definition constraint.h:261
virtual bool violated(double slack) const
Checks if a constraint is violated given the slack of a vector.
virtual double rhs() const
Returns the right hand side of the constraint.
Definition constraint.h:131
INFEAS
The different ways of infeasibility of a constraint.
Definition infeascon.h:56
The linear program of a subproblem.
Definition lpsub.h:62
The master of the optimization.
Definition master.h:70
Representation of constraints in the row format.
Definition row.h:52
The subproblem.
Definition sub.h:69
bool ancestor(const Sub *sub) const
Returns true if this subproblem is an ancestor of the subproblem sub, false otherwise.
Forms the virtual base class for all possible variables given in pool format.
Definition variable.h:60
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition exceptions.h:247
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition Logger.h:218
constraint classification.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
constraints and variables.
csense.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
Definition exceptions.h:58
infeasible constraints.
the master of the optimization.