Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

convar.h
Go to the documentation of this file.
1 
31 #pragma once
32 
34 
35 namespace abacus {
36 
37 class Master;
38 class Sub;
39 class Variable;
40 class Constraint;
41 
42 template<class BaseType, class CoType> class PoolSlot;
43 template<class BaseType, class CoType> class PoolSlotRef;
44 template<class BaseType, class CoType> class StandardPool;
45 template<class BaseType, class CoType> class CutBuffer;
46 
47 
49 
65 class OGDF_EXPORT ConVar : public AbacusRoot {
66 
67  friend class PoolSlot<Constraint, Variable>;
68  friend class PoolSlot<Variable, Constraint>;
73  friend class CutBuffer<Constraint, Variable>;
74  friend class CutBuffer<Variable, Constraint>;
75  friend class Sub;
76 
77 public:
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 
143 
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 
281 protected:
282 
284 
286 
289  const Sub *sub_;
290 
291  mutable bool expanded_;
292 
294 
300  bool dynamic_;
301 
303 
308  int nActive_;
309 
310  int nLocks_;
311 
312  bool local_;
313 
314 private:
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 
376 
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 
412 inline void ConVar::deactivate()
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 
428 inline void ConVar::unlock()
429 {
430  OGDF_ASSERT(nLocks_ != 0);
431  --nLocks_;
432 }
433 
434 
435 }
abacus::ConVar::local
bool local() const
Returns true if the constraint/variable is only locally valid, false otherwise.
Definition: convar.h:113
abacus::ConVar::addReference
void addReference()
Indicates that there is a new reference to the pool slot storing this constraint/variable.
Definition: convar.h:358
abacus::PoolSlotRef
Stores a pointer to a pool slot with version number.
Definition: active.h:40
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:199
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:419
abacusroot.h
abacus::ConVar::unlock
void unlock()
Removes one lock from the constraint/variable.
Definition: convar.h:428
abacus::CutBuffer
Cut buffers.
Definition: convar.h:45
abacus::ConVar::~ConVar
virtual ~ConVar()
Definition: convar.h:393
abacus::ConVar::deactivate
void deactivate()
Counterpart of activate().
Definition: convar.h:412
abacus
Definition: ILPClusterPlanarity.h:50
abacus::ConVar::sub_
const Sub * sub_
A pointer to the subproblem associated with the constraint/variable.
Definition: convar.h:289
abacus::ConVar::global
bool global() const
Returns true if the constraint/variable is globally valid, false otherwise.
Definition: convar.h:116
abacus::ConVar::locked
bool locked() const
Returns true if at least one lock is set on the constraint/variable, false otherwise.
Definition: convar.h:379
abacus::ConVar::nReferences
int nReferences() const
Returns the number of references to the pool slot PoolSlotRef storing this constraint/variable.
Definition: convar.h:351
abacus::ConVar::deletable
virtual bool deletable() const
Returns true if the constraint/variable can be destructed.
Definition: convar.h:174
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:335
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:65
abacus::ConVar::compress
virtual void compress() const
Compresses a constraint/variable.
Definition: convar.h:167
abacus::ConVar::dynamic
virtual bool dynamic() const
Return true if the constraint/variable is dynamic.
Definition: convar.h:124
abacus::AbacusRoot
Base class of all other classes of ABACUS.
Definition: abacusroot.h:68
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:109
abacus::ConVar::sub
void sub(Sub *sub)
Associates a new subproblem with the constraint/variable.
Definition: convar.h:206
abacus::ConVar::lock
void lock()
Adds an additional lock to the constraint/variable.
Definition: convar.h:383
abacus::Variable
Forms the virtual base class for all possible variables given in pool format.
Definition: variable.h:59
abacus::ConVar::master_
Master * master_
A pointer to the corresponding master of the optimization.
Definition: convar.h:283
abacus::ConVar::nLocks_
int nLocks_
The number of locks which have been set on the constraint/variable.
Definition: convar.h:310
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:157
abacus::ConVar::local_
bool local_
true if the constraint/variable is only locally valid
Definition: convar.h:312
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 DLL.
Definition: config.h:101
abacus::Sub
The subproblem.
Definition: sub.h:68
abacus::Constraint
Forms the virtual base class for all possible constraints given in pool format.
Definition: constraint.h:56
abacus::PoolSlot
Stores constraints and variables.
Definition: active.h:39
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:91
abacus::ConVar::rank
virtual double rank() const
The function should return a rank associated with the constraint/variable.
Definition: convar.h:279
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:308
abacus::ConVar::expanded_
bool expanded_
true, if expanded version of constraint/variables available.
Definition: convar.h:291
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:300
abacus::ConVar::nReferences_
int nReferences_
The number of references to the pool slot the constraint is stored in.
Definition: convar.h:293
abacus::ConVar::expanded
bool expanded() const
Returns true if the expanded format of a constraint/variable is available, false otherwise.
Definition: convar.h:146
abacus::Master
The master of the optimization.
Definition: master.h:69