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
35namespace abacus {
36
37class Master;
38class Sub;
39class Variable;
40class Constraint;
41
42template<class BaseType, class CoType> class PoolSlot;
43template<class BaseType, class CoType> class PoolSlotRef;
44template<class BaseType, class CoType> class StandardPool;
45template<class BaseType, class CoType> class CutBuffer;
46
47
49
66
67 friend class PoolSlot<Constraint, Variable>;
68 friend class PoolSlot<Variable, Constraint>;
69 friend class PoolSlotRef<Constraint, Variable>;
70 friend class PoolSlotRef<Variable, Constraint>;
71 friend class StandardPool<Constraint, Variable>;
72 friend class StandardPool<Variable, Constraint>;
73 friend class CutBuffer<Constraint, Variable>;
74 friend class CutBuffer<Variable, Constraint>;
75 friend class Sub;
76
77public:
78
80
91 ConVar (Master *master, const Sub *sub, bool dynamic, bool local) :
92 master_(master),
93 sub_(sub),
94 expanded_(false),
95 nReferences_(0),
96 dynamic_(dynamic),
97 nActive_(0),
98 nLocks_(0),
99 local_(local)
100 { }
101
102 virtual ~ConVar();
103
104
106
109 bool active() const { return (nActive_ != 0); }
110
111
113 bool local() const { return local_; }
114
116 bool global() const { return !local_; }
117
118
120
124 virtual bool dynamic() const { return dynamic_; }
125
126
144
146 bool expanded() const { return expanded_; }
147
148
150
157 virtual void expand() const { }
158
160
167 virtual void compress() const { }
168
170
174 virtual bool deletable() const {
175 return !(nReferences_ || nLocks_);
176 }
177
179
181
193 virtual void print(std::ostream &out) const;
194
196
199 const Sub *sub() const { return sub_; }
200
201
203
206 void sub(Sub *sub) { sub_ = sub; }
207
208
210
228 virtual unsigned hashKey() const;
229
231
250 virtual const char *name() const;
251
253
271 virtual bool equal(const ConVar *cv) const;
272
274
279 virtual double rank() const { return 0; }
280
281protected:
282
284
286
289 const Sub *sub_;
290
291 mutable bool expanded_;
292
294
301
303
309
311
312 bool local_;
313
314private:
315
317
321 void _expand() const;
322
323
325
329 void _compress() const;
330
332
335 void activate() { ++nActive_; }
336
337
339
344 void deactivate();
345
347
351 int nReferences() const { return nReferences_; }
352
353
355
358 void addReference() { ++nReferences_; }
359
360
362
365 void removeReference();
366
377
379 bool locked() const { return (nLocks_ != 0); }
380
381
383 void lock() { ++nLocks_; }
384
385
387 void unlock();
388
390};
391
392
394{
395#ifdef OGDF_DEBUG
396 if (nActive_) {
397 Logger::ifout() << "ConVar::~ConVar(): constraint/variable still active: \ncounter = " << nActive_ << "\n";
398 }
399
400 if (nLocks_) {
401 Logger::ifout() << "ConVar::~ConVar(): constraint/variable has still " << nLocks_ << " locks\n";
402 }
403
404#ifndef OGDF_USE_ASSERT_EXCEPTIONS // do not throw exceptions in destructor
405 OGDF_ASSERT(nActive_ == 0);
406 OGDF_ASSERT(nLocks_ == 0);
407#endif
408#endif
409}
410
411
413{
414 OGDF_ASSERT(nActive_ != 0);
415 --nActive_;
416}
417
418
420{
421 if(--nReferences_ < 0) {
422 Logger::ifout() << "ConVar::removeReference : reference counter negative\n";
424 }
425}
426
427
428inline void ConVar::unlock()
429{
430 OGDF_ASSERT(nLocks_ != 0);
431 --nLocks_;
432}
433
434
435}
Base class of all other classes of ABACUS.
Definition abacusroot.h:68
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
bool expanded_
true, if expanded version of constraint/variables available.
Definition convar.h:291
virtual double rank() const
The function should return a rank associated with the constraint/variable.
Definition convar.h:279
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:300
int nReferences() const
Returns the number of references to the pool slot PoolSlotRef storing this constraint/variable.
Definition convar.h:351
virtual void expand() const
Expands a constraint/variable.
Definition convar.h:157
void unlock()
Removes one lock from the constraint/variable.
Definition convar.h:428
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:310
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:358
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:383
const Sub * sub() const
Returns a const pointer to the subproblem associated with the constraint/variable.
Definition convar.h:199
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:393
bool global() const
Returns true if the constraint/variable is globally valid, false otherwise.
Definition convar.h:116
Master * master_
A pointer to the corresponding master of the optimization.
Definition convar.h:283
int nActive_
The number of active subproblems of which the constraint/variable belongs to the set of active constr...
Definition convar.h:308
void sub(Sub *sub)
Associates a new subproblem with the constraint/variable.
Definition convar.h:206
virtual bool deletable() const
Returns true if the constraint/variable can be destructed.
Definition convar.h:174
virtual void compress() const
Compresses a constraint/variable.
Definition convar.h:167
ConVar(Master *master, const Sub *sub, bool dynamic, bool local)
Creates an instance of type ConVar.
Definition convar.h:91
int nReferences_
The number of references to the pool slot the constraint is stored in.
Definition convar.h:293
void removeReference()
Is the counterpart of the function addReference() and indicates the removal of a reference to this co...
Definition convar.h:419
bool local() const
Returns true if the constraint/variable is only locally valid, false otherwise.
Definition convar.h:113
void deactivate()
Counterpart of activate().
Definition convar.h:412
bool active() const
Checks if the constraint/variable is active in at least one active subproblem.
Definition convar.h:109
virtual bool dynamic() const
Return true if the constraint/variable is dynamic.
Definition convar.h:124
void activate()
Must be called if the constraint/variable is added to the active formulation of an active subproblem.
Definition convar.h:335
bool locked() const
Returns true if at least one lock is set on the constraint/variable, false otherwise.
Definition convar.h:379
bool expanded() const
Returns true if the expanded format of a constraint/variable is available, false otherwise.
Definition convar.h:146
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:312
Forms the virtual base class for all possible constraints given in pool format.
Definition constraint.h:56
Cut buffers.
Definition cutbuffer.h:52
The master of the optimization.
Definition master.h:69
Stores constraints and variables.
Definition poolslot.h:77
Stores a pointer to a pool slot with version number.
Definition poolslotref.h:54
Standard pools.
The subproblem.
Definition sub.h:68
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
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
#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
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()