Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
constraint.h
Go to the documentation of this file.
1
30#pragma once
31
33
37
38
39namespace abacus {
40
41class Row;
42class Master;
43class Variable;
44class LpSub;
45
46template<class BaseType, class CoType> class Active;
47
48
50
57
58 friend class LpSub;
59
60public:
61
63
80 Master *master,
81 const Sub *sub,
82 CSense::SENSE sense,
83 double rhs,
84 bool dynamic,
85 bool local,
86 bool liftable);
87
88
90
97 Constraint (Master *master);
98
99
101
105 : ConVar(rhs), sense_(rhs.sense_), rhs_(rhs.rhs_), conClass_(nullptr), liftable_(rhs.liftable_)
106 {
107 if (rhs.conClass_) conClass_ = new ConClass(*(rhs.conClass_));
108 }
109
110
111 virtual ~Constraint() { delete conClass_; }
112
113
115 CSense *sense() { return &sense_; }
116
118 const CSense *sense() const { return &sense_; }
119
120
122
127 virtual double coeff(const Variable *v) const = 0;
128
130 virtual double rhs() const { return rhs_; }
131
132
134
140 bool liftable() const { return liftable_; }
141
142
144
153 virtual bool valid(Sub *sub) const;
154
155
157
171 Row &row) const;
172
174
181 double *x) const;
182
184
192 virtual bool violated(
193 Active<Variable, Constraint> *variables, double *x, double *sl = nullptr) const;
194
196
204 virtual bool violated(double slack) const;
205
207
211 void printRow(std::ostream &out, Active<Variable, Constraint> *var) const;
212
214
227 virtual double distance(double *x, Active<Variable, Constraint> *actVar) const;
228
229 //Constraint *duplicate() { return 0; }
230
232
240
241protected:
242
256
261 return nullptr;
262 }
263
264
266
267 double rhs_;
268
269 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
270
276
277private:
278 const Constraint &operator=(const Constraint &rhs);
279};
280
281}
282
283#include <ogdf/lib/abacus/sub.h>
285
286namespace abacus {
287
289 Master *master,
290 const Sub *sub,
291 CSense::SENSE sense,
292 double rhs,
293 bool dynamic,
294 bool local,
295 bool liftable)
296 : ConVar(master, sub, dynamic, local), sense_(sense), rhs_(rhs), conClass_(nullptr), liftable_(liftable)
297{
298 if (local && sub == nullptr) {
299 Logger::ifout() << "Constraint::Constraint(): subtree of local item must not be 0\n";
301 }
302}
303
304
306 : ConVar(master, nullptr, true, true), conClass_(nullptr) { }
307
308
309inline bool Constraint::valid(Sub *sub) const {
310 OGDF_ASSERT(!local_ || sub != nullptr);
311
312 return (!local_ || sub_->ancestor(sub));
313}
314
315}
Implements the sets of active constraints and variables which are associated with each subproblem.
Definition active.h:62
Sense of constraints.
Definition csense.h:48
Constraint classification.
Definition conclass.h:44
Common base class for constraints (Constraint) and variables (Variable).
Definition convar.h:65
const Sub * sub_
A pointer to the subproblem associated with the constraint/variable.
Definition convar.h:289
const Sub * sub() const
Returns a const pointer to the subproblem associated with the constraint/variable.
Definition convar.h:199
bool local() const
Returns true if the constraint/variable is only locally valid, false otherwise.
Definition convar.h:113
bool local_
true if the constraint/variable is only locally valid
Definition convar.h:312
Forms the virtual base class for all possible constraints given in pool format.
Definition constraint.h:56
bool liftable() const
Checks if the constraint is liftable.
Definition constraint.h:140
CSense sense_
The sense of the constraint.
Definition constraint.h:265
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:275
CSense * sense()
Returns a pointer to the sense of the constraint.
Definition constraint.h:115
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:104
Constraint(Master *master, const Sub *sub, CSense::SENSE sense, double rhs, bool dynamic, bool local, bool liftable)
Initializes a constraint.
Definition constraint.h:288
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:269
virtual ~Constraint()
Definition constraint.h:111
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:118
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:309
double rhs_
The right hand side of the constraint.
Definition constraint.h:267
virtual ConClass * classify(Active< Variable, Constraint > *var) const
The default implementation returns a 0 pointer.
Definition constraint.h:260
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:130
INFEAS
The different ways of infeasibility of a constraint.
Definition infeascon.h:55
The linear program of a subproblem.
Definition lpsub.h:61
The master of the optimization.
Definition master.h:69
Representation of constraints in the row format.
Definition row.h:51
The subproblem.
Definition sub.h:68
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:59
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition exceptions.h:241
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition Logger.h:192
constraint classification.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
constraints and variables.
csense.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
Definition exceptions.h:54
infeasible constraints.
the master of the optimization.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()