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

min_cut.h

00001 #include <boost/graph/graph_traits.hpp>
00002 #include <boost/graph/adjacency_matrix.hpp>
00003 #include <boost/graph/adjacency_list.hpp>
00004 #include <boost/graph/graph_concepts.hpp>
00005 #include <boost/type_traits/is_same.hpp>
00006 #include <boost/type_traits/is_base_and_derived.hpp>
00007 
00008 #ifndef MIN_CUT_H
00009 #define MIN_CUT_H
00010 
00011 using namespace std;
00012 using namespace boost;
00013 
00014 namespace SCIL {
00015 
00016 template <typename Graph>
00017 class MC {
00018    public:
00019       typedef graph_traits<Graph> GraphTraits;
00020       typedef typename GraphTraits::vertex_descriptor vertex_descriptor;
00021      int value;
00022      list<vertex_descriptor> nodes;
00023      MC()
00024         : value(0)
00025      {};
00026      MC(int val, list<vertex_descriptor> nod)
00027         : value(val) {
00028            nodes = nod;
00029         }
00030      ~MC() {
00031         nodes.clear();
00032      }
00033      MC<Graph>& operator= ( const MC<Graph>& x ) {
00034         value = x.value;
00035         nodes = x.nodes;
00036      }
00037 };
00038 
00040 /* See the paper 'A Simple Min-Cut Algorithm' (Journal of the ACM, Vol. 44,
00041    No. 4, July 1997, pp. 585-591) for a detailed description of the algorithm.
00042    You need to provide an undirected Graph and a map<edge_descriptor, int>
00043    that provides positive weights for all edges. 
00044    After that you can start the algorithm by calling the function run(), which
00045    will return a pair<int, list<vertex_descriptor> > containing the minimum 
00046    weight of the cut and the vertices in the min-cut in the list.
00047  */
00048 
00049 template <typename Graph>
00050 class MIN_CUT {
00051 
00052    public:
00053       MC<Graph> minCutOfPhase;
00054       MC<Graph> minCut;
00055 
00056    private:
00057       typedef graph_traits<Graph> GraphTraits;
00058       typedef typename GraphTraits::vertex_descriptor vertex_descriptor;
00059       typedef typename GraphTraits::edge_descriptor edge_descriptor;
00060       const Graph &G_ref; 
00061       Graph G; 
00062 
00063       map<vertex_descriptor, vertex_descriptor> GtoG_ref;
00065       map<vertex_descriptor, vertex_descriptor> merged_vertex;
00066       map<edge_descriptor, int> w; 
00067       set<vertex_descriptor> vertices_of_G; 
00068 
00070       /* The most tightly connected vertex with the set of previously most 
00071          tightly connected vertices is determined and added to the set until 
00072          just one vertex is left. The cut between this vertex and the set is a 
00073          possible minimum cut and returned to run() for evaluation.
00074        */
00075       void MinCutPhase();
00076 
00078       /* Vertex t is removed and edges of t are added to s. If an edge, which 
00079          should be added, already exists in s, the weights of both edges are 
00080          summed up. 
00081        */
00082       void contract(vertex_descriptor s, vertex_descriptor t);
00083 
00085       /* Since vertices in G might be merged, the function has to return a list
00086          and add all the vertices that have been merged into vertex t to it.
00087        */
00088       void getCutOfPhase(int w, vertex_descriptor t);
00089 
00090    public:
00092       /* Used to create an object of MIN_CUT. Furthermore a copy of the input-
00093          graph is created and some check for feasibility of input are run.
00094          G_ should be a reference to the graph and w_ a map, which maps all
00095          edges to their appropriate weight.
00096        */
00097       MIN_CUT(const Graph &G_, const map<edge_descriptor, int> &w_);
00098 
00100       /* This function returns the integer value of the minimum cut and a list
00101          of the vertices in the minimum cut.
00102          The actual algorithm is just executed for graphs with more than 2 
00103          vertices. For 2 vertices the solution is trivial and for less than 2 
00104          vertices there is no minimum cut.
00105        */
00106       void run();
00107 };
00108 
00109 #include "../../../src/core/min_cut.cc"
00110 
00111 }
00112 
00113 #endif
Generated on Mon Mar 28 22:03:49 2011 for SCIL by  doxygen 1.6.3