1 # ifndef TPL_BIPARTITE_H
2 # define TPL_BIPARTITE_H
4 # include <tpl_dynDlist.H>
5 # include <tpl_netgraph.H>
9 enum Bipartite_Color { Bp_White, Bp_Red, Bp_Blue };
12 static long & color(
typename GT::Node * p)
18 static long & color(
typename GT::Arc * a)
41 template <
class GT,
class SA = Dft_Show_Arc<GT> >
50 typename GT::Node * p = g.get_first_node();
51 color<GT>(p) = Bp_Red;
57 typename GT::Node * p = red.
get();
60 typename GT::Arc * a = it.get_current();
61 if (color<GT>(a) == Bp_Red)
62 throw std::domain_error(
"Graph is not bipartite");
63 else if (color<GT>(a) == Bp_Blue)
66 color<GT>(a) = Bp_Red;
67 typename GT::Node * q = it.get_tgt_node();
68 if (color<GT>(q) == Bp_Red)
69 throw std::domain_error(
"Graph is not bipartite");
70 else if (color<GT>(q) == Bp_Blue)
73 color<GT>(q) = Bp_Blue;
79 typename GT::Node * p = blue.
get();
82 typename GT::Arc * a = it.get_current();
83 if (color<GT>(a) == Bp_Blue)
84 throw std::domain_error(
"Graph is not bipartite");
85 else if (color<GT>(a) == Bp_Red)
88 color<GT>(a) = Bp_Blue;
90 typename GT::Node * q = it.get_tgt_node();
91 if (color<GT>(q) == Bp_Blue)
92 throw std::domain_error(
"Graph is not bipartite");
93 else if (color<GT>(q) == Bp_Red)
96 color<GT>(q) = Bp_Red;
112 template <
class GT,
class SA = Dft_Show_Arc<GT> >
130 compute_bipartite <GT, SA> (g, l, r);
174 typename GT::Node * p = it.get_current();
179 typename AN::Node * source = net.insert_node();
183 i.has_current(); i.next())
185 typename GT::Node * p = i.get_current();
186 typename AN::Node * src = mapped_node<GT, AN> (p);
187 net.insert_arc(source, src, 1);
191 typename GT::Arc * arc = j.get_current_arc();
192 typename AN::Node * tgt = mapped_node <GT, AN> (g.get_tgt_node(arc));
193 typename AN::Arc * a = net.insert_arc(src, tgt, 1);
199 typename AN::Node * sink = net.insert_node();
203 it.has_current(); it.next())
205 typename GT::Node * p = it.get_current();
206 net.insert_arc(mapped_node<GT, AN> (p), sink, 1);
209 Max_Flow <AN> () (net);
213 typename AN::Arc * a = it.get_current();
217 typename GT::Arc * arc = mapped_arc <AN, GT> (a);
261 compute_maximum_cardinality_bipartite_matching <GT, Max_Flow, SA>
269 # endif // TPL_BIPARTITE_H
void compute_bipartite(GT &g, DynDlist< typename GT::Node * > &l, DynDlist< typename GT::Node * > &r)
Definition: tpl_bipartite.H:42
#define ARC_COUNTER(p)
Definition: aleph-graph.H:254
Definition: tpl_netgraph.H:66
#define NODE_COOKIE(p)
Definition: aleph-graph.H:248
Definition: tpl_graph.H:751
T & put(const T &item)
Si this es una cola, entonces mete el elemento item.
Definition: tpl_dynDlist.H:245
#define ARC_COOKIE(p)
Definition: aleph-graph.H:281
#define NODE_COUNTER(p)
Definition: aleph-graph.H:226
void operator()(GT &g, DynDlist< typename GT::Arc * > &matching)
Definition: tpl_bipartite.H:259
Definition: tpl_graph.H:634
void next()
Adelanta el iterador una posición.
Definition: filter_iterator.H:143
Definition: tpl_bipartite.H:240
Definition: tpl_bipartite.H:113
void operator()(GT &g, DynDlist< typename GT::Node * > &l, DynDlist< typename GT::Node * > &r)
Definition: tpl_bipartite.H:126
Definition: tpl_netgraph.H:205
Definition: tpl_graph.H:814
Definition: tpl_netgraph.H:1231
T get()
Si this es una cola, entonces extrae el elemento más antiguo.
Definition: tpl_dynDlist.H:250
void compute_maximum_cardinality_bipartite_matching(GT &g, DynDlist< typename GT::Arc * > &matching)
Definition: tpl_bipartite.H:162
Definition: tpl_graph.H:694
bool is_empty() const
retorna true si this está vacía
Definition: dlink.H:127
T & append(const T &item)
Definition: tpl_dynDlist.H:106