Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
convar.h
Go to the documentation of this file.
1
31#pragma once
32
34
35#pragma GCC visibility push(default)
36namespace abacus {
37
38class Master;
39class Sub;
40class Variable;
41class Constraint;
42
43template<class BaseType, class CoType> class PoolSlot;
44template<class BaseType, class CoType> class PoolSlotRef;
45template<class BaseType, class CoType> class StandardPool;
46template<class BaseType, class CoType> class CutBuffer;
47
48
50
67
68 friend class PoolSlot<Constraint, Variable>;
69 friend class PoolSlot<Variable, Constraint>;
70 friend class PoolSlotRef<Constraint, Variable>;
71 friend class PoolSlotRef<Variable, Constraint>;
72 friend class StandardPool<Constraint, Variable>;
73 friend class StandardPool<Variable, Constraint>;
74 friend class CutBuffer<Constraint, Variable>;
75 friend class CutBuffer<Variable, Constraint>;
76 friend class Sub;
77
78public:
79
81
92 ConVar (Master *master, const Sub *sub, bool dynamic, bool local) :
93 master_(master),
94 sub_(sub),
95 expanded_(false),
96 nReferences_(0),
97 dynamic_(dynamic),
98 nActive_(0),
99 nLocks_(0),
100 local_(local)
101 { }
102
103 virtual ~ConVar();
104
105
107
110 bool active() const { return (nActive_ != 0); }
111
112
114 bool local() const { return local_; }
115
117 bool global() const { return !local_; }
118
119
121
125 virtual bool dynamic() const { return dynamic_; }
126
127
145
147 bool expanded() const { return expanded_; }
148
149
151
158 virtual void expand() const { }
159
161
168 virtual void compress() const { }
169
171
175 virtual bool deletable() const {
176 return !(nReferences_ || nLocks_);
177 }
178
180
182
194 virtual void print(std::ostream &out) const;
195
197
200 const Sub *sub() const { return sub_; }
201
202
204
207 void sub(Sub *sub) { sub_ = sub; }
208
209
211
229 virtual unsigned hashKey() const;
230
232
251 virtual const char *name() const;
252
254
272 virtual bool equal(const ConVar *cv) const;
273
275
280 virtual double rank() const { return 0; }
281
282protected:
283
285
287
290 const Sub *sub_;
291
292 mutable bool expanded_;
293
295
302
304
310
312
313 bool local_;
314
315private:
316
318
322 void _expand() const;
323
324
326
330 void _compress() const;
331
333
336 void activate() { ++nActive_; }
337
338
340
345 void deactivate();
346
348
352 int nReferences() const { return nReferences_; }
353
354
356
359 void addReference() { ++nReferences_; }
360
361
363
366 void removeReference();
367
378
380 bool locked() const { return (nLocks_ != 0); }
381
382
384 void lock() { ++nLocks_; }
385
386
388 void unlock();
389
391};
392
393
395{
396#ifdef OGDF_DEBUG
397 if (nActive_) {
398 Logger::ifout() << "ConVar::~ConVar(): constraint/variable still active: \ncounter = " << nActive_ << "\n";
399 }
400
401 if (nLocks_) {
402 Logger::ifout() << "ConVar::~ConVar(): constraint/variable has still " << nLocks_ << " locks\n";
403 }
404
405#ifndef OGDF_USE_ASSERT_EXCEPTIONS // do not throw exceptions in destructor
406 OGDF_ASSERT(nActive_ == 0);
407 OGDF_ASSERT(nLocks_ == 0);
408#endif
409#endif
410}
411
412
414{
415 OGDF_ASSERT(nActive_ != 0);
416 --nActive_;
417}
418
419
421{
422 if(--nReferences_ < 0) {
423 Logger::ifout() << "ConVar::removeReference : reference counter negative\n";
425 }
426}
427
428
429inline void ConVar::unlock()
430{
431 OGDF_ASSERT(nLocks_ != 0);
432 --nLocks_;
433}
434
435
436}
437#pragma GCC visibility pop
Base class of all other classes of ABACUS.
Definition abacusroot.h:69
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
bool expanded_
true, if expanded version of constraint/variables available.
Definition convar.h:292
virtual double rank() const
The function should return a rank associated with the constraint/variable.
Definition convar.h:280
virtual const char * name() const
Should return the name of the constraint/variable.
bool dynamic_
If this member is true then the constraint/variable can be also removed from the active formulation a...
Definition convar.h:301
int nReferences() const
Returns the number of references to the pool slot PoolSlotRef storing this constraint/variable.
Definition convar.h:352
virtual void expand() const
Expands a constraint/variable.
Definition convar.h:158
void unlock()
Removes one lock from the constraint/variable.
Definition convar.h:429
virtual void print(std::ostream &out) const
Writes the constraint/variable to the output stream out.
int nLocks_
The number of locks which have been set on the constraint/variable.
Definition convar.h:311
void _compress() const
Removes the expanded format of the constraint/variable.
void addReference()
Indicates that there is a new reference to the pool slot storing this constraint/variable.
Definition convar.h:359
void _expand() const
Tries to generate the expanded format of the constraint/variable.
void lock()
Adds an additional lock to the constraint/variable.
Definition convar.h:384
const Sub * sub() const
Returns a const pointer to the subproblem associated with the constraint/variable.
Definition convar.h:200
virtual bool equal(const ConVar *cv) const
Should compare if the constraint/variable is identical (in a mathematical sense) with the constraint/...
virtual ~ConVar()
Definition convar.h:394
bool global() const
Returns true if the constraint/variable is globally valid, false otherwise.
Definition convar.h:117
Master * master_
A pointer to the corresponding master of the optimization.
Definition convar.h:284
int nActive_
The number of active subproblems of which the constraint/variable belongs to the set of active constr...
Definition convar.h:309
void sub(Sub *sub)
Associates a new subproblem with the constraint/variable.
Definition convar.h:207
virtual bool deletable() const
Returns true if the constraint/variable can be destructed.
Definition convar.h:175
virtual void compress() const
Compresses a constraint/variable.
Definition convar.h:168
ConVar(Master *master, const Sub *sub, bool dynamic, bool local)
Creates an instance of type ConVar.
Definition convar.h:92
int nReferences_
The number of references to the pool slot the constraint is stored in.
Definition convar.h:294
void removeReference()
Is the counterpart of the function addReference() and indicates the removal of a reference to this co...
Definition convar.h:420
bool local() const
Returns true if the constraint/variable is only locally valid, false otherwise.
Definition convar.h:114
void deactivate()
Counterpart of activate().
Definition convar.h:413
bool active() const
Checks if the constraint/variable is active in at least one active subproblem.
Definition convar.h:110
virtual bool dynamic() const
Return true if the constraint/variable is dynamic.
Definition convar.h:125
void activate()
Must be called if the constraint/variable is added to the active formulation of an active subproblem.
Definition convar.h:336
bool locked() const
Returns true if at least one lock is set on the constraint/variable, false otherwise.
Definition convar.h:380
bool expanded() const
Returns true if the expanded format of a constraint/variable is available, false otherwise.
Definition convar.h:147
virtual unsigned hashKey() const
Should provide a key for the constraint/variable that can be used to insert it into a hash table.
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
Cut buffers.
Definition cutbuffer.h:53
The master of the optimization.
Definition master.h:70
Stores constraints and variables.
Definition poolslot.h:78
Stores a pointer to a pool slot with version number.
Definition poolslotref.h:55
Standard pools.
The subproblem.
Definition sub.h:69
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
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
#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