Main Page   Class Hierarchy   Compound List   File List   Contact   Download   Symbolic Constraints   Examples  

partition.h

00001 #ifndef SCIL_PARTITION_H
00002 #define SCIL_PARTITION_H
00003 #include <vector>
00004 #include <boost/graph/graph_traits.hpp>
00005 
00006 
00012 template<typename GraphTyp>
00013 class Partition {
00014    typedef typename boost::graph_traits<GraphTyp>::vertex_descriptor vertex_descriptor;
00015    typedef typename boost::graph_traits<GraphTyp>::vertex_iterator vertex_iter;
00016 
00017 public:
00018    Partition();
00019    Partition( GraphTyp& G );
00020    bool same_block(vertex_descriptor v, vertex_descriptor w);
00021    void union_blocks( vertex_descriptor v, vertex_descriptor w);
00022    Partition(const Partition& orig);
00023 
00024    template<typename T>
00025    friend std::ostream& operator<< (std::ostream& os, Partition<T> const& rhs);
00026    virtual ~Partition();
00027 
00028 private:
00029    std::vector<unsigned int> block;
00030 
00031 };
00032 
00036 template<typename GraphTyp>
00037 Partition<GraphTyp>::Partition(GraphTyp& G) : block( num_vertices(G) ) {
00038    for( unsigned int i=0; i<num_vertices(G); i++ )
00039       block[i] = i;
00040 }
00041 
00043 template<typename GraphTyp>
00044 bool Partition<GraphTyp>::same_block(vertex_descriptor v, vertex_descriptor w) {
00045    return block[v]==block[w];
00046 }
00047 
00049 template<typename GraphTyp>
00050 void Partition<GraphTyp>::union_blocks( vertex_descriptor v, vertex_descriptor w ) {
00051    for( unsigned int i=0; i<block.size(); i++ )
00052       if( block[i] = block[w] )
00053          block[i] = block[v];
00054 }
00055 
00057 template<typename GraphTyp>
00058 Partition<GraphTyp>::Partition() : block(0) {
00059 }
00060 
00062 template<typename GraphTyp>
00063 Partition<GraphTyp>::Partition(const Partition& orig) : block(orig.block) {
00064 }
00065 
00066 template<typename GraphTyp>
00067 Partition<GraphTyp>::~Partition() {
00068 }
00069 
00070 template<typename T>
00071 std::ostream& operator<< (std::ostream& os, Partition<T> const& part) {
00072    os << "Partition with " << part.block.size() << " elements" << std::endl;
00073    for( int i=0;i<part.block.size();i++)
00074       os << " (" << i << " <-> " << part.block[i] << ") ";
00075    return os << std::endl;
00076 }
00077 
00078 #endif  /* _PARTITION_H */
00079 
00080 
Generated on Mon Mar 28 22:03:49 2011 for SCIL by  doxygen 1.6.3