dependency.hh
Go to the documentation of this file.00001
00002 #ifndef DUNE_AMG_DEPENDENCY_HH
00003 #define DUNE_AMG_DEPENDENCY_HH
00004
00005
00006 #include<bitset>
00007 #include<ostream>
00008
00009 #include "graph.hh"
00010 #include "properties.hh"
00011 #include <dune/common/propertymap.hh>
00012
00013
00014 namespace Dune
00015 {
00016 namespace Amg
00017 {
00035 class EdgeProperties
00036 {
00037 friend std::ostream& operator<<(std::ostream& os, const EdgeProperties& props);
00038 public:
00040 enum{INFLUENCE, DEPEND, SIZE};
00041
00042 private:
00043
00044 std::bitset<SIZE> flags_;
00045 public:
00047 EdgeProperties();
00048
00050 std::bitset<SIZE>::reference operator[](std::size_t v);
00051
00053 bool operator[](std::size_t v)const;
00054
00060 bool depends() const;
00061
00066 void setDepends();
00067
00071 void resetDepends();
00072
00077 bool influences() const;
00078
00082 void setInfluences();
00083
00087 void resetInfluences();
00088
00093 bool isOneWay() const;
00094
00099 bool isTwoWay() const;
00100
00105 bool isStrong() const;
00106
00110 void reset();
00111
00115 void printFlags() const;
00116 };
00117
00123 class VertexProperties{
00124 friend std::ostream& operator<<(std::ostream& os, const VertexProperties& props);
00125 public:
00126 enum{ ISOLATED, VISITED, FRONT, SIZE };
00127 private:
00128
00130 std::bitset<SIZE> flags_;
00131
00132 public:
00134 VertexProperties();
00135
00137 std::bitset<SIZE>::reference operator[](std::size_t v);
00138
00140 bool operator[](std::size_t v) const;
00141
00148 void setIsolated();
00149
00153 bool isolated() const;
00154
00158 void resetIsolated();
00159
00163 void setVisited();
00164
00168 bool visited() const;
00169
00173 void resetVisited();
00174
00178 void setFront();
00179
00183 bool front() const;
00184
00188 void resetFront();
00189
00193 void setExcluded();
00194
00199 bool excluded() const;
00200
00204 void resetExcluded();
00205
00209 void reset();
00210
00211 };
00212
00213 template<typename G, std::size_t i>
00214 class PropertyGraphVertexPropertyMap
00215 : public RAPropertyMapHelper<typename std::bitset<VertexProperties::SIZE>::reference,
00216 PropertyGraphVertexPropertyMap<G,i> >
00217 {
00218 public:
00219
00220 typedef ReadWritePropertyMapTag Category;
00221
00222 enum{
00224 index = i
00225 };
00226
00230 typedef G Graph;
00231
00235 typedef std::bitset<VertexProperties::SIZE> BitSet;
00236
00240 typedef typename BitSet::reference Reference;
00241
00245 typedef bool ValueType;
00246
00250 typedef typename G::VertexDescriptor Vertex;
00251
00256 PropertyGraphVertexPropertyMap(G& g)
00257 : graph_(&g)
00258 {}
00259
00263 PropertyGraphVertexPropertyMap()
00264 :graph_(0)
00265 {}
00266
00267
00272 Reference operator[](const Vertex& vertex) const
00273 {
00274 return graph_->getVertexProperties(vertex)[index];
00275 }
00276 private:
00277 Graph* graph_;
00278 };
00279
00280 }
00281
00282 template<typename G, typename EP, typename VM, typename EM>
00283 struct PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >
00284 {
00285 typedef Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED> Type;
00286 };
00287
00288 template<typename G, typename EP, typename VM, typename EM>
00289 typename PropertyMapTypeSelector<Amg::VertexVisitedTag,Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM> >::Type
00290 get(const Amg::VertexVisitedTag& tag, Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>& graph)
00291 {
00292 return Amg::PropertyGraphVertexPropertyMap<Amg::PropertiesGraph<G,Amg::VertexProperties,EP,VM,EM>, Amg::VertexProperties::VISITED>(graph);
00293 }
00294
00295 namespace Amg
00296 {
00297 inline std::ostream& operator<<(std::ostream& os, const EdgeProperties& props)
00298 {
00299 return os << props.flags_;
00300 }
00301
00302 EdgeProperties::EdgeProperties()
00303 : flags_()
00304 {}
00305
00306 inline std::bitset<EdgeProperties::SIZE>::reference
00307 EdgeProperties::operator[](std::size_t v)
00308 {
00309 return flags_[v];
00310 }
00311
00312 inline bool EdgeProperties::operator[](std::size_t i) const
00313 {
00314 return flags_[i];
00315 }
00316
00317 inline void EdgeProperties::reset()
00318 {
00319 flags_.reset();
00320 }
00321
00322 inline void EdgeProperties::setInfluences()
00323 {
00324
00325
00326 flags_.set(INFLUENCE);
00327 }
00328
00329 inline bool EdgeProperties::influences() const
00330 {
00331
00332 return flags_.test(INFLUENCE);
00333 }
00334
00335 inline void EdgeProperties::setDepends()
00336 {
00337
00338
00339 flags_.set(DEPEND);
00340 }
00341
00342 inline void EdgeProperties::resetDepends()
00343 {
00344
00345
00346 flags_.reset(DEPEND);
00347 }
00348
00349 inline bool EdgeProperties::depends() const
00350 {
00351
00352 return flags_.test(DEPEND);
00353 }
00354
00355 inline void EdgeProperties::resetInfluences()
00356 {
00357
00358 flags_ &= ~(1<<INFLUENCE);
00359 }
00360
00361 inline bool EdgeProperties::isOneWay() const
00362 {
00363
00364 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==(1<<DEPEND);
00365 }
00366
00367 inline bool EdgeProperties::isTwoWay() const
00368 {
00369
00370 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==((1<<INFLUENCE)|(1<<DEPEND));
00371 }
00372
00373 inline bool EdgeProperties::isStrong() const
00374 {
00375
00376 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND))).to_ulong();
00377 }
00378
00379
00380 inline std::ostream& operator<<(std::ostream& os, const VertexProperties& props)
00381 {
00382 return os << props.flags_;
00383 }
00384
00385 inline VertexProperties::VertexProperties()
00386 : flags_()
00387 {}
00388
00389
00390 inline std::bitset<VertexProperties::SIZE>::reference
00391 VertexProperties::operator[](std::size_t v)
00392 {
00393 return flags_[v];
00394 }
00395
00396 inline bool VertexProperties::operator[](std::size_t v) const
00397 {
00398 return flags_[v];
00399 }
00400
00401 inline void VertexProperties::setIsolated()
00402 {
00403 flags_.set(ISOLATED);
00404 }
00405
00406 inline bool VertexProperties::isolated() const
00407 {
00408 return flags_.test(ISOLATED);
00409 }
00410
00411 inline void VertexProperties::resetIsolated()
00412 {
00413 flags_.reset(ISOLATED);
00414 }
00415
00416 inline void VertexProperties::setVisited()
00417 {
00418 flags_.set(VISITED);
00419 }
00420
00421 inline bool VertexProperties::visited() const
00422 {
00423 return flags_.test(VISITED);
00424 }
00425
00426 inline void VertexProperties::resetVisited()
00427 {
00428 flags_.reset(VISITED);
00429 }
00430
00431 inline void VertexProperties::setFront()
00432 {
00433 flags_.set(FRONT);
00434 }
00435
00436 inline bool VertexProperties::front() const
00437 {
00438 return flags_.test(FRONT);
00439 }
00440
00441 inline void VertexProperties::resetFront()
00442 {
00443 flags_.reset(FRONT);
00444 }
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461 inline void VertexProperties::reset()
00462 {
00463 flags_.reset();
00464 }
00465
00467 }
00468 }
00469 #endif