marci@368: // -*- c++ -*-
marci@368: #include <iostream>
marci@368: #include <fstream>
marci@368: #include <vector>
marci@368: 
marci@902: //#include <sage_graph.h>
alpar@921: #include <lemon/smart_graph.h>
marci@368: //#include <dimacs.h>
alpar@921: #include <lemon/time_measure.h>
marci@902: //#include <for_each_macros.h>
marci@602: #include <bfs_dfs.h>
alpar@921: #include <lemon/graph_wrapper.h>
marci@496: #include <bipartite_graph_wrapper.h>
alpar@921: #include <lemon/maps.h>
alpar@921: #include <lemon/preflow.h>
marci@762: #include <augmenting_flow.h>
marci@368: 
marci@902: using std::cout;
marci@902: using std::endl;
marci@902: 
alpar@921: using namespace lemon;
marci@368: 
marci@368: int main() {
marci@902:   //typedef UndirSageGraph Graph; 
marci@902:   typedef SmartGraph Graph;
marci@368:   typedef Graph::Node Node;
marci@368:   typedef Graph::NodeIt NodeIt;
marci@368:   typedef Graph::Edge Edge;
marci@368:   typedef Graph::EdgeIt EdgeIt;
marci@368:   typedef Graph::OutEdgeIt OutEdgeIt;
marci@368: 
marci@368:   Graph g;
marci@409: //   std::vector<Graph::Node> s_nodes;
marci@409: //   std::vector<Graph::Node> t_nodes;
marci@409: //   for (int i=0; i<3; ++i) s_nodes.push_back(g.addNode());
marci@409: //   for (int i=0; i<3; ++i) t_nodes.push_back(g.addNode());
marci@409: //   g.addEdge(s_nodes[0], t_nodes[2]);
marci@409: //   g.addEdge(t_nodes[1], s_nodes[2]);
marci@409: //   g.addEdge(s_nodes[0], t_nodes[1]);
marci@409:   
marci@409: //   Graph::NodeMap<int> ref_map(g, -1);
marci@409: //   IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
marci@409: //   for (int i=0; i<3; ++i) bipartite_map.insert(s_nodes[i], false);
marci@409: //   for (int i=0; i<3; ++i) bipartite_map.insert(t_nodes[i], true);
marci@409: 
marci@409:   std::vector<Graph::Node> nodes;
marci@409:   for (int i=0; i<3; ++i) nodes.push_back(g.addNode());
marci@409:   for (int i=3; i<6; ++i) nodes.push_back(g.addNode());
marci@409:   g.addEdge(nodes[0], nodes[3+2]);
marci@409:   g.addEdge(nodes[3+1], nodes[2]);
marci@409:   g.addEdge(nodes[0], nodes[3+1]);
marci@368:   
marci@368:   Graph::NodeMap<int> ref_map(g, -1);
marci@368:   IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
marci@409:   for (int i=0; i<3; ++i) bipartite_map.insert(nodes[i], false);
marci@409:   for (int i=3; i<6; ++i) bipartite_map.insert(nodes[i], true);
marci@409: 
marci@409:   Graph::Node u;
marci@902:   cout << "These nodes will be in S:" << endl;
marci@409:   //FIXME azert kellene ++, es invalid vizsgalat u-bol, hogy ezt le lehessen 
marci@409:   //irni 1etlen FOR_EACH-csel.
marci@902:   for (bipartite_map.first(u, false); u!=INVALID; bipartite_map.next(u)) 
marci@902:     cout << g.id(u) << " ";
marci@902:   cout << endl;
marci@902:   cout << "These nodes will be in T:" << endl;
marci@902:   for (bipartite_map.first(u, true); u!=INVALID; bipartite_map.next(u)) 
marci@902:     cout << g.id(u) << " ";
marci@902:   cout << endl;
marci@409: 
marci@368:   typedef BipartiteGraphWrapper<Graph> BGW;
marci@368:   BGW bgw(g, bipartite_map);
marci@409: 
marci@902:   cout << "Nodes by NodeIt:" << endl;
marci@902:   for (BGW::NodeIt n(bgw); n!=INVALID; ++n)
marci@902:     cout << g.id(n) << " ";
marci@902:   cout << endl;
marci@902: 
marci@902:   cout << "Nodes in S by ClassNodeIt:" << endl;
marci@902:   for (BGW::ClassNodeIt n(bgw, bgw.S_CLASS); n!=INVALID; ++n)
marci@902:     cout << g.id(n) << " ";
marci@902:   cout << endl;
marci@902: 
marci@902:   cout << "Nodes in T by ClassNodeIt:" << endl;
marci@902:   for (BGW::ClassNodeIt n(bgw, bgw.T_CLASS); n!=INVALID; ++n)
marci@902:     cout << g.id(n) << " ";
marci@902:   cout << endl;
marci@902: 
marci@902:   cout << "Edges of the bipartite graph:" << endl;
marci@902:   for (BGW::EdgeIt e(bgw); e!=INVALID; ++e)
alpar@986:     cout << g.id(bgw.source(e)) << "->" << g.id(bgw.target(e)) << endl;
marci@368: 
marci@379:   BGW::NodeMap<int> dbyj(bgw);
marci@379:   BGW::EdgeMap<int> dbyxcj(bgw);
marci@368: 
marci@902: //   typedef stBipartiteGraphWrapper<BGW> stGW;
marci@902: //   stGW stgw(bgw);
marci@902: //   ConstMap<stGW::Edge, int> const1map(1);
marci@902: //   stGW::NodeMap<int> ize(stgw);
marci@902: //   stGW::EdgeMap<int> flow(stgw);
marci@379: 
marci@902: //   BfsIterator< BGW, BGW::NodeMap<bool> > bfs(bgw);
marci@902: //   Graph::NodeIt si;
marci@902: //   Graph::Node s; 
marci@902: //   s=g.first(si);
marci@902: //   bfs.pushAndSetReached(BGW::Node(s));
marci@902: //   while (!bfs.finished()) { ++bfs; }
marci@379: 
marci@902: //   FOR_EACH_LOC(stGW::NodeIt, n, stgw) { 
marci@902: //     cout << "out-edges of " << n << ":" << endl; 
marci@902: //     FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) { 
marci@902: //       cout << " " << e << endl;
marci@902: //       cout << " aNode: " << stgw.aNode(e) << endl;
marci@902: //       cout << " bNode: " << stgw.bNode(e) << endl;      
marci@902: //     }
marci@902: //     cout << "in-edges of " << n << ":" << endl; 
marci@902: //     FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) { 
marci@902: //       cout << " " << e << endl;
marci@902: //       cout << " aNode: " << stgw.aNode(e) << endl;
marci@902: //       cout << " bNode: " << stgw.bNode(e) << endl;     
marci@902: //     }
marci@902: //   }
marci@902: //   cout << "Edges of the stGraphWrapper:" << endl; 
marci@902: //   FOR_EACH_LOC(stGW::EdgeIt, n, stgw) { 
marci@902: //     cout << " " << n << endl;
marci@902: //   }
marci@379: 
marci@902: //   stGW::NodeMap<bool> b(stgw);
marci@902: //   FOR_EACH_LOC(stGW::NodeIt, n, stgw) { 
marci@902: //     cout << n << ": " << b[n] << endl;
marci@902: //   }
marci@409: 
marci@902: //   cout << "Bfs from s:" << endl;
marci@902: //   BfsIterator< stGW, stGW::NodeMap<bool> > bfs_stgw(stgw);
marci@902: //   bfs_stgw.pushAndSetReached(stgw.S_NODE);
marci@902: //   while (!bfs_stgw.finished()) { 
marci@902: //     cout << " " << stGW::OutEdgeIt(bfs_stgw) << endl;
marci@902: //     ++bfs_stgw; 
marci@902: //   }
marci@379:   
marci@902: //   AugmentingFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> > 
marci@902: //     max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
marci@902: //   while (max_flow_test.augmentOnShortestPath()) { }
marci@393: 
marci@902: //   cout << max_flow_test.flowValue() << std::endl;
marci@368: 
marci@368:   return 0;
marci@368: }