27 # ifndef TPL_BIPARTITE_H 28 # define TPL_BIPARTITE_H 30 # include <tpl_dynDlist.H> 35 enum Bipartite_Color { Bp_White, Bp_Red, Bp_Blue };
38 static long & color(
typename GT::Node * p)
44 static long & color(
typename GT::Arc * a)
67 template <
class GT,
class SA = Dft_Show_Arc<GT> >
76 typename GT::Node * p = g.get_first_node();
77 color<GT>(p) = Bp_Red;
83 typename GT::Node * p = red.
get();
86 typename GT::Arc * a = it.get_curr_ne();
87 if (color<GT>(a) == Bp_Red)
88 throw std::domain_error(
"Graph is not bipartite");
89 else if (color<GT>(a) == Bp_Blue)
92 color<GT>(a) = Bp_Red;
93 typename GT::Node * q = it.get_tgt_node();
94 if (color<GT>(q) == Bp_Red)
95 throw std::domain_error(
"Graph is not bipartite");
96 else if (color<GT>(q) == Bp_Blue)
99 color<GT>(q) = Bp_Blue;
105 typename GT::Node * p = blue.
get();
108 typename GT::Arc * a = it.get_curr_ne();
109 if (color<GT>(a) == Bp_Blue)
110 throw std::domain_error(
"Graph is not bipartite");
111 else if (color<GT>(a) == Bp_Red)
114 color<GT>(a) = Bp_Blue;
116 typename GT::Node * q = it.get_tgt_node();
117 if (color<GT>(q) == Bp_Blue)
118 throw std::domain_error(
"Graph is not bipartite");
119 else if (color<GT>(q) == Bp_Red)
122 color<GT>(q) = Bp_Red;
138 template <
class GT,
class SA = Dft_Show_Arc<GT> >
156 compute_bipartite <GT, SA> (g, l, r);
200 typename GT::Node * p = it.get_curr_ne();
205 typename AN::Node * source = net.insert_node();
211 typename GT::Node * p = i.get_curr_ne();
212 typename AN::Node * src = mapped_node<GT, AN> (p);
213 net.insert_arc(source, src, 1);
217 typename GT::Arc * arc = j.get_current_arc_ne();
218 typename AN::Node * tgt = mapped_node <GT, AN> (g.get_tgt_node(arc));
219 typename AN::Arc * a = net.insert_arc(src, tgt, 1);
225 typename AN::Node * sink = net.insert_node();
231 typename GT::Node * p = it.get_curr_ne();
232 net.insert_arc(mapped_node<GT, AN> (p), sink, 1);
235 Max_Flow <AN> () (net);
239 typename AN::Arc * a = it.get_curr_ne();
243 typename GT::Arc * arc = mapped_arc <AN, GT> (a);
287 compute_maximum_cardinality_bipartite_matching <GT, Max_Flow, SA>
295 # endif // TPL_BIPARTITE_H Definition: tpl_graph.H:1225
bool has_curr() const noexcept
Return true if the iterator has current item.
Definition: dlink.H:658
#define ARC_COUNTER(p)
Definition: aleph-graph.H:339
void operator()(const GT &g, DynDlist< typename GT::Node *> &l, DynDlist< typename GT::Node *> &r)
Definition: tpl_bipartite.H:152
#define NODE_COOKIE(p)
Definition: aleph-graph.H:333
Definition: tpl_dynDlist.H:51
void compute_bipartite(const GT &g, DynDlist< typename GT::Node *> &l, DynDlist< typename GT::Node *> &r)
Definition: tpl_bipartite.H:68
Definition: tpl_net.H:216
T & put(const T &item)
Definition: tpl_dynDlist.H:300
#define ARC_COOKIE(p)
Definition: aleph-graph.H:366
#define NODE_COUNTER(p)
Definition: aleph-graph.H:311
Definition: tpl_dynDlist.H:413
Definition: tpl_graph.H:1063
Definition: tpl_bipartite.H:266
Definition: tpl_bipartite.H:139
Definition: tpl_net.H:1530
bool is_empty() const noexcept
Return true if this (as header node) is empty.
Definition: dlink.H:192
void compute_maximum_cardinality_bipartite_matching(const GT &g, DynDlist< typename GT::Arc *> &matching)
Definition: tpl_bipartite.H:188
Definition: tpl_graph.H:1270
T get()
Definition: tpl_dynDlist.H:306
Definition: tpl_graph.H:1177
T & append(const T &item)
Definition: tpl_dynDlist.H:149