1.1 --- a/src/work/marci/merge_node_graph_wrapper_test.cc Sun Apr 17 18:57:22 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,258 +0,0 @@
1.4 -#include <iostream>
1.5 -#include <fstream>
1.6 -
1.7 -#include <lemon/list_graph.h>
1.8 -#include <lemon/smart_graph.h>
1.9 -#include <lemon/dimacs.h>
1.10 -#include <lemon/preflow.h>
1.11 -#include <lemon/full_graph.h>
1.12 -#include <merge_node_graph_wrapper.h>
1.13 -
1.14 -#include<lemon/concept_check.h>
1.15 -#include<lemon/concept/graph.h>
1.16 -
1.17 -using std::cout;
1.18 -using std::endl;
1.19 -
1.20 -using namespace lemon;
1.21 -using namespace lemon::concept;
1.22 -
1.23 -class Graph3 : ListGraph {
1.24 -public:
1.25 - class Node : public ListGraph::Node { };
1.26 - class Edge { };
1.27 -};
1.28 -
1.29 -template <typename Graph>
1.30 -void printGraph(const Graph& g) {
1.31 - cout << " nodes:" << endl;
1.32 - for (typename Graph::NodeIt n(g); n!=INVALID; ++n) {
1.33 - cout << " " << g.id(n) << ": out edges:" << endl;
1.34 - for (typename Graph::OutEdgeIt e(g, n); e!=INVALID; ++e)
1.35 - cout << " " << g.id(g.source(e)) << "->" << g.id(g.target(e)) << endl;
1.36 - }
1.37 - cout << " edges:" << endl;
1.38 - for (typename Graph::EdgeIt e(g); e!=INVALID; ++e) {
1.39 - cout << " " << g.id(e) << ": "
1.40 - << g.id(g.source(e)) << "->" << g.id(g.target(e)) << endl;
1.41 - }
1.42 -}
1.43 -
1.44 -int main() {
1.45 - {
1.46 - cout << "FIRST TEST" << endl;
1.47 - //typedef SmartGraph Graph1;
1.48 - typedef ListGraph Graph1;
1.49 - typedef ListGraph Graph2;
1.50 - typedef SmartGraph Graph3;
1.51 -
1.52 -// {
1.53 -// checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph2> >();
1.54 -// MergeEdgeGraphWrapper<Graph1, Graph2>::printNode();
1.55 -// MergeEdgeGraphWrapper<Graph1, Graph2>::printEdge();
1.56 -// checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph1> >();
1.57 -// MergeEdgeGraphWrapper<Graph1, Graph1>::printNode();
1.58 -// MergeEdgeGraphWrapper<Graph1, Graph1>::printEdge();
1.59 -// typedef ResGraphWrapper<Graph1, int,
1.60 -// ConstMap<Graph1, int>, ConstMap<Graph1, int> > Graph4;
1.61 -// checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph1, Graph4> >();
1.62 -// MergeEdgeGraphWrapper<Graph1, Graph4>::printNode();
1.63 -// MergeEdgeGraphWrapper<Graph1, Graph4>::printEdge();
1.64 -// checkConcept<StaticGraph, MergeEdgeGraphWrapper<Graph4, Graph1> >();
1.65 -// MergeEdgeGraphWrapper<Graph4, Graph1>::printNode();
1.66 -// MergeEdgeGraphWrapper<Graph4, Graph1>::printEdge();
1.67 -// }
1.68 -
1.69 - Graph1 g1;
1.70 - Graph2 g2;
1.71 - typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
1.72 - GW gw(g1, g2);
1.73 - Graph1::Node s1, t1;
1.74 - Graph2::Node s2, t2;
1.75 - Graph1::EdgeMap<int> cap1(g1);
1.76 - Graph2::EdgeMap<int> cap2(g2);
1.77 -
1.78 - std::ifstream f1("graph1.dim");
1.79 - std::ifstream f2("graph2.dim");
1.80 - readDimacs(f1, g1);
1.81 - readDimacs(f2, g2);
1.82 -
1.83 -// GW::NodeMap<int> ize(gw, 8);
1.84 -// for (GW::NodeIt n(gw); n!=INVALID; ++n) ize.set(n, 9);
1.85 -// GW::EdgeMap<int> mize(gw, 8);
1.86 -// for (GW::EdgeIt n(gw); n!=INVALID; ++n) mize.set(n, 7);
1.87 -
1.88 -// std::ifstream f1("flow-1.dim");
1.89 -// std::ifstream f2("flow2.dim");
1.90 -// readDimacs(f1, g1, cap1, s1, t1);
1.91 -// readDimacs(f2, g2, cap2, s2, t2);
1.92 -
1.93 -// GW::EdgeMap<int> cap(gw);
1.94 -// for (GW::EdgeIt e(gw); e!=INVALID; ++e) {
1.95 -// if (gw.forward(e)) cap.set(e, cap1[e]);
1.96 -// if (gw.backward(e)) cap.set(e, cap2[e]);
1.97 -// }
1.98 -
1.99 -// {
1.100 -// GW::EdgeMap<int> flow(gw, 0);
1.101 -// Preflow<GW, int> preflow(gw, GW::Node(s1, INVALID, false),
1.102 -// GW::Node(t1, INVALID, false), cap, flow);
1.103 -// preflow.run();
1.104 -// std::cout << "s1->t1: " << preflow.flowValue() << std::endl;
1.105 -// }
1.106 -// {
1.107 -// GW::EdgeMap<int> flow(gw, 0);
1.108 -// Preflow<GW, int> preflow(gw, GW::Node(INVALID, s2, true),
1.109 -// GW::Node(INVALID, t2, true), cap, flow);
1.110 -// preflow.run();
1.111 -// std::cout << "s2->t2: " << preflow.flowValue() << std::endl;
1.112 -// }
1.113 -// {
1.114 -// GW::EdgeMap<int> flow(gw, 0);
1.115 -// Preflow<GW, int> preflow(gw, GW::Node(s1, INVALID, false),
1.116 -// GW::Node(INVALID, t2, true), cap, flow);
1.117 -// preflow.run();
1.118 -// std::cout << "s1->t2: " << preflow.flowValue() << std::endl;
1.119 -// }
1.120 -// {
1.121 -// GW::EdgeMap<int> flow(gw, 0);
1.122 -// Preflow<GW, int> preflow(gw, GW::Node(INVALID, s2, true),
1.123 -// GW::Node(s1, INVALID, false), cap, flow);
1.124 -// preflow.run();
1.125 -// std::cout << "s2->t1: " << preflow.flowValue() << std::endl;
1.126 -// }
1.127 - cout << "1st graph" << endl;
1.128 - printGraph(g1);
1.129 -
1.130 - cout << "2nd graph" << endl;
1.131 - printGraph(g2);
1.132 -
1.133 - cout << "merged graph" << endl;
1.134 - printGraph(gw);
1.135 -
1.136 -// for (GW::NodeIt n(gw); n!=INVALID; ++n)
1.137 -// std::cout << ize[n] << std::endl;
1.138 -// for (GW::EdgeIt n(gw); n!=INVALID; ++n)
1.139 -// std::cout << mize[n] << std::endl;
1.140 -
1.141 - typedef NewEdgeSetGraphWrapper2<GW, Graph3> GWW;
1.142 -// {
1.143 -// checkConcept<StaticGraph, GWW>();
1.144 -// }
1.145 -
1.146 - GWW gww(gw);
1.147 -
1.148 - cout << "new edges graph" << endl;
1.149 - printGraph(gww);
1.150 -
1.151 - GWW::NodeIt n(gww);
1.152 - GWW::Node n1=n;
1.153 - ++n;
1.154 - GWW::Node n2=n;
1.155 - gww.addEdge(n1, n2);
1.156 - // gww.addNode();
1.157 - // gww.addNode();
1.158 -
1.159 - cout << "new edges graph" << endl;
1.160 - printGraph(gww);
1.161 -
1.162 - typedef AugmentingGraphWrapper<GW, GWW> GWWW;
1.163 - // {
1.164 - // checkConcept<StaticGraph, GWWW>();
1.165 - // }
1.166 - GWWW gwww(gw, gww);
1.167 -
1.168 - cout << "fully merged graph" << endl;
1.169 - printGraph(gwww);
1.170 - }
1.171 -
1.172 -
1.173 - {
1.174 - cout << "SECOND TEST" << endl;
1.175 - typedef SmartGraph Graph1;
1.176 -// {
1.177 -// checkConcept<StaticGraph, Graph1>();
1.178 -// }
1.179 -
1.180 - Graph1 g1;
1.181 -
1.182 - FullGraph pre_g2(2);
1.183 - ConstMap<FullGraph::Edge, bool> const_false_map(false);
1.184 - typedef EdgeSubGraphWrapper<FullGraph, ConstMap<FullGraph::Edge, bool> >
1.185 - Graph2;
1.186 -// {
1.187 -// checkConcept<StaticGraph, Graph2>();
1.188 -// }
1.189 -
1.190 - Graph2 g2(pre_g2, const_false_map);
1.191 -
1.192 - typedef MergeEdgeGraphWrapper<Graph1, Graph2> GW;
1.193 -// {
1.194 -// checkConcept<StaticGraph, GW>();
1.195 -// }
1.196 - GW gw(g1, g2);
1.197 - GW::Node sw;
1.198 - GW::Node tw;
1.199 - {
1.200 - Graph2::NodeIt k(g2);
1.201 - sw=GW::Node(INVALID, k, true);
1.202 - ++k;
1.203 - tw=GW::Node(INVALID, k, true);
1.204 - }
1.205 -
1.206 - std::ifstream f1("graph2.dim");
1.207 - readDimacs(f1, g1);
1.208 -
1.209 - cout << "1st graph" << endl;
1.210 - printGraph(g1);
1.211 -
1.212 - cout << "2nd graph" << endl;
1.213 - printGraph(g2);
1.214 -
1.215 - cout << "merged graph" << endl;
1.216 - printGraph(gw);
1.217 -
1.218 - typedef ListGraph Graph3;
1.219 - //typedef SmartGraph Graph3;
1.220 - Graph3 g3;
1.221 - GW::NodeMap<Graph3::Node> gwn(gw);
1.222 - Graph3::NodeMap<GW::Node> g3n(g3);
1.223 - for (GW::NodeIt n(gw); n!=INVALID; ++n) {
1.224 - Graph3::Node m=g3.addNode();
1.225 - gwn.set(n, m);
1.226 - g3n.set(m, n);
1.227 - }
1.228 -
1.229 - typedef NewEdgeSetGraphWrapper<GW, Graph3> GWW;
1.230 -// {
1.231 -// checkConcept<StaticGraph, GWW>();
1.232 -// }
1.233 -
1.234 - GWW gww(gw, g3, gwn, g3n);
1.235 -
1.236 - for (Graph1::NodeIt n(g1); n!=INVALID; ++n) {
1.237 - g3.addEdge(gwn[sw], gwn[GW::Node(n,INVALID,false)]);
1.238 - }
1.239 -
1.240 -// for (Graph1::NodeIt n(g1); n!=INVALID; ++n) {
1.241 -// gww.addEdge(sw, GW::Node(n,INVALID,false));
1.242 -// }
1.243 -
1.244 - cout << "new edges" << endl;
1.245 - printGraph(g3);
1.246 -
1.247 - cout << "new edges in the new graph" << endl;
1.248 - printGraph(gww);
1.249 -
1.250 - typedef AugmentingGraphWrapper<GW, GWW> GWWW;
1.251 -// {
1.252 -// checkConcept<StaticGraph, GWWW>();
1.253 -// }
1.254 - GWWW gwww(gw, gww);
1.255 -
1.256 - cout << "new edges merged into the original graph" << endl;
1.257 - printGraph(gwww);
1.258 -
1.259 - }
1.260 -
1.261 -}