Dune Core Modules (2.5.2)

dependency.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_AMG_DEPENDENCY_HH
4 #define DUNE_AMG_DEPENDENCY_HH
5 
6 
7 #include <bitset>
8 #include <ostream>
9 
10 #include "graph.hh"
11 #include "properties.hh"
12 #include <dune/common/propertymap.hh>
13 #include <dune/common/unused.hh>
14 
15 
16 namespace Dune
17 {
18  namespace Amg
19  {
38  {
39  friend std::ostream& operator<<(std::ostream& os, const EdgeProperties& props);
40  public:
42  enum {INFLUENCE, DEPEND, SIZE};
43 
44  private:
45 
46  std::bitset<SIZE> flags_;
47  public:
50 
52  std::bitset<SIZE>::reference operator[](std::size_t v);
53 
55  bool operator[](std::size_t v) const;
56 
62  bool depends() const;
63 
68  void setDepends();
69 
73  void resetDepends();
74 
79  bool influences() const;
80 
84  void setInfluences();
85 
89  void resetInfluences();
90 
95  bool isOneWay() const;
96 
101  bool isTwoWay() const;
102 
107  bool isStrong() const;
108 
112  void reset();
113 
117  void printFlags() const;
118  };
119 
126  friend std::ostream& operator<<(std::ostream& os, const VertexProperties& props);
127  public:
128  enum { ISOLATED, VISITED, FRONT, BORDER, SIZE };
129  private:
130 
132  std::bitset<SIZE> flags_;
133 
134  public:
137 
139  std::bitset<SIZE>::reference operator[](std::size_t v);
140 
142  bool operator[](std::size_t v) const;
143 
150  void setIsolated();
151 
155  bool isolated() const;
156 
160  void resetIsolated();
161 
165  void setVisited();
166 
170  bool visited() const;
171 
175  void resetVisited();
176 
180  void setFront();
181 
185  bool front() const;
186 
190  void resetFront();
191 
195  void setExcludedBorder();
196 
201  bool excludedBorder() const;
202 
206  void resetExcludedBorder();
207 
211  void reset();
212 
213  };
214 
215  template<typename G, std::size_t i>
216  class PropertyGraphVertexPropertyMap
217  : public RAPropertyMapHelper<typename std::bitset<VertexProperties::SIZE>::reference,
218  PropertyGraphVertexPropertyMap<G,i> >
219  {
220  public:
221 
222  typedef ReadWritePropertyMapTag Category;
223 
224  enum {
226  index = i
227  };
228 
232  typedef G Graph;
233 
237  typedef std::bitset<VertexProperties::SIZE> BitSet;
238 
242  typedef typename BitSet::reference Reference;
243 
247  typedef bool ValueType;
248 
252  typedef typename G::VertexDescriptor Vertex;
253 
259  : graph_(&g)
260  {}
261 
266  : graph_(0)
267  {}
268 
269 
274  Reference operator[](const Vertex& vertex) const
275  {
276  return graph_->getVertexProperties(vertex)[index];
277  }
278  private:
279  Graph* graph_;
280  };
281 
282  } // end namespace Amg
283 
284  template<typename G, typename EP, typename VM, typename EM>
285  struct PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >
286  {
287  typedef Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED> Type;
288  };
289 
290  template<typename G, typename EP, typename VM, typename EM>
291  typename PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >::Type
292  get(const Amg::VertexVisitedTag& tag, Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>& graph)
293  {
295  return Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED>(graph);
296  }
297 
298  namespace Amg
299  {
300  inline std::ostream& operator<<(std::ostream& os, const EdgeProperties& props)
301  {
302  return os << props.flags_;
303  }
304 
306  : flags_()
307  {}
308 
309  inline std::bitset<EdgeProperties::SIZE>::reference
311  {
312  return flags_[v];
313  }
314 
315  inline bool EdgeProperties::operator[](std::size_t i) const
316  {
317  return flags_[i];
318  }
319 
320  inline void EdgeProperties::reset()
321  {
322  flags_.reset();
323  }
324 
326  {
327  // Set the INFLUENCE bit
328  //flags_ |= (1<<INFLUENCE);
329  flags_.set(INFLUENCE);
330  }
331 
332  inline bool EdgeProperties::influences() const
333  {
334  // Test the INFLUENCE bit
335  return flags_.test(INFLUENCE);
336  }
337 
339  {
340  // Set the first bit.
341  //flags_ |= (1<<DEPEND);
342  flags_.set(DEPEND);
343  }
344 
346  {
347  // reset the first bit.
348  //flags_ &= ~(1<<DEPEND);
349  flags_.reset(DEPEND);
350  }
351 
352  inline bool EdgeProperties::depends() const
353  {
354  // Return the first bit.
355  return flags_.test(DEPEND);
356  }
357 
359  {
360  // reset the second bit.
361  flags_ &= ~(1<<INFLUENCE);
362  }
363 
364  inline bool EdgeProperties::isOneWay() const
365  {
366  // Test whether only the first bit is set
367  //return isStrong() && !isTwoWay();
368  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==(1<<DEPEND);
369  }
370 
371  inline bool EdgeProperties::isTwoWay() const
372  {
373  // Test whether the first and second bit is set
374  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==((1<<INFLUENCE)|(1<<DEPEND));
375  }
376 
377  inline bool EdgeProperties::isStrong() const
378  {
379  // Test whether the first or second bit is set
380  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND))).to_ulong();
381  }
382 
383 
384  inline std::ostream& operator<<(std::ostream& os, const VertexProperties& props)
385  {
386  return os << props.flags_;
387  }
388 
390  : flags_()
391  {}
392 
393 
394  inline std::bitset<VertexProperties::SIZE>::reference
396  {
397  return flags_[v];
398  }
399 
400  inline bool VertexProperties::operator[](std::size_t v) const
401  {
402  return flags_[v];
403  }
404 
406  {
407  flags_.set(ISOLATED);
408  }
409 
410  inline bool VertexProperties::isolated() const
411  {
412  return flags_.test(ISOLATED);
413  }
414 
416  {
417  flags_.reset(ISOLATED);
418  }
419 
421  {
422  flags_.set(VISITED);
423  }
424 
425  inline bool VertexProperties::visited() const
426  {
427  return flags_.test(VISITED);
428  }
429 
431  {
432  flags_.reset(VISITED);
433  }
434 
436  {
437  flags_.set(FRONT);
438  }
439 
440  inline bool VertexProperties::front() const
441  {
442  return flags_.test(FRONT);
443  }
444 
446  {
447  flags_.reset(FRONT);
448  }
449 
451  {
452  flags_.set(BORDER);
453  }
454 
456  {
457  return flags_.test(BORDER);
458  }
459 
461  {
462  flags_.reset(BORDER);
463  }
464 
466  {
467  flags_.reset();
468  }
469 
471  }
472 }
473 #endif
Class representing the properties of an ede in the matrix graph.
Definition: dependency.hh:38
Class representing a node in the matrix graph.
Definition: dependency.hh:125
Provides classes for building the matrix graph.
bool depends() const
Checks wether the vertex the edge points to depends on the vertex the edge starts.
Definition: dependency.hh:352
void resetFront()
Resets the front node flag.
Definition: dependency.hh:445
std::bitset< VertexProperties::SIZE > BitSet
The type of the bitset.
Definition: dependency.hh:237
bool isolated() const
Checks wether the node is isolated.
Definition: dependency.hh:410
bool ValueType
The value type.
Definition: dependency.hh:247
BitSet::reference Reference
The reference type.
Definition: dependency.hh:242
bool isTwoWay() const
Checks wether the edge is two way. I.e. both the influence flag and the depends flag are that.
Definition: dependency.hh:371
void setInfluences()
Marks the edge as one of which the start vertex by the end vertex.
Definition: dependency.hh:325
VertexProperties()
Constructor.
Definition: dependency.hh:389
void setDepends()
Marks the edge as one of which the end point depends on the starting point.
Definition: dependency.hh:338
PropertyGraphVertexPropertyMap()
Default constructor.
Definition: dependency.hh:265
PropertyGraphVertexPropertyMap(G &g)
Constructor.
Definition: dependency.hh:258
G::VertexDescriptor Vertex
The vertex descriptor.
Definition: dependency.hh:252
void resetExcludedBorder()
Marks the vertex as included in the aggregation.
Definition: dependency.hh:460
void setFront()
Marks the node as belonging to the current clusters front.
Definition: dependency.hh:435
void reset()
Reset all flags.
Definition: dependency.hh:465
void setVisited()
Mark the node as already visited.
Definition: dependency.hh:420
EdgeProperties()
Constructor.
Definition: dependency.hh:305
void resetInfluences()
Resets the influence flag.
Definition: dependency.hh:358
G Graph
The type of the graph with internal properties.
Definition: dependency.hh:232
std::bitset< SIZE >::reference operator[](std::size_t v)
Access the bits directly.
Definition: dependency.hh:395
void printFlags() const
Prints the attributes of the edge for debugging.
bool influences() const
Checks wether the start vertex is influenced by the end vertex.
Definition: dependency.hh:332
void setIsolated()
Marks that node as being isolated.
Definition: dependency.hh:405
bool excludedBorder() const
Tests whether the vertex is excluded from the aggregation.
Definition: dependency.hh:455
void resetVisited()
Resets the visited flag.
Definition: dependency.hh:430
bool visited() const
Checks wether the node is marked as visited.
Definition: dependency.hh:425
Reference operator[](const Vertex &vertex) const
Get the properties associated to a vertex.
Definition: dependency.hh:274
void reset()
Reset all flags.
Definition: dependency.hh:320
void resetDepends()
Resets the depends flag.
Definition: dependency.hh:345
void resetIsolated()
Resets the isolated flag.
Definition: dependency.hh:415
bool isStrong() const
Checks wether the edge is strong. I.e. the influence or depends flag is set.
Definition: dependency.hh:377
bool front() const
Checks wether the node is marked as a front node.
Definition: dependency.hh:440
std::bitset< SIZE >::reference operator[](std::size_t v)
Access the bits directly.
Definition: dependency.hh:310
void setExcludedBorder()
Marks the vertex as excluded from the aggregation.
Definition: dependency.hh:450
bool isOneWay() const
Checks wether the edge is one way. I.e. either the influence or the depends flag but is set.
Definition: dependency.hh:364
Dune namespace.
Definition: alignment.hh:11
Provides classes for handling internal properties in a graph.
Tag for the category of readable and writable property maps.
Definition: propertymap.hh:48
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 9, 22:29, 2024)