Check StaticGraphSkeleton, as well.
2 #ifndef HUGO_MAX_BIPARTITE_MATCHING_H
3 #define HUGO_MAX_BIPARTITE_MATCHING_H
7 /// \brief Maximum bipartite matchings, b-matchings and
8 /// capacitated b-matchings.
10 /// This file contains a class for bipartite maximum matching, b-matchings
11 /// and capacitated b-matching computations.
13 // /// \author Marton Makai
15 //#include <for_each_macros.h>
16 #include <bipartite_graph_wrapper.h>
17 //#include <hugo/maps.h>
22 // template <typename Graph, typename EdgeCap, typename NodeCap,
23 // typename EdgeFlow, typename NodeFlow>
24 // class MaxMatching : public MaxFlow<stGraphWrapper<Graph>,
25 // stGraphWrapper<Graph>:: EdgeMapWrapper<EdgeCan, NodeCap>, stGraphWrapper<Graph>::EdgeMapWrapper<EdgeFlow, NodeFlow> > {
26 // typedef MaxFlow<stGraphWrapper<Graph>,
27 // stGraphWrapper<Graph>::EdgeMapWrapper<EdgeCan, NodeCap>,
28 // stGraphWrapper<Graph>::EdgeMapWrapper<EdgeFlow, NodeFlow> >
31 // stGraphWrapper<Graph> gw;
32 // stGraphWrapper<Graph>::EdgeMapWrapper<EdgeCap, NodeCap> cap;
33 // stGraphWrapper<Graph>::EdgeMapWrapper<EdgeFlow, NodeFlow> flow;
35 // //EdgeCap* edge_cap;
36 // //EdgeFlow* edge_flow;
38 // MaxMatching(Graph& _g, EdgeCap& _edge_cap, NodeCap& _node_cap,
39 // EdgeFlow& _edge_flow, NodeFlow& _node_flow) :
41 // cap(_edge_cap, _node_cap), flow(_edge_flow, _node_flow) {
42 // Parent::set(gw, cap, flow);
46 /// \brief A bipartite matching class.
48 /// This class reduces the matching problem to a flow problem and
49 /// a preflow is used on a wrapper. Such a generic approach means that
50 /// matchings, b-matchings an capacitated b-matchings can be handled in
51 /// a similar way. Due to the efficiency of the preflow algorithm, an
52 /// efficient matching framework is obtained.
54 template <typename Graph, typename EdgeCap, typename NodeCap,
55 typename EdgeFlow, typename NodeFlow>
56 class MaxBipartiteMatching {
60 // EdgeFlow* edge_flow;
61 // NodeFlow* node_flow;
62 typedef stGraphWrapper<Graph> stGW;
64 typedef typename stGW::template EdgeMapWrapper<EdgeCap, NodeCap> CapMap;
67 typedef typename stGW::template EdgeMapWrapper<EdgeFlow, NodeFlow> FlowMap;
69 MaxFlow<stGW, int, CapMap, FlowMap> mf;
72 //EdgeFlow* edge_flow;
74 /// For capacitated b-matchings, edge-caoacities and node-capacities
75 /// have to be given. After running \c run the matching is is given
76 /// back in the edge-map \c _edge_flow and \c _node_map can be used
77 /// to obtain saturation information about nodes.
78 ///\bug Note that the values in _edge_flow and _node_flow have
80 MaxBipartiteMatching(Graph& _g, EdgeCap& _edge_cap, NodeCap& _node_cap,
81 EdgeFlow& _edge_flow, NodeFlow& _node_flow) :
83 cap(_edge_cap, _node_cap),
85 flow(_edge_flow, _node_flow),
86 mf(stgw, stgw.S_NODE, stgw.T_NODE, cap, flow) { }
87 /// If the saturation information of nodes is not needed that the use of
88 /// this constructor is more comfortable.
89 ///\bug Note that the values in _edge_flow and _node_flow have
91 MaxBipartiteMatching(Graph& _g, EdgeCap& _edge_cap, NodeCap& _node_cap,
92 EdgeFlow& _edge_flow/*, NodeFlow& _node_flow*/) :
94 cap(_edge_cap, _node_cap),
95 node_flow(new NodeFlow(_g)),
96 flow(_edge_flow, *node_flow),
97 mf(stgw, stgw.S_NODE, stgw.T_NODE, cap, flow) { }
98 /// The class have a nontrivial destructor.
99 ~MaxBipartiteMatching() { if (node_flow) delete node_flow; }
100 /// run computes the max matching.
101 void run() { mf.run(); }
102 /// The matching value after running \c run.
103 int matchingValue() { return mf.flowValue(); }
108 #endif //HUGO_MAX_BIPARTITE_MATCHING_H