# HG changeset patch # User marci # Date 1075474510 0 # Node ID f00a4f7e21498f1ad69dccfc5ba0f46e837d6f1d # Parent 55fa34646895190b1aa5cb4c275ca22450d60316 marci_graph_demo in new concept diff -r 55fa34646895 -r f00a4f7e2149 src/work/marci_graph_demo.cc --- a/src/work/marci_graph_demo.cc Fri Jan 30 14:54:32 2004 +0000 +++ b/src/work/marci_graph_demo.cc Fri Jan 30 14:55:10 2004 +0000 @@ -2,186 +2,217 @@ #include #include -#include -#include -#include -#include +#include +#include +#include using namespace marci; int main (int, char*[]) { - typedef list_graph::node_iterator node_iterator; - typedef list_graph::edge_iterator edge_iterator; - typedef list_graph::each_node_iterator each_node_iterator; - typedef list_graph::each_edge_iterator each_edge_iterator; - typedef list_graph::out_edge_iterator out_edge_iterator; - typedef list_graph::in_edge_iterator in_edge_iterator; - typedef list_graph::sym_edge_iterator sym_edge_iterator; - list_graph G; - std::vector vector_of_node_iterators; - for(int i=0; i!=8; ++i) vector_of_node_iterators.push_back(G.add_node()); + typedef ListGraph::NodeIt NodeIt; + typedef ListGraph::EdgeIt EdgeIt; + typedef ListGraph::EachNodeIt EachNodeIt; + typedef ListGraph::EachEdgeIt EachEdgeIt; + typedef ListGraph::OutEdgeIt OutEdgeIt; + typedef ListGraph::InEdgeIt InEdgeIt; + typedef ListGraph::SymEdgeIt SymEdgeIt; + ListGraph G; + std::vector vector_of_NodeIts; + for(int i=0; i!=8; ++i) vector_of_NodeIts.push_back(G.addNode()); for(int i=0; i!=8; ++i) - for(int j=0; j!=8; ++j) { - if ((ij is arc iff i()) << std::endl; - for(each_node_iterator i=G.first_node(); i.valid(); ++i) { + for(EachNodeIt i=G.first(); i.valid(); ++i) { std::cout << "node " << G.id(i) << std::endl; - std::cout << " outdegree (out_edge_iterator): " << number_of(G.first_out_edge(i)) << " "; - for(out_edge_iterator j=G.first_out_edge(i); j.valid(); ++j) { + std::cout << " outdegree (OutEdgeIt): " << count(G.first(i)) << " "; + for(OutEdgeIt j=G.first(i); j.valid(); ++j) { std::cout << "(" << G.id(G.tail(j)) << "--" << G.id(j) << "->" << G.id(G.head(j)) << ") "; } std::cout << std::endl; std::cout<< " "; - for(out_edge_iterator j=G.first_out_edge(i); j.valid(); ++j) { - std::cout << G.a_node(j) << "->" << G.b_node(j) << " "; } + for(OutEdgeIt j=G.first(i); j.valid(); ++j) { + std::cout << G.aNode(j) << "->" << G.bNode(j) << " "; } std::cout<(i)) << " "; + for(InEdgeIt j=G.first(i); j.valid(); ++j) { std::cout << j << " "; } std::cout << std::endl; std::cout<< " "; - for(in_edge_iterator j=G.first_in_edge(i); j.valid(); ++j) { - std::cout << G.a_node(j) << "->" << G.b_node(j) << " "; } + for(InEdgeIt j=G.first(i); j.valid(); ++j) { + std::cout << G.aNode(j) << "->" << G.bNode(j) << " "; } std::cout<(i)) << " "; + for(SymEdgeIt j=G.first(i); j.valid(); ++j) { std::cout << j << " "; } std::cout<" << G.b_node(j) << " "; } + for(SymEdgeIt j=G.first(i); j.valid(); ++j) { + std::cout << G.aNode(j) << "->" << G.bNode(j) << " "; } std::cout<(); i.valid(); ++i) { std::cout << i << " "; } std::cout << std::endl; std::cout << "node property array test" << std::endl; - node_property_vector my_property_vector(G); - each_node_iterator v; - G.get_first(v); - my_property_vector.put(v, 42); - my_property_vector.put(++G.first_node(), 314); - my_property_vector.put(++++G.first_node(), 1956); - my_property_vector.put(vector_of_node_iterators[3], 1989); - my_property_vector.put(vector_of_node_iterators[4], 2003); - my_property_vector.put(vector_of_node_iterators[7], 1978); + ListGraph::NodeMap my_property_vector(G); + EachNodeIt v; + G.getFirst(v); + my_property_vector.set(v, 42); + my_property_vector.set(++G.first(), 314); + my_property_vector.set(++++G.first(), 1956); + my_property_vector.set(vector_of_NodeIts[3], 1989); + my_property_vector.set(vector_of_NodeIts[4], 2003); + my_property_vector.set(vector_of_NodeIts[7], 1978); std::cout << "some node property values..." << std::endl; - for(each_node_iterator i=G.first_node(); i.valid(); ++i) { + for(EachNodeIt i=G.first(); i.valid(); ++i) { std::cout << my_property_vector.get(i) << std::endl; } int _i=1; int _ii=1; - edge_property_vector my_edge_property(G); - for(each_edge_iterator i=G.first_edge(); i.valid(); ++i) { - my_edge_property.put(i, _i); + ListGraph::EdgeMap my_edge_property(G); + for(EachEdgeIt i=G.first(); i.valid(); ++i) { + my_edge_property.set(i, _i); _i*=_ii; ++_ii; } std::cout << "node and edge property values on the tails and heads of edges..." << std::endl; - for(each_edge_iterator j=G.first_edge(); j.valid(); ++j) { + for(EachEdgeIt j=G.first(); j.valid(); ++j) { std::cout << my_property_vector.get(G.tail(j)) << "--" << my_edge_property.get(j) << "-->" << my_property_vector.get(G.head(j)) << " "; } std::cout << std::endl; - //std::cout << "the same for inedges of the nodes..." << std::endl; - //k=0; - //for(each_node_iterator i=G.first_node(); i.valid(); ++i) { - // for(in_edge_iterator j=G.first_in_edge(i); j.valid(); ++j) { - // std::cout << my_property_vector.get(G.tail(j)) << "-->" << my_property_vector.get(G.head(j)) << " "; - // } - // std::cout << std::endl; - //} - std::cout << "bfs from the first node" << std::endl; - bfs bfs_test(G, G.first_node()); + bfs bfs_test(G, G.first()); bfs_test.run(); std::cout << "reached: "; - for(each_node_iterator i=G.first_node(); i.valid(); ++i) { + for(EachNodeIt i=G.first(); i.valid(); ++i) { std::cout << bfs_test.reached.get(i) << " "; } std::cout<(); i.valid(); ++i) { std::cout << bfs_test.dist.get(i) << " "; } std::cout< node_name(flow_test); - node_name.put(s, "s"); - node_name.put(v1, "v1"); - node_name.put(v2, "v2"); - node_name.put(v3, "v3"); - node_name.put(v4, "v4"); - node_name.put(t, "t"); + ListGraph::NodeMap node_name(flowG); + node_name.set(s, "s"); + node_name.set(v1, "v1"); + node_name.set(v2, "v2"); + node_name.set(v3, "v3"); + node_name.set(v4, "v4"); + node_name.set(t, "t"); - edge_iterator s_v1=flow_test.add_edge(s, v1); - edge_iterator s_v2=flow_test.add_edge(s, v2); - edge_iterator v1_v2=flow_test.add_edge(v1, v2); - edge_iterator v2_v1=flow_test.add_edge(v2, v1); - edge_iterator v1_v3=flow_test.add_edge(v1, v3); - edge_iterator v3_v2=flow_test.add_edge(v3, v2); - edge_iterator v2_v4=flow_test.add_edge(v2, v4); - edge_iterator v4_v3=flow_test.add_edge(v4, v3); - edge_iterator v3_t=flow_test.add_edge(v3, t); - edge_iterator v4_t=flow_test.add_edge(v4, t); + EdgeIt s_v1=flowG.addEdge(s, v1); + EdgeIt s_v2=flowG.addEdge(s, v2); + EdgeIt v1_v2=flowG.addEdge(v1, v2); + EdgeIt v2_v1=flowG.addEdge(v2, v1); + EdgeIt v1_v3=flowG.addEdge(v1, v3); + EdgeIt v3_v2=flowG.addEdge(v3, v2); + EdgeIt v2_v4=flowG.addEdge(v2, v4); + EdgeIt v4_v3=flowG.addEdge(v4, v3); + EdgeIt v3_t=flowG.addEdge(v3, t); + EdgeIt v4_t=flowG.addEdge(v4, t); - edge_property_vector cap(flow_test); + ListGraph::EdgeMap cap(flowG); - cap.put(s_v1, 16); - cap.put(s_v2, 13); - cap.put(v1_v2, 10); - cap.put(v2_v1, 4); - cap.put(v1_v3, 12); - cap.put(v3_v2, 9); - cap.put(v2_v4, 14); - cap.put(v4_v3, 7); - cap.put(v3_t, 20); - cap.put(v4_t, 4); + cap.set(s_v1, 16); + cap.set(s_v2, 13); + cap.set(v1_v2, 10); + cap.set(v2_v1, 4); + cap.set(v1_v3, 12); + cap.set(v3_v2, 9); + cap.set(v2_v4, 14); + cap.set(v4_v3, 7); + cap.set(v3_t, 20); + cap.set(v4_t, 4); - std::cout << "on directed graph graph" << std::endl; //<< flow_test; + std::cout << "on directed graph graph" << std::endl; //<< flowG; std::cout << "names and capacity values" << std::endl; - for(each_node_iterator i=flow_test.first_node(); i.valid(); ++i) { + for(EachNodeIt i=flowG.first(); i.valid(); ++i) { std::cout << node_name.get(i) << ": "; std::cout << "out edges: "; - for(out_edge_iterator j=flow_test.first_out_edge(i); j.valid(); ++j) - std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " "; + for(OutEdgeIt j=flowG.first(i); j.valid(); ++j) + std::cout << node_name.get(flowG.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flowG.head(j)) << " "; std::cout << "in edges: "; - for(in_edge_iterator j=flow_test.first_in_edge(i); j.valid(); ++j) - std::cout << node_name.get(flow_test.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flow_test.head(j)) << " "; + for(InEdgeIt j=flowG.first(i); j.valid(); ++j) + std::cout << node_name.get(flowG.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flowG.head(j)) << " "; std::cout << std::endl; } + //flowG.setTail(v3_t, v2); + //flowG.setHead(v3_t, s); + + for(EachNodeIt i=flowG.first(); i.valid(); ++i) { + std::cout << node_name.get(i) << ": "; + std::cout << "out edges: "; + for(OutEdgeIt j=flowG.first(i); j.valid(); ++j) + std::cout << node_name.get(flowG.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flowG.head(j)) << " "; + std::cout << "in edges: "; + for(InEdgeIt j=flowG.first(i); j.valid(); ++j) + std::cout << node_name.get(flowG.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flowG.head(j)) << " "; + std::cout << std::endl; + } - //for(each_node_iterator i=flow_test.first_node(); i.valid(); ++i) { - // std::cout << i << " "; - //} + + /* + while (flowG.first().valid()) { + flowG.deleteEdge(flowG.first()); + for(EachNodeIt i=flowG.first(); i.valid(); ++i) { + std::cout << node_name.get(i) << ": "; + std::cout << "out edges: "; + for(OutEdgeIt j=flowG.first(i); j.valid(); ++j) + std::cout << node_name.get(flowG.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flowG.head(j)) << " "; + std::cout << "in edges: "; + for(InEdgeIt j=flowG.first(i); j.valid(); ++j) + std::cout << node_name.get(flowG.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flowG.head(j)) << " "; + std::cout << std::endl; + } + } - max_flow_type max_flow_test(flow_test, s, t, cap); + while (flowG.first().valid()) { + flowG.deleteNode(flowG.first()); + for(EachNodeIt i=flowG.first(); i.valid(); ++i) { + std::cout << node_name.get(i) << ": "; + std::cout << "out edges: "; + for(OutEdgeIt j=flowG.first(i); j.valid(); ++j) + std::cout << node_name.get(flowG.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flowG.head(j)) << " "; + std::cout << "in edges: "; + for(InEdgeIt j=flowG.first(i); j.valid(); ++j) + std::cout << node_name.get(flowG.tail(j)) << "-"<< cap.get(j) << "->" << node_name.get(flowG.head(j)) << " "; + std::cout << std::endl; + } + } + */ + + //ListGraph::EdgeMap flow(flowG, 0); + //ResGraph res_graph(flowG, cap, flow); + max_flow_type max_flow_test(flowG, s, t, cap); max_flow_test.run(); return 0;