Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

convar.h
Go to the documentation of this file.
1 
31 #pragma once
32 
34 
35 #pragma GCC visibility push(default)
36 namespace abacus {
37 
38 class Master;
39 class Sub;
40 class Variable;
41 class Constraint;
42 
43 template<class BaseType, class CoType> class PoolSlot;
44 template<class BaseType, class CoType> class PoolSlotRef;
45 template<class BaseType, class CoType> class StandardPool;
46 template<class BaseType, class CoType> class CutBuffer;
47 
48 
50 
66 class OGDF_EXPORT ConVar : public AbacusRoot {
67 
68  friend class PoolSlot<Constraint, Variable>;
69  friend class PoolSlot<Variable, Constraint>;
74  friend class CutBuffer<Constraint, Variable>;
75  friend class CutBuffer<Variable, Constraint>;
76  friend class Sub;
77 
78 public:
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 
144 
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 
282 protected:
283 
285 
287 
290  const Sub *sub_;
291 
292  mutable bool expanded_;
293 
295 
301  bool dynamic_;
302 
304 
309  int nActive_;
310 
311  int nLocks_;
312 
313  bool local_;
314 
315 private:
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 
377 
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 
413 inline void ConVar::deactivate()
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 
429 inline void ConVar::unlock()
430 {
431  OGDF_ASSERT(nLocks_ != 0);
432  --nLocks_;
433 }
434 
435 
436 }
437 #pragma GCC visibility pop
abacus::ConVar::local
bool local() const
Returns true if the constraint/variable is only locally valid, false otherwise.
Definition: convar.h:114
abacus::ConVar::addReference
void addReference()
Indicates that there is a new reference to the pool slot storing this constraint/variable.
Definition: convar.h:359
abacus::PoolSlotRef
Stores a pointer to a pool slot with version number.
Definition: active.h:41
ogdf::internal::gcm::tools::equal
bool equal(const node a, const node b)
Definition: Universal.h:44
abacus::ConVar::sub
const Sub * sub() const
Returns a const pointer to the subproblem associated with the constraint/variable.
Definition: convar.h:200
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
abacus::ConVar::removeReference
void removeReference()
Is the counterpart of the function addReference() and indicates the removal of a reference to this co...
Definition: convar.h:420
abacusroot.h
abacus::ConVar::unlock
void unlock()
Removes one lock from the constraint/variable.
Definition: convar.h:429
abacus::CutBuffer
Cut buffers.
Definition: convar.h:46
abacus::ConVar::~ConVar
virtual ~ConVar()
Definition: convar.h:394
abacus::ConVar::deactivate
void deactivate()
Counterpart of activate().
Definition: convar.h:413
abacus
Definition: ILPClusterPlanarity.h:50
abacus::ConVar::sub_
const Sub * sub_
A pointer to the subproblem associated with the constraint/variable.
Definition: convar.h:290
abacus::ConVar::global
bool global() const
Returns true if the constraint/variable is globally valid, false otherwise.
Definition: convar.h:117
abacus::ConVar::locked
bool locked() const
Returns true if at least one lock is set on the constraint/variable, false otherwise.
Definition: convar.h:380
abacus::ConVar::nReferences
int nReferences() const
Returns the number of references to the pool slot PoolSlotRef storing this constraint/variable.
Definition: convar.h:352
abacus::ConVar::deletable
virtual bool deletable() const
Returns true if the constraint/variable can be destructed.
Definition: convar.h:175
abacus::StandardPool
Standard pools.
Definition: ILPClusterPlanarity.h:52
abacus::ConVar::activate
void activate()
Must be called if the constraint/variable is added to the active formulation of an active subproblem.
Definition: convar.h:336
ogdf::AlgorithmFailureException
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition: exceptions.h:247
ogdf::AlgorithmFailureCode::Constraint
@ Constraint
abacus::ConVar
Common base class for constraints (Constraint) and variables (Variable).
Definition: convar.h:66
abacus::ConVar::compress
virtual void compress() const
Compresses a constraint/variable.
Definition: convar.h:168
abacus::ConVar::dynamic
virtual bool dynamic() const
Return true if the constraint/variable is dynamic.
Definition: convar.h:125
abacus::AbacusRoot
Base class of all other classes of ABACUS.
Definition: abacusroot.h:69
ogdf::AlgorithmFailureCode::Convar
@ Convar
abacus::ConVar::active
bool active() const
Checks if the constraint/variable is active in at least one active subproblem.
Definition: convar.h:110
abacus::ConVar::sub
void sub(Sub *sub)
Associates a new subproblem with the constraint/variable.
Definition: convar.h:207
abacus::ConVar::lock
void lock()
Adds an additional lock to the constraint/variable.
Definition: convar.h:384
abacus::Variable
Forms the virtual base class for all possible variables given in pool format.
Definition: variable.h:60
abacus::ConVar::master_
Master * master_
A pointer to the corresponding master of the optimization.
Definition: convar.h:284
abacus::ConVar::nLocks_
int nLocks_
The number of locks which have been set on the constraint/variable.
Definition: convar.h:311
OGDF_THROW_PARAM
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
Definition: exceptions.h:71
abacus::ConVar::expand
virtual void expand() const
Expands a constraint/variable.
Definition: convar.h:158
abacus::ConVar::local_
bool local_
true if the constraint/variable is only locally valid
Definition: convar.h:313
ogdf::Logger::ifout
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition: Logger.h:218
ogdf::AlgorithmFailureCode::Variable
@ Variable
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition: config.h:117
abacus::Sub
The subproblem.
Definition: sub.h:69
abacus::Constraint
Forms the virtual base class for all possible constraints given in pool format.
Definition: constraint.h:57
abacus::PoolSlot
Stores constraints and variables.
Definition: active.h:40
ogdf::print
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
Definition: Array.h:972
abacus::ConVar::ConVar
ConVar(Master *master, const Sub *sub, bool dynamic, bool local)
Creates an instance of type ConVar.
Definition: convar.h:92
abacus::ConVar::rank
virtual double rank() const
The function should return a rank associated with the constraint/variable.
Definition: convar.h:280
ogdf::AlgorithmFailureCode::StandardPool
@ StandardPool
abacus::ConVar::nActive_
int nActive_
The number of active subproblems of which the constraint/variable belongs to the set of active constr...
Definition: convar.h:309
abacus::ConVar::expanded_
bool expanded_
true, if expanded version of constraint/variables available.
Definition: convar.h:292
abacus::ConVar::dynamic_
bool dynamic_
If this member is true then the constraint/variable can be also removed from the active formulation a...
Definition: convar.h:301
abacus::ConVar::nReferences_
int nReferences_
The number of references to the pool slot the constraint is stored in.
Definition: convar.h:294
abacus::ConVar::expanded
bool expanded() const
Returns true if the expanded format of a constraint/variable is available, false otherwise.
Definition: convar.h:147
abacus::Master
The master of the optimization.
Definition: master.h:70