dune-istl
2.1.1
|
00001 // $Id: dependency.hh 1296 2010-10-01 14:40:21Z robertk $ 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, BORDER, 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 setExcludedBorder(); 00194 00199 bool excludedBorder() const; 00200 00204 void resetExcludedBorder(); 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 } // end namespace Amg 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 inline 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 // Set the INFLUENCE bit 00325 //flags_ |= (1<<INFLUENCE); 00326 flags_.set(INFLUENCE); 00327 } 00328 00329 inline bool EdgeProperties::influences() const 00330 { 00331 // Test the INFLUENCE bit 00332 return flags_.test(INFLUENCE); 00333 } 00334 00335 inline void EdgeProperties::setDepends() 00336 { 00337 // Set the first bit. 00338 //flags_ |= (1<<DEPEND); 00339 flags_.set(DEPEND); 00340 } 00341 00342 inline void EdgeProperties::resetDepends() 00343 { 00344 // reset the first bit. 00345 //flags_ &= ~(1<<DEPEND); 00346 flags_.reset(DEPEND); 00347 } 00348 00349 inline bool EdgeProperties::depends() const 00350 { 00351 // Return the first bit. 00352 return flags_.test(DEPEND); 00353 } 00354 00355 inline void EdgeProperties::resetInfluences() 00356 { 00357 // reset the second bit. 00358 flags_ &= ~(1<<INFLUENCE); 00359 } 00360 00361 inline bool EdgeProperties::isOneWay() const 00362 { 00363 // Test whether only the first bit is set 00364 //return isStrong() && !isTwoWay(); 00365 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==(1<<DEPEND); 00366 } 00367 00368 inline bool EdgeProperties::isTwoWay() const 00369 { 00370 // Test whether the first and second bit is set 00371 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND)))==((1<<INFLUENCE)|(1<<DEPEND)); 00372 } 00373 00374 inline bool EdgeProperties::isStrong() const 00375 { 00376 // Test whether the first or second bit is set 00377 return ((flags_) & std::bitset<SIZE>((1<<INFLUENCE)|(1<<DEPEND))).to_ulong(); 00378 } 00379 00380 00381 inline std::ostream& operator<<(std::ostream& os, const VertexProperties& props) 00382 { 00383 return os << props.flags_; 00384 } 00385 00386 inline VertexProperties::VertexProperties() 00387 : flags_() 00388 {} 00389 00390 00391 inline std::bitset<VertexProperties::SIZE>::reference 00392 VertexProperties::operator[](std::size_t v) 00393 { 00394 return flags_[v]; 00395 } 00396 00397 inline bool VertexProperties::operator[](std::size_t v) const 00398 { 00399 return flags_[v]; 00400 } 00401 00402 inline void VertexProperties::setIsolated() 00403 { 00404 flags_.set(ISOLATED); 00405 } 00406 00407 inline bool VertexProperties::isolated() const 00408 { 00409 return flags_.test(ISOLATED); 00410 } 00411 00412 inline void VertexProperties::resetIsolated() 00413 { 00414 flags_.reset(ISOLATED); 00415 } 00416 00417 inline void VertexProperties::setVisited() 00418 { 00419 flags_.set(VISITED); 00420 } 00421 00422 inline bool VertexProperties::visited() const 00423 { 00424 return flags_.test(VISITED); 00425 } 00426 00427 inline void VertexProperties::resetVisited() 00428 { 00429 flags_.reset(VISITED); 00430 } 00431 00432 inline void VertexProperties::setFront() 00433 { 00434 flags_.set(FRONT); 00435 } 00436 00437 inline bool VertexProperties::front() const 00438 { 00439 return flags_.test(FRONT); 00440 } 00441 00442 inline void VertexProperties::resetFront() 00443 { 00444 flags_.reset(FRONT); 00445 } 00446 00447 inline void VertexProperties::setExcludedBorder() 00448 { 00449 flags_.set(BORDER); 00450 } 00451 00452 inline bool VertexProperties::excludedBorder() const 00453 { 00454 return flags_.test(BORDER); 00455 } 00456 00457 inline void VertexProperties::resetExcludedBorder() 00458 { 00459 flags_.reset(BORDER); 00460 } 00461 00462 inline void VertexProperties::reset() 00463 { 00464 flags_.reset(); 00465 } 00466 00468 } 00469 } 00470 #endif