Dune Core Modules (2.3.1)

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 // $Id$
4 #ifndef DUNE_AMG_DEPENDENCY_HH
5 #define DUNE_AMG_DEPENDENCY_HH
6 
7 
8 #include <bitset>
9 #include <ostream>
10 
11 #include "graph.hh"
12 #include "properties.hh"
13 #include <dune/common/propertymap.hh>
14 #include <dune/common/unused.hh>
15 
16 
17 namespace Dune
18 {
19  namespace Amg
20  {
39  {
40  friend std::ostream& operator<<(std::ostream& os, const EdgeProperties& props);
41  public:
43  enum {INFLUENCE, DEPEND, SIZE};
44 
45  private:
46 
47  std::bitset<SIZE> flags_;
48  public:
51 
53  std::bitset<SIZE>::reference operator[](std::size_t v);
54 
56  bool operator[](std::size_t v) const;
57 
63  bool depends() const;
64 
69  void setDepends();
70 
74  void resetDepends();
75 
80  bool influences() const;
81 
85  void setInfluences();
86 
90  void resetInfluences();
91 
96  bool isOneWay() const;
97 
102  bool isTwoWay() const;
103 
108  bool isStrong() const;
109 
113  void reset();
114 
118  void printFlags() const;
119  };
120 
127  friend std::ostream& operator<<(std::ostream& os, const VertexProperties& props);
128  public:
129  enum { ISOLATED, VISITED, FRONT, BORDER, SIZE };
130  private:
131 
133  std::bitset<SIZE> flags_;
134 
135  public:
138 
140  std::bitset<SIZE>::reference operator[](std::size_t v);
141 
143  bool operator[](std::size_t v) const;
144 
151  void setIsolated();
152 
156  bool isolated() const;
157 
161  void resetIsolated();
162 
166  void setVisited();
167 
171  bool visited() const;
172 
176  void resetVisited();
177 
181  void setFront();
182 
186  bool front() const;
187 
191  void resetFront();
192 
196  void setExcludedBorder();
197 
202  bool excludedBorder() const;
203 
207  void resetExcludedBorder();
208 
212  void reset();
213 
214  };
215 
216  template<typename G, std::size_t i>
217  class PropertyGraphVertexPropertyMap
218  : public RAPropertyMapHelper<typename std::bitset<VertexProperties::SIZE>::reference,
219  PropertyGraphVertexPropertyMap<G,i> >
220  {
221  public:
222 
223  typedef ReadWritePropertyMapTag Category;
224 
225  enum {
227  index = i
228  };
229 
233  typedef G Graph;
234 
238  typedef std::bitset<VertexProperties::SIZE> BitSet;
239 
243  typedef typename BitSet::reference Reference;
244 
248  typedef bool ValueType;
249 
253  typedef typename G::VertexDescriptor Vertex;
254 
260  : graph_(&g)
261  {}
262 
267  : graph_(0)
268  {}
269 
270 
275  Reference operator[](const Vertex& vertex) const
276  {
277  return graph_->getVertexProperties(vertex)[index];
278  }
279  private:
280  Graph* graph_;
281  };
282 
283  } // end namespace Amg
284 
285  template<typename G, typename EP, typename VM, typename EM>
286  struct PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >
287  {
288  typedef Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED> Type;
289  };
290 
291  template<typename G, typename EP, typename VM, typename EM>
292  typename PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >::Type
293  get(const Amg::VertexVisitedTag& tag, Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>& graph)
294  {
296  return Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED>(graph);
297  }
298 
299  namespace Amg
300  {
301  inline std::ostream& operator<<(std::ostream& os, const EdgeProperties& props)
302  {
303  return os << props.flags_;
304  }
305 
307  : flags_()
308  {}
309 
310  inline std::bitset<EdgeProperties::SIZE>::reference
312  {
313  return flags_[v];
314  }
315 
316  inline bool EdgeProperties::operator[](std::size_t i) const
317  {
318  return flags_[i];
319  }
320 
321  inline void EdgeProperties::reset()
322  {
323  flags_.reset();
324  }
325 
327  {
328  // Set the INFLUENCE bit
329  //flags_ |= (1<<INFLUENCE);
330  flags_.set(INFLUENCE);
331  }
332 
333  inline bool EdgeProperties::influences() const
334  {
335  // Test the INFLUENCE bit
336  return flags_.test(INFLUENCE);
337  }
338 
340  {
341  // Set the first bit.
342  //flags_ |= (1<<DEPEND);
343  flags_.set(DEPEND);
344  }
345 
347  {
348  // reset the first bit.
349  //flags_ &= ~(1<<DEPEND);
350  flags_.reset(DEPEND);
351  }
352 
353  inline bool EdgeProperties::depends() const
354  {
355  // Return the first bit.
356  return flags_.test(DEPEND);
357  }
358 
360  {
361  // reset the second bit.
362  flags_ &= ~(1<<INFLUENCE);
363  }
364 
365  inline bool EdgeProperties::isOneWay() const
366  {
367  // Test whether only the first bit is set
368  //return isStrong() && !isTwoWay();
369  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==(1<<DEPEND);
370  }
371 
372  inline bool EdgeProperties::isTwoWay() const
373  {
374  // Test whether the first and second bit is set
375  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==((1<<INFLUENCE)|(1<<DEPEND));
376  }
377 
378  inline bool EdgeProperties::isStrong() const
379  {
380  // Test whether the first or second bit is set
381  return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND))).to_ulong();
382  }
383 
384 
385  inline std::ostream& operator<<(std::ostream& os, const VertexProperties& props)
386  {
387  return os << props.flags_;
388  }
389 
391  : flags_()
392  {}
393 
394 
395  inline std::bitset<VertexProperties::SIZE>::reference
397  {
398  return flags_[v];
399  }
400 
401  inline bool VertexProperties::operator[](std::size_t v) const
402  {
403  return flags_[v];
404  }
405 
407  {
408  flags_.set(ISOLATED);
409  }
410 
411  inline bool VertexProperties::isolated() const
412  {
413  return flags_.test(ISOLATED);
414  }
415 
417  {
418  flags_.reset(ISOLATED);
419  }
420 
422  {
423  flags_.set(VISITED);
424  }
425 
426  inline bool VertexProperties::visited() const
427  {
428  return flags_.test(VISITED);
429  }
430 
432  {
433  flags_.reset(VISITED);
434  }
435 
437  {
438  flags_.set(FRONT);
439  }
440 
441  inline bool VertexProperties::front() const
442  {
443  return flags_.test(FRONT);
444  }
445 
447  {
448  flags_.reset(FRONT);
449  }
450 
452  {
453  flags_.set(BORDER);
454  }
455 
457  {
458  return flags_.test(BORDER);
459  }
460 
462  {
463  flags_.reset(BORDER);
464  }
465 
467  {
468  flags_.reset();
469  }
470 
472  }
473 }
474 #endif
Class representing the properties of an ede in the matrix graph.
Definition: dependency.hh:39
Class representing a node in the matrix graph.
Definition: dependency.hh:126
Provides classes for building the matrix graph.
std::ostream & operator<<(std::ostream &s, const array< T, N > &e)
Output operator for array.
Definition: array.hh:159
bool depends() const
Checks wether the vertex the edge points to depends on the vertex the edge starts.
Definition: dependency.hh:353
void resetFront()
Resets the front node flag.
Definition: dependency.hh:446
std::bitset< VertexProperties::SIZE > BitSet
The type of the bitset.
Definition: dependency.hh:238
bool isolated() const
Checks wether the node is isolated.
Definition: dependency.hh:411
bool ValueType
The value type.
Definition: dependency.hh:248
BitSet::reference Reference
The reference type.
Definition: dependency.hh:243
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:372
void setInfluences()
Marks the edge as one of which the start vertex by the end vertex.
Definition: dependency.hh:326
VertexProperties()
Constructor.
Definition: dependency.hh:390
void setDepends()
Marks the edge as one of which the end point depends on the starting point.
Definition: dependency.hh:339
PropertyGraphVertexPropertyMap()
Default constructor.
Definition: dependency.hh:266
PropertyGraphVertexPropertyMap(G &g)
Constructor.
Definition: dependency.hh:259
G::VertexDescriptor Vertex
The vertex descriptor.
Definition: dependency.hh:253
void resetExcludedBorder()
Marks the vertex as included in the aggregation.
Definition: dependency.hh:461
void setFront()
Marks the node as belonging to the current clusters front.
Definition: dependency.hh:436
void reset()
Reset all flags.
Definition: dependency.hh:466
void setVisited()
Mark the node as already visited.
Definition: dependency.hh:421
EdgeProperties()
Constructor.
Definition: dependency.hh:306
void resetInfluences()
Resets the influence flag.
Definition: dependency.hh:359
G Graph
The type of the graph with internal properties.
Definition: dependency.hh:233
std::bitset< SIZE >::reference operator[](std::size_t v)
Access the bits directly.
Definition: dependency.hh:396
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:333
void setIsolated()
Marks that node as being isolated.
Definition: dependency.hh:406
bool excludedBorder() const
Tests whether the vertex is excluded from the aggregation.
Definition: dependency.hh:456
void resetVisited()
Resets the visited flag.
Definition: dependency.hh:431
bool visited() const
Checks wether the node is marked as visited.
Definition: dependency.hh:426
Reference operator[](const Vertex &vertex) const
Get the properties associated to a vertex.
Definition: dependency.hh:275
void reset()
Reset all flags.
Definition: dependency.hh:321
void resetDepends()
Resets the depends flag.
Definition: dependency.hh:346
void resetIsolated()
Resets the isolated flag.
Definition: dependency.hh:416
bool isStrong() const
Checks wether the edge is strong. I.e. the influence or depends flag is set.
Definition: dependency.hh:378
bool front() const
Checks wether the node is marked as a front node.
Definition: dependency.hh:441
std::bitset< SIZE >::reference operator[](std::size_t v)
Access the bits directly.
Definition: dependency.hh:311
void setExcludedBorder()
Marks the vertex as excluded from the aggregation.
Definition: dependency.hh:451
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:365
Dune namespace.
Definition: alignment.hh:14
Provides classes for handling internal properties in a graph.
Tag for the category of readable and writable property maps.
Definition: propertymap.hh:51
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional 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 16, 22:29, 2024)