diff -r 7c88989ea45b -r 3151a1026db9 src/work/marci_max_flow.hh --- a/src/work/marci_max_flow.hh Tue Jan 20 11:21:42 2004 +0000 +++ b/src/work/marci_max_flow.hh Tue Jan 20 17:39:13 2004 +0000 @@ -3,7 +3,6 @@ #include -#include #include #include @@ -11,24 +10,22 @@ template class res_graph_type { - typedef typename graph_traits::node_iterator node_iterator; - typedef typename graph_traits::edge_iterator edge_iterator; - typedef typename graph_traits::each_node_iterator each_node_iterator; - typedef typename graph_traits::sym_edge_iterator sym_edge_iterator; - + typedef typename graph_type::node_iterator node_iterator; + typedef typename graph_type::each_node_iterator each_node_iterator; + typedef typename graph_type::sym_edge_iterator old_sym_edge_iterator; graph_type& G; edge_property_vector& flow; edge_property_vector& capacity; public: res_graph_type(graph_type& _G, edge_property_vector& _flow, edge_property_vector& _capacity) : G(_G), flow(_flow), capacity(_capacity) { } - class res_edge_it { + class edge_iterator { friend class res_graph_type; protected: res_graph_type* resG; - sym_edge_iterator sym; + old_sym_edge_iterator sym; public: - res_edge_it() { } + edge_iterator() { } //bool is_free() { //if (resG->G.a_node(sym)==resG->G.tail(sym)) { // return (resG->flow.get(sym)capacity.get(sym)); @@ -43,7 +40,7 @@ return (resG->flow.get(sym)); } } - bool is_valid() { return sym.is_valid(); } + bool valid() { return sym.valid(); } void make_invalid() { sym.make_invalid(); } void augment(T a) { if (resG->G.a_node(sym)==resG->G.tail(sym)) { @@ -54,56 +51,45 @@ } }; - class res_out_edge_it : public res_edge_it { + class out_edge_iterator : public edge_iterator { public: - res_out_edge_it() { } - res_out_edge_it(res_graph_type& _resG, const node_iterator& v) { + out_edge_iterator() { } + out_edge_iterator(res_graph_type& _resG, const node_iterator& v) { resG=&_resG; sym=resG->G.first_sym_edge(v); - while( sym.is_valid() && !(free()>0) ) { ++sym; } + while( sym.valid() && !(free()>0) ) { ++sym; } } - res_out_edge_it& operator++() { + out_edge_iterator& operator++() { ++sym; - while( sym.is_valid() && !(free()>0) ) { ++sym; } + while( sym.valid() && !(free()>0) ) { ++sym; } return *this; } }; - res_out_edge_it first_out_edge(const node_iterator& v) { - return res_out_edge_it(*this, v); + out_edge_iterator first_out_edge(const node_iterator& v) { + return out_edge_iterator(*this, v); } each_node_iterator first_node() { return G.first_node(); } - node_iterator tail(const res_edge_it& e) { return G.a_node(e.sym); } - node_iterator head(const res_edge_it& e) { return G.b_node(e.sym); } + node_iterator tail(const edge_iterator& e) { return G.a_node(e.sym); } + node_iterator head(const edge_iterator& e) { return G.b_node(e.sym); } int id(const node_iterator& v) { return G.id(v); } //node_iterator invalid_node() { return G.invalid_node(); } - //res_edge_it invalid_edge() { res_edge_it n; n.sym=G.invalid_sym_edge(); return n; } - - }; - - template - struct graph_traits< res_graph_type > { - typedef typename graph_traits::node_iterator node_iterator; - typedef typename res_graph_type::res_edge_it edge_iterator; - typedef typename graph_traits::each_node_iterator each_node_iterator; - typedef typename res_graph_type::res_out_edge_it out_edge_iterator; + //res_edge_it invalid_edge() { res_edge_it n; n.sym=G.invalid_sym_edge(); return n; } }; template struct max_flow_type { - - typedef typename graph_traits::node_iterator node_iterator; - typedef typename graph_traits::edge_iterator edge_iterator; - typedef typename graph_traits::each_node_iterator each_node_iterator; - typedef typename graph_traits::out_edge_iterator out_edge_iterator; - typedef typename graph_traits::in_edge_iterator in_edge_iterator; - + typedef typename graph_type::node_iterator node_iterator; + typedef typename graph_type::edge_iterator edge_iterator; + typedef typename graph_type::each_node_iterator each_node_iterator; + typedef typename graph_type::out_edge_iterator out_edge_iterator; + typedef typename graph_type::in_edge_iterator in_edge_iterator; graph_type& G; node_iterator s; node_iterator t; @@ -111,8 +97,8 @@ edge_property_vector& capacity; max_flow_type(graph_type& _G, node_iterator _s, node_iterator _t, edge_property_vector& _capacity) : G(_G), s(_s), t(_t), flow(_G), capacity(_capacity) { - for(each_node_iterator i=G.first_node(); i.is_valid(); ++i) - for(out_edge_iterator j=G.first_out_edge(i); j.is_valid(); ++j) + for(each_node_iterator i=G.first_node(); i.valid(); ++i) + for(out_edge_iterator j=G.first_out_edge(i); j.valid(); ++j) flow.put(j, 0); } void run() { @@ -123,7 +109,7 @@ do { augment=false; - typedef std::queue::out_edge_iterator> bfs_queue_type; + typedef std::queue bfs_queue_type; bfs_queue_type bfs_queue; bfs_queue.push(res_graph.first_out_edge(s)); @@ -134,9 +120,9 @@ bfs_iterator1< aug_graph_type, reached_type > res_bfs(res_graph, bfs_queue, reached); - typedef node_property_vector::edge_iterator> pred_type; + typedef node_property_vector pred_type; pred_type pred(res_graph); - graph_traits::edge_iterator a; + aug_graph_type::edge_iterator a; a.make_invalid(); pred.put(s, a); @@ -144,16 +130,16 @@ free_type free(res_graph); //searching for augmenting path - while ( res_bfs.is_valid() ) { + while ( res_bfs.valid() ) { //std::cout<<"KULSO ciklus itt jar: "<"<::edge_iterator e; + if (res_bfs.newly_reached()) { + aug_graph_type::edge_iterator e; e=res_bfs; node_iterator v=res_graph.tail(e); node_iterator w=res_graph.head(e); //std::cout<"<::edge_iterator e=pred.get(n); + while (pred.get(n).valid()) { + aug_graph_type::edge_iterator e=pred.get(n); e.augment(augment_value); std::cout<<"("<"<::each_edge_iterator e=G.first_edge(); e.is_valid(); ++e) { + for(typename graph_type::each_edge_iterator e=G.first_edge(); e.valid(); ++e) { std::cout<<"("<"<