deba@1198
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
deba@1198
|
2 |
*
|
deba@1198
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
deba@1198
|
4 |
*
|
alpar@1270
|
5 |
* Copyright (C) 2003-2013
|
deba@1198
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@1198
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@1198
|
8 |
*
|
deba@1198
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@1198
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@1198
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@1198
|
12 |
*
|
deba@1198
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@1198
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@1198
|
15 |
* purpose.
|
deba@1198
|
16 |
*
|
deba@1198
|
17 |
*/
|
deba@1198
|
18 |
|
deba@1198
|
19 |
#include <string>
|
deba@1198
|
20 |
|
deba@1198
|
21 |
#include <lemon/concepts/digraph.h>
|
deba@1198
|
22 |
#include <lemon/concepts/graph.h>
|
deba@1198
|
23 |
#include <lemon/concepts/bpgraph.h>
|
deba@1198
|
24 |
|
deba@1198
|
25 |
#include <lemon/list_graph.h>
|
deba@1198
|
26 |
#include <lemon/smart_graph.h>
|
deba@1198
|
27 |
#include <lemon/lgf_reader.h>
|
deba@1198
|
28 |
|
deba@1198
|
29 |
#include "test_tools.h"
|
deba@1198
|
30 |
|
deba@1198
|
31 |
struct ReaderConverter {
|
deba@1198
|
32 |
int operator()(const std::string& str) const {
|
deba@1198
|
33 |
return str.length();
|
deba@1198
|
34 |
}
|
deba@1198
|
35 |
};
|
deba@1198
|
36 |
|
deba@1198
|
37 |
struct WriterConverter {
|
deba@1198
|
38 |
std::string operator()(int value) const {
|
deba@1198
|
39 |
return std::string(value, '*');
|
deba@1198
|
40 |
}
|
deba@1198
|
41 |
};
|
deba@1198
|
42 |
|
deba@1198
|
43 |
void checkDigraphReaderCompile() {
|
deba@1198
|
44 |
typedef lemon::concepts::ExtendableDigraphComponent<
|
deba@1198
|
45 |
lemon::concepts::Digraph> Digraph;
|
deba@1198
|
46 |
Digraph digraph;
|
deba@1198
|
47 |
Digraph::NodeMap<int> node_map(digraph);
|
deba@1198
|
48 |
Digraph::ArcMap<int> arc_map(digraph);
|
deba@1198
|
49 |
Digraph::Node node;
|
deba@1198
|
50 |
Digraph::Arc arc;
|
deba@1198
|
51 |
int attr;
|
deba@1198
|
52 |
|
deba@1198
|
53 |
lemon::DigraphReader<Digraph> reader(digraph, "filename");
|
deba@1198
|
54 |
reader.nodeMap("node_map", node_map);
|
deba@1198
|
55 |
reader.nodeMap("node_map", node_map, ReaderConverter());
|
deba@1198
|
56 |
reader.arcMap("arc_map", arc_map);
|
deba@1198
|
57 |
reader.arcMap("arc_map", arc_map, ReaderConverter());
|
deba@1198
|
58 |
reader.attribute("attr", attr);
|
deba@1198
|
59 |
reader.attribute("attr", attr, ReaderConverter());
|
deba@1198
|
60 |
reader.node("node", node);
|
deba@1198
|
61 |
reader.arc("arc", arc);
|
deba@1198
|
62 |
|
deba@1198
|
63 |
reader.nodes("alt_nodes_caption");
|
deba@1198
|
64 |
reader.arcs("alt_arcs_caption");
|
deba@1198
|
65 |
reader.attributes("alt_attrs_caption");
|
deba@1198
|
66 |
|
deba@1198
|
67 |
reader.useNodes(node_map);
|
deba@1198
|
68 |
reader.useNodes(node_map, WriterConverter());
|
deba@1198
|
69 |
reader.useArcs(arc_map);
|
deba@1198
|
70 |
reader.useArcs(arc_map, WriterConverter());
|
deba@1198
|
71 |
|
deba@1198
|
72 |
reader.skipNodes();
|
deba@1198
|
73 |
reader.skipArcs();
|
deba@1198
|
74 |
|
deba@1198
|
75 |
reader.run();
|
deba@1198
|
76 |
|
deba@1198
|
77 |
lemon::DigraphReader<Digraph> reader2(digraph, std::cin);
|
deba@1198
|
78 |
}
|
deba@1198
|
79 |
|
deba@1198
|
80 |
void checkDigraphWriterCompile() {
|
deba@1198
|
81 |
typedef lemon::concepts::Digraph Digraph;
|
deba@1198
|
82 |
Digraph digraph;
|
deba@1198
|
83 |
Digraph::NodeMap<int> node_map(digraph);
|
deba@1198
|
84 |
Digraph::ArcMap<int> arc_map(digraph);
|
deba@1198
|
85 |
Digraph::Node node;
|
deba@1198
|
86 |
Digraph::Arc arc;
|
deba@1198
|
87 |
int attr;
|
deba@1198
|
88 |
|
deba@1198
|
89 |
lemon::DigraphWriter<Digraph> writer(digraph, "filename");
|
deba@1198
|
90 |
writer.nodeMap("node_map", node_map);
|
deba@1198
|
91 |
writer.nodeMap("node_map", node_map, WriterConverter());
|
deba@1198
|
92 |
writer.arcMap("arc_map", arc_map);
|
deba@1198
|
93 |
writer.arcMap("arc_map", arc_map, WriterConverter());
|
deba@1198
|
94 |
writer.attribute("attr", attr);
|
deba@1198
|
95 |
writer.attribute("attr", attr, WriterConverter());
|
deba@1198
|
96 |
writer.node("node", node);
|
deba@1198
|
97 |
writer.arc("arc", arc);
|
deba@1198
|
98 |
|
deba@1198
|
99 |
writer.nodes("alt_nodes_caption");
|
deba@1198
|
100 |
writer.arcs("alt_arcs_caption");
|
deba@1198
|
101 |
writer.attributes("alt_attrs_caption");
|
deba@1198
|
102 |
|
deba@1198
|
103 |
writer.skipNodes();
|
deba@1198
|
104 |
writer.skipArcs();
|
deba@1198
|
105 |
|
deba@1198
|
106 |
writer.run();
|
deba@1198
|
107 |
}
|
deba@1198
|
108 |
|
deba@1198
|
109 |
void checkGraphReaderCompile() {
|
deba@1198
|
110 |
typedef lemon::concepts::ExtendableGraphComponent<
|
deba@1198
|
111 |
lemon::concepts::Graph> Graph;
|
deba@1198
|
112 |
Graph graph;
|
deba@1198
|
113 |
Graph::NodeMap<int> node_map(graph);
|
deba@1198
|
114 |
Graph::ArcMap<int> arc_map(graph);
|
deba@1198
|
115 |
Graph::EdgeMap<int> edge_map(graph);
|
deba@1198
|
116 |
Graph::Node node;
|
deba@1198
|
117 |
Graph::Arc arc;
|
deba@1198
|
118 |
Graph::Edge edge;
|
deba@1198
|
119 |
int attr;
|
deba@1198
|
120 |
|
deba@1198
|
121 |
lemon::GraphReader<Graph> reader(graph, "filename");
|
deba@1198
|
122 |
reader.nodeMap("node_map", node_map);
|
deba@1198
|
123 |
reader.nodeMap("node_map", node_map, ReaderConverter());
|
deba@1198
|
124 |
reader.arcMap("arc_map", arc_map);
|
deba@1198
|
125 |
reader.arcMap("arc_map", arc_map, ReaderConverter());
|
deba@1198
|
126 |
reader.edgeMap("edge_map", edge_map);
|
deba@1198
|
127 |
reader.edgeMap("edge_map", edge_map, ReaderConverter());
|
deba@1198
|
128 |
reader.attribute("attr", attr);
|
deba@1198
|
129 |
reader.attribute("attr", attr, ReaderConverter());
|
deba@1198
|
130 |
reader.node("node", node);
|
deba@1198
|
131 |
reader.arc("arc", arc);
|
deba@1198
|
132 |
|
deba@1198
|
133 |
reader.nodes("alt_nodes_caption");
|
deba@1198
|
134 |
reader.edges("alt_edges_caption");
|
deba@1198
|
135 |
reader.attributes("alt_attrs_caption");
|
deba@1198
|
136 |
|
deba@1198
|
137 |
reader.useNodes(node_map);
|
deba@1198
|
138 |
reader.useNodes(node_map, WriterConverter());
|
deba@1198
|
139 |
reader.useEdges(edge_map);
|
deba@1198
|
140 |
reader.useEdges(edge_map, WriterConverter());
|
deba@1198
|
141 |
|
deba@1198
|
142 |
reader.skipNodes();
|
deba@1198
|
143 |
reader.skipEdges();
|
deba@1198
|
144 |
|
deba@1198
|
145 |
reader.run();
|
deba@1198
|
146 |
|
deba@1198
|
147 |
lemon::GraphReader<Graph> reader2(graph, std::cin);
|
deba@1198
|
148 |
}
|
deba@1198
|
149 |
|
deba@1198
|
150 |
void checkGraphWriterCompile() {
|
deba@1198
|
151 |
typedef lemon::concepts::Graph Graph;
|
deba@1198
|
152 |
Graph graph;
|
deba@1198
|
153 |
Graph::NodeMap<int> node_map(graph);
|
deba@1198
|
154 |
Graph::ArcMap<int> arc_map(graph);
|
deba@1198
|
155 |
Graph::EdgeMap<int> edge_map(graph);
|
deba@1198
|
156 |
Graph::Node node;
|
deba@1198
|
157 |
Graph::Arc arc;
|
deba@1198
|
158 |
Graph::Edge edge;
|
deba@1198
|
159 |
int attr;
|
deba@1198
|
160 |
|
deba@1198
|
161 |
lemon::GraphWriter<Graph> writer(graph, "filename");
|
deba@1198
|
162 |
writer.nodeMap("node_map", node_map);
|
deba@1198
|
163 |
writer.nodeMap("node_map", node_map, WriterConverter());
|
deba@1198
|
164 |
writer.arcMap("arc_map", arc_map);
|
deba@1198
|
165 |
writer.arcMap("arc_map", arc_map, WriterConverter());
|
deba@1198
|
166 |
writer.edgeMap("edge_map", edge_map);
|
deba@1198
|
167 |
writer.edgeMap("edge_map", edge_map, WriterConverter());
|
deba@1198
|
168 |
writer.attribute("attr", attr);
|
deba@1198
|
169 |
writer.attribute("attr", attr, WriterConverter());
|
deba@1198
|
170 |
writer.node("node", node);
|
deba@1198
|
171 |
writer.arc("arc", arc);
|
deba@1198
|
172 |
writer.edge("edge", edge);
|
deba@1198
|
173 |
|
deba@1198
|
174 |
writer.nodes("alt_nodes_caption");
|
deba@1198
|
175 |
writer.edges("alt_edges_caption");
|
deba@1198
|
176 |
writer.attributes("alt_attrs_caption");
|
deba@1198
|
177 |
|
deba@1198
|
178 |
writer.skipNodes();
|
deba@1198
|
179 |
writer.skipEdges();
|
deba@1198
|
180 |
|
deba@1198
|
181 |
writer.run();
|
deba@1198
|
182 |
|
deba@1198
|
183 |
lemon::GraphWriter<Graph> writer2(graph, std::cout);
|
deba@1198
|
184 |
}
|
deba@1198
|
185 |
|
deba@1198
|
186 |
void checkBpGraphReaderCompile() {
|
deba@1198
|
187 |
typedef lemon::concepts::ExtendableBpGraphComponent<
|
deba@1198
|
188 |
lemon::concepts::BpGraph> BpGraph;
|
deba@1198
|
189 |
BpGraph graph;
|
deba@1198
|
190 |
BpGraph::NodeMap<int> node_map(graph);
|
deba@1198
|
191 |
BpGraph::RedNodeMap<int> red_node_map(graph);
|
deba@1198
|
192 |
BpGraph::BlueNodeMap<int> blue_node_map(graph);
|
deba@1198
|
193 |
BpGraph::ArcMap<int> arc_map(graph);
|
deba@1198
|
194 |
BpGraph::EdgeMap<int> edge_map(graph);
|
deba@1198
|
195 |
BpGraph::Node node;
|
deba@1198
|
196 |
BpGraph::RedNode red_node;
|
deba@1198
|
197 |
BpGraph::BlueNode blue_node;
|
deba@1198
|
198 |
BpGraph::Arc arc;
|
deba@1198
|
199 |
BpGraph::Edge edge;
|
deba@1198
|
200 |
int attr;
|
deba@1198
|
201 |
|
deba@1198
|
202 |
lemon::BpGraphReader<BpGraph> reader(graph, "filename");
|
deba@1198
|
203 |
reader.nodeMap("node_map", node_map);
|
deba@1198
|
204 |
reader.nodeMap("node_map", node_map, ReaderConverter());
|
deba@1198
|
205 |
reader.redNodeMap("red_node_map", red_node_map);
|
deba@1198
|
206 |
reader.redNodeMap("red_node_map", red_node_map, ReaderConverter());
|
deba@1198
|
207 |
reader.blueNodeMap("blue_node_map", blue_node_map);
|
deba@1198
|
208 |
reader.blueNodeMap("blue_node_map", blue_node_map, ReaderConverter());
|
deba@1198
|
209 |
reader.arcMap("arc_map", arc_map);
|
deba@1198
|
210 |
reader.arcMap("arc_map", arc_map, ReaderConverter());
|
deba@1198
|
211 |
reader.edgeMap("edge_map", edge_map);
|
deba@1198
|
212 |
reader.edgeMap("edge_map", edge_map, ReaderConverter());
|
deba@1198
|
213 |
reader.attribute("attr", attr);
|
deba@1198
|
214 |
reader.attribute("attr", attr, ReaderConverter());
|
deba@1198
|
215 |
reader.node("node", node);
|
deba@1198
|
216 |
reader.redNode("red_node", red_node);
|
deba@1198
|
217 |
reader.blueNode("blue_node", blue_node);
|
deba@1198
|
218 |
reader.arc("arc", arc);
|
deba@1198
|
219 |
|
deba@1198
|
220 |
reader.nodes("alt_nodes_caption");
|
deba@1198
|
221 |
reader.edges("alt_edges_caption");
|
deba@1198
|
222 |
reader.attributes("alt_attrs_caption");
|
deba@1198
|
223 |
|
deba@1198
|
224 |
reader.useNodes(node_map);
|
deba@1198
|
225 |
reader.useNodes(node_map, WriterConverter());
|
deba@1198
|
226 |
reader.useEdges(edge_map);
|
deba@1198
|
227 |
reader.useEdges(edge_map, WriterConverter());
|
deba@1198
|
228 |
|
deba@1198
|
229 |
reader.skipNodes();
|
deba@1198
|
230 |
reader.skipEdges();
|
deba@1198
|
231 |
|
deba@1198
|
232 |
reader.run();
|
deba@1198
|
233 |
|
deba@1198
|
234 |
lemon::BpGraphReader<BpGraph> reader2(graph, std::cin);
|
deba@1198
|
235 |
}
|
deba@1198
|
236 |
|
deba@1198
|
237 |
void checkBpGraphWriterCompile() {
|
deba@1198
|
238 |
typedef lemon::concepts::BpGraph BpGraph;
|
deba@1198
|
239 |
BpGraph graph;
|
deba@1198
|
240 |
BpGraph::NodeMap<int> node_map(graph);
|
deba@1198
|
241 |
BpGraph::RedNodeMap<int> red_node_map(graph);
|
deba@1198
|
242 |
BpGraph::BlueNodeMap<int> blue_node_map(graph);
|
deba@1198
|
243 |
BpGraph::ArcMap<int> arc_map(graph);
|
deba@1198
|
244 |
BpGraph::EdgeMap<int> edge_map(graph);
|
deba@1198
|
245 |
BpGraph::Node node;
|
deba@1198
|
246 |
BpGraph::RedNode red_node;
|
deba@1198
|
247 |
BpGraph::BlueNode blue_node;
|
deba@1198
|
248 |
BpGraph::Arc arc;
|
deba@1198
|
249 |
BpGraph::Edge edge;
|
deba@1198
|
250 |
int attr;
|
deba@1198
|
251 |
|
deba@1198
|
252 |
lemon::BpGraphWriter<BpGraph> writer(graph, "filename");
|
deba@1198
|
253 |
writer.nodeMap("node_map", node_map);
|
deba@1198
|
254 |
writer.nodeMap("node_map", node_map, WriterConverter());
|
deba@1198
|
255 |
writer.redNodeMap("red_node_map", red_node_map);
|
deba@1198
|
256 |
writer.redNodeMap("red_node_map", red_node_map, WriterConverter());
|
deba@1198
|
257 |
writer.blueNodeMap("blue_node_map", blue_node_map);
|
deba@1198
|
258 |
writer.blueNodeMap("blue_node_map", blue_node_map, WriterConverter());
|
deba@1198
|
259 |
writer.arcMap("arc_map", arc_map);
|
deba@1198
|
260 |
writer.arcMap("arc_map", arc_map, WriterConverter());
|
deba@1198
|
261 |
writer.edgeMap("edge_map", edge_map);
|
deba@1198
|
262 |
writer.edgeMap("edge_map", edge_map, WriterConverter());
|
deba@1198
|
263 |
writer.attribute("attr", attr);
|
deba@1198
|
264 |
writer.attribute("attr", attr, WriterConverter());
|
deba@1198
|
265 |
writer.node("node", node);
|
deba@1198
|
266 |
writer.redNode("red_node", red_node);
|
deba@1198
|
267 |
writer.blueNode("blue_node", blue_node);
|
deba@1198
|
268 |
writer.arc("arc", arc);
|
deba@1198
|
269 |
|
deba@1198
|
270 |
writer.nodes("alt_nodes_caption");
|
deba@1198
|
271 |
writer.edges("alt_edges_caption");
|
deba@1198
|
272 |
writer.attributes("alt_attrs_caption");
|
deba@1198
|
273 |
|
deba@1198
|
274 |
writer.skipNodes();
|
deba@1198
|
275 |
writer.skipEdges();
|
deba@1198
|
276 |
|
deba@1198
|
277 |
writer.run();
|
deba@1198
|
278 |
|
deba@1198
|
279 |
lemon::BpGraphWriter<BpGraph> writer2(graph, std::cout);
|
deba@1198
|
280 |
}
|
deba@1198
|
281 |
|
deba@1198
|
282 |
void checkDigraphReaderWriter() {
|
deba@1198
|
283 |
typedef lemon::SmartDigraph Digraph;
|
deba@1198
|
284 |
Digraph digraph;
|
deba@1198
|
285 |
Digraph::Node n1 = digraph.addNode();
|
deba@1198
|
286 |
Digraph::Node n2 = digraph.addNode();
|
deba@1198
|
287 |
Digraph::Node n3 = digraph.addNode();
|
deba@1198
|
288 |
|
deba@1198
|
289 |
Digraph::Arc a1 = digraph.addArc(n1, n2);
|
deba@1198
|
290 |
Digraph::Arc a2 = digraph.addArc(n2, n3);
|
deba@1198
|
291 |
|
deba@1198
|
292 |
Digraph::NodeMap<int> node_map(digraph);
|
deba@1198
|
293 |
node_map[n1] = 11;
|
deba@1198
|
294 |
node_map[n2] = 12;
|
deba@1198
|
295 |
node_map[n3] = 13;
|
deba@1198
|
296 |
|
deba@1198
|
297 |
Digraph::ArcMap<int> arc_map(digraph);
|
deba@1198
|
298 |
arc_map[a1] = 21;
|
deba@1198
|
299 |
arc_map[a2] = 22;
|
deba@1198
|
300 |
|
deba@1198
|
301 |
int attr = 100;
|
deba@1198
|
302 |
|
deba@1198
|
303 |
std::ostringstream os;
|
deba@1198
|
304 |
lemon::DigraphWriter<Digraph> writer(digraph, os);
|
deba@1198
|
305 |
|
deba@1198
|
306 |
writer.nodeMap("node_map1", node_map);
|
deba@1198
|
307 |
writer.nodeMap("node_map2", node_map, WriterConverter());
|
deba@1198
|
308 |
writer.arcMap("arc_map1", arc_map);
|
deba@1198
|
309 |
writer.arcMap("arc_map2", arc_map, WriterConverter());
|
deba@1198
|
310 |
writer.node("node", n2);
|
deba@1198
|
311 |
writer.arc("arc", a1);
|
deba@1198
|
312 |
writer.attribute("attr1", attr);
|
deba@1198
|
313 |
writer.attribute("attr2", attr, WriterConverter());
|
deba@1198
|
314 |
|
deba@1198
|
315 |
writer.run();
|
deba@1198
|
316 |
|
deba@1198
|
317 |
typedef lemon::ListDigraph ExpDigraph;
|
deba@1198
|
318 |
ExpDigraph exp_digraph;
|
deba@1198
|
319 |
ExpDigraph::NodeMap<int> exp_node_map1(exp_digraph);
|
deba@1198
|
320 |
ExpDigraph::NodeMap<int> exp_node_map2(exp_digraph);
|
deba@1198
|
321 |
ExpDigraph::ArcMap<int> exp_arc_map1(exp_digraph);
|
deba@1198
|
322 |
ExpDigraph::ArcMap<int> exp_arc_map2(exp_digraph);
|
deba@1198
|
323 |
ExpDigraph::Node exp_n2;
|
deba@1198
|
324 |
ExpDigraph::Arc exp_a1;
|
deba@1198
|
325 |
int exp_attr1;
|
deba@1198
|
326 |
int exp_attr2;
|
deba@1198
|
327 |
|
deba@1198
|
328 |
std::istringstream is(os.str());
|
deba@1198
|
329 |
lemon::DigraphReader<ExpDigraph> reader(exp_digraph, is);
|
deba@1198
|
330 |
|
deba@1198
|
331 |
reader.nodeMap("node_map1", exp_node_map1);
|
deba@1198
|
332 |
reader.nodeMap("node_map2", exp_node_map2, ReaderConverter());
|
deba@1198
|
333 |
reader.arcMap("arc_map1", exp_arc_map1);
|
deba@1198
|
334 |
reader.arcMap("arc_map2", exp_arc_map2, ReaderConverter());
|
deba@1198
|
335 |
reader.node("node", exp_n2);
|
deba@1198
|
336 |
reader.arc("arc", exp_a1);
|
deba@1198
|
337 |
reader.attribute("attr1", exp_attr1);
|
deba@1198
|
338 |
reader.attribute("attr2", exp_attr2, ReaderConverter());
|
deba@1198
|
339 |
|
deba@1198
|
340 |
reader.run();
|
deba@1198
|
341 |
|
deba@1198
|
342 |
check(lemon::countNodes(exp_digraph) == 3, "Wrong number of nodes");
|
deba@1198
|
343 |
check(lemon::countArcs(exp_digraph) == 2, "Wrong number of arcs");
|
deba@1198
|
344 |
check(exp_node_map1[exp_n2] == 12, "Wrong map value");
|
deba@1198
|
345 |
check(exp_node_map2[exp_n2] == 12, "Wrong map value");
|
deba@1198
|
346 |
check(exp_arc_map1[exp_a1] == 21, "Wrong map value");
|
deba@1198
|
347 |
check(exp_arc_map2[exp_a1] == 21, "Wrong map value");
|
deba@1198
|
348 |
check(exp_attr1 == 100, "Wrong attr value");
|
deba@1198
|
349 |
check(exp_attr2 == 100, "Wrong attr value");
|
deba@1198
|
350 |
}
|
deba@1198
|
351 |
|
deba@1198
|
352 |
void checkGraphReaderWriter() {
|
deba@1198
|
353 |
typedef lemon::SmartGraph Graph;
|
deba@1198
|
354 |
Graph graph;
|
deba@1198
|
355 |
Graph::Node n1 = graph.addNode();
|
deba@1198
|
356 |
Graph::Node n2 = graph.addNode();
|
deba@1198
|
357 |
Graph::Node n3 = graph.addNode();
|
deba@1198
|
358 |
|
deba@1198
|
359 |
Graph::Edge e1 = graph.addEdge(n1, n2);
|
deba@1198
|
360 |
Graph::Edge e2 = graph.addEdge(n2, n3);
|
deba@1198
|
361 |
|
deba@1198
|
362 |
Graph::NodeMap<int> node_map(graph);
|
deba@1198
|
363 |
node_map[n1] = 11;
|
deba@1198
|
364 |
node_map[n2] = 12;
|
deba@1198
|
365 |
node_map[n3] = 13;
|
deba@1198
|
366 |
|
deba@1198
|
367 |
Graph::EdgeMap<int> edge_map(graph);
|
deba@1198
|
368 |
edge_map[e1] = 21;
|
deba@1198
|
369 |
edge_map[e2] = 22;
|
deba@1198
|
370 |
|
deba@1198
|
371 |
Graph::ArcMap<int> arc_map(graph);
|
deba@1198
|
372 |
arc_map[graph.direct(e1, true)] = 211;
|
deba@1198
|
373 |
arc_map[graph.direct(e1, false)] = 212;
|
deba@1198
|
374 |
arc_map[graph.direct(e2, true)] = 221;
|
deba@1198
|
375 |
arc_map[graph.direct(e2, false)] = 222;
|
deba@1198
|
376 |
|
deba@1198
|
377 |
int attr = 100;
|
deba@1198
|
378 |
|
deba@1198
|
379 |
std::ostringstream os;
|
deba@1198
|
380 |
lemon::GraphWriter<Graph> writer(graph, os);
|
deba@1198
|
381 |
|
deba@1198
|
382 |
writer.nodeMap("node_map1", node_map);
|
deba@1198
|
383 |
writer.nodeMap("node_map2", node_map, WriterConverter());
|
deba@1198
|
384 |
writer.edgeMap("edge_map1", edge_map);
|
deba@1198
|
385 |
writer.edgeMap("edge_map2", edge_map, WriterConverter());
|
deba@1198
|
386 |
writer.arcMap("arc_map1", arc_map);
|
deba@1198
|
387 |
writer.arcMap("arc_map2", arc_map, WriterConverter());
|
alpar@1270
|
388 |
writer.node("node", n2);
|
deba@1198
|
389 |
writer.edge("edge", e1);
|
deba@1198
|
390 |
writer.arc("arc", graph.direct(e1, false));
|
deba@1198
|
391 |
writer.attribute("attr1", attr);
|
deba@1198
|
392 |
writer.attribute("attr2", attr, WriterConverter());
|
deba@1198
|
393 |
|
deba@1198
|
394 |
writer.run();
|
deba@1198
|
395 |
|
deba@1198
|
396 |
typedef lemon::ListGraph ExpGraph;
|
deba@1198
|
397 |
ExpGraph exp_graph;
|
deba@1198
|
398 |
ExpGraph::NodeMap<int> exp_node_map1(exp_graph);
|
deba@1198
|
399 |
ExpGraph::NodeMap<int> exp_node_map2(exp_graph);
|
deba@1198
|
400 |
ExpGraph::EdgeMap<int> exp_edge_map1(exp_graph);
|
deba@1198
|
401 |
ExpGraph::EdgeMap<int> exp_edge_map2(exp_graph);
|
deba@1198
|
402 |
ExpGraph::ArcMap<int> exp_arc_map1(exp_graph);
|
deba@1198
|
403 |
ExpGraph::ArcMap<int> exp_arc_map2(exp_graph);
|
deba@1198
|
404 |
ExpGraph::Node exp_n2;
|
deba@1198
|
405 |
ExpGraph::Edge exp_e1;
|
deba@1198
|
406 |
ExpGraph::Arc exp_a1;
|
deba@1198
|
407 |
int exp_attr1;
|
deba@1198
|
408 |
int exp_attr2;
|
deba@1198
|
409 |
|
deba@1198
|
410 |
std::istringstream is(os.str());
|
deba@1198
|
411 |
lemon::GraphReader<ExpGraph> reader(exp_graph, is);
|
deba@1198
|
412 |
|
deba@1198
|
413 |
reader.nodeMap("node_map1", exp_node_map1);
|
deba@1198
|
414 |
reader.nodeMap("node_map2", exp_node_map2, ReaderConverter());
|
deba@1198
|
415 |
reader.edgeMap("edge_map1", exp_edge_map1);
|
deba@1198
|
416 |
reader.edgeMap("edge_map2", exp_edge_map2, ReaderConverter());
|
deba@1198
|
417 |
reader.arcMap("arc_map1", exp_arc_map1);
|
deba@1198
|
418 |
reader.arcMap("arc_map2", exp_arc_map2, ReaderConverter());
|
deba@1198
|
419 |
reader.node("node", exp_n2);
|
deba@1198
|
420 |
reader.edge("edge", exp_e1);
|
deba@1198
|
421 |
reader.arc("arc", exp_a1);
|
deba@1198
|
422 |
reader.attribute("attr1", exp_attr1);
|
deba@1198
|
423 |
reader.attribute("attr2", exp_attr2, ReaderConverter());
|
deba@1198
|
424 |
|
deba@1198
|
425 |
reader.run();
|
deba@1198
|
426 |
|
deba@1198
|
427 |
check(lemon::countNodes(exp_graph) == 3, "Wrong number of nodes");
|
deba@1198
|
428 |
check(lemon::countEdges(exp_graph) == 2, "Wrong number of edges");
|
deba@1198
|
429 |
check(lemon::countArcs(exp_graph) == 4, "Wrong number of arcs");
|
deba@1198
|
430 |
check(exp_node_map1[exp_n2] == 12, "Wrong map value");
|
deba@1198
|
431 |
check(exp_node_map2[exp_n2] == 12, "Wrong map value");
|
deba@1198
|
432 |
check(exp_edge_map1[exp_e1] == 21, "Wrong map value");
|
deba@1198
|
433 |
check(exp_edge_map2[exp_e1] == 21, "Wrong map value");
|
deba@1198
|
434 |
check(exp_arc_map1[exp_a1] == 212, "Wrong map value");
|
deba@1198
|
435 |
check(exp_arc_map2[exp_a1] == 212, "Wrong map value");
|
deba@1198
|
436 |
check(exp_attr1 == 100, "Wrong attr value");
|
deba@1198
|
437 |
check(exp_attr2 == 100, "Wrong attr value");
|
deba@1198
|
438 |
}
|
deba@1198
|
439 |
|
deba@1198
|
440 |
void checkBpGraphReaderWriter() {
|
deba@1198
|
441 |
typedef lemon::SmartBpGraph Graph;
|
deba@1198
|
442 |
Graph graph;
|
deba@1198
|
443 |
Graph::RedNode rn1 = graph.addRedNode();
|
deba@1198
|
444 |
Graph::RedNode rn2 = graph.addRedNode();
|
deba@1198
|
445 |
Graph::RedNode rn3 = graph.addRedNode();
|
deba@1198
|
446 |
Graph::BlueNode bn1 = graph.addBlueNode();
|
deba@1198
|
447 |
Graph::BlueNode bn2 = graph.addBlueNode();
|
deba@1198
|
448 |
Graph::Node n = bn1;
|
deba@1198
|
449 |
|
deba@1198
|
450 |
Graph::Edge e1 = graph.addEdge(rn1, bn1);
|
deba@1198
|
451 |
Graph::Edge e2 = graph.addEdge(rn2, bn1);
|
deba@1198
|
452 |
|
deba@1198
|
453 |
Graph::NodeMap<int> node_map(graph);
|
deba@1198
|
454 |
node_map[rn1] = 11;
|
deba@1198
|
455 |
node_map[rn2] = 12;
|
deba@1198
|
456 |
node_map[rn3] = 13;
|
deba@1198
|
457 |
node_map[bn1] = 14;
|
deba@1198
|
458 |
node_map[bn2] = 15;
|
deba@1198
|
459 |
|
deba@1198
|
460 |
Graph::NodeMap<int> red_node_map(graph);
|
deba@1198
|
461 |
red_node_map[rn1] = 411;
|
deba@1198
|
462 |
red_node_map[rn2] = 412;
|
deba@1198
|
463 |
red_node_map[rn3] = 413;
|
deba@1198
|
464 |
|
deba@1198
|
465 |
Graph::NodeMap<int> blue_node_map(graph);
|
deba@1198
|
466 |
blue_node_map[bn1] = 414;
|
deba@1198
|
467 |
blue_node_map[bn2] = 415;
|
deba@1198
|
468 |
|
deba@1198
|
469 |
Graph::EdgeMap<int> edge_map(graph);
|
deba@1198
|
470 |
edge_map[e1] = 21;
|
deba@1198
|
471 |
edge_map[e2] = 22;
|
deba@1198
|
472 |
|
deba@1198
|
473 |
Graph::ArcMap<int> arc_map(graph);
|
deba@1198
|
474 |
arc_map[graph.direct(e1, true)] = 211;
|
deba@1198
|
475 |
arc_map[graph.direct(e1, false)] = 212;
|
deba@1198
|
476 |
arc_map[graph.direct(e2, true)] = 221;
|
deba@1198
|
477 |
arc_map[graph.direct(e2, false)] = 222;
|
deba@1198
|
478 |
|
deba@1198
|
479 |
int attr = 100;
|
deba@1198
|
480 |
|
deba@1198
|
481 |
std::ostringstream os;
|
deba@1198
|
482 |
lemon::BpGraphWriter<Graph> writer(graph, os);
|
deba@1198
|
483 |
|
deba@1198
|
484 |
writer.nodeMap("node_map1", node_map);
|
deba@1198
|
485 |
writer.nodeMap("node_map2", node_map, WriterConverter());
|
deba@1198
|
486 |
writer.nodeMap("red_node_map1", red_node_map);
|
deba@1198
|
487 |
writer.nodeMap("red_node_map2", red_node_map, WriterConverter());
|
deba@1198
|
488 |
writer.nodeMap("blue_node_map1", blue_node_map);
|
deba@1198
|
489 |
writer.nodeMap("blue_node_map2", blue_node_map, WriterConverter());
|
deba@1198
|
490 |
writer.edgeMap("edge_map1", edge_map);
|
deba@1198
|
491 |
writer.edgeMap("edge_map2", edge_map, WriterConverter());
|
deba@1198
|
492 |
writer.arcMap("arc_map1", arc_map);
|
deba@1198
|
493 |
writer.arcMap("arc_map2", arc_map, WriterConverter());
|
deba@1198
|
494 |
writer.node("node", n);
|
alpar@1270
|
495 |
writer.redNode("red_node", rn1);
|
deba@1198
|
496 |
writer.blueNode("blue_node", bn2);
|
deba@1198
|
497 |
writer.edge("edge", e1);
|
deba@1198
|
498 |
writer.arc("arc", graph.direct(e1, false));
|
deba@1198
|
499 |
writer.attribute("attr1", attr);
|
deba@1198
|
500 |
writer.attribute("attr2", attr, WriterConverter());
|
deba@1198
|
501 |
|
deba@1198
|
502 |
writer.run();
|
deba@1198
|
503 |
|
deba@1198
|
504 |
typedef lemon::ListBpGraph ExpGraph;
|
deba@1198
|
505 |
ExpGraph exp_graph;
|
deba@1198
|
506 |
ExpGraph::NodeMap<int> exp_node_map1(exp_graph);
|
deba@1198
|
507 |
ExpGraph::NodeMap<int> exp_node_map2(exp_graph);
|
deba@1198
|
508 |
ExpGraph::RedNodeMap<int> exp_red_node_map1(exp_graph);
|
deba@1198
|
509 |
ExpGraph::RedNodeMap<int> exp_red_node_map2(exp_graph);
|
deba@1198
|
510 |
ExpGraph::BlueNodeMap<int> exp_blue_node_map1(exp_graph);
|
deba@1198
|
511 |
ExpGraph::BlueNodeMap<int> exp_blue_node_map2(exp_graph);
|
deba@1198
|
512 |
ExpGraph::EdgeMap<int> exp_edge_map1(exp_graph);
|
deba@1198
|
513 |
ExpGraph::EdgeMap<int> exp_edge_map2(exp_graph);
|
deba@1198
|
514 |
ExpGraph::ArcMap<int> exp_arc_map1(exp_graph);
|
deba@1198
|
515 |
ExpGraph::ArcMap<int> exp_arc_map2(exp_graph);
|
deba@1198
|
516 |
ExpGraph::Node exp_n;
|
deba@1198
|
517 |
ExpGraph::RedNode exp_rn1;
|
deba@1198
|
518 |
ExpGraph::BlueNode exp_bn2;
|
deba@1198
|
519 |
ExpGraph::Edge exp_e1;
|
deba@1198
|
520 |
ExpGraph::Arc exp_a1;
|
deba@1198
|
521 |
int exp_attr1;
|
deba@1198
|
522 |
int exp_attr2;
|
deba@1198
|
523 |
|
deba@1198
|
524 |
std::istringstream is(os.str());
|
deba@1198
|
525 |
lemon::BpGraphReader<ExpGraph> reader(exp_graph, is);
|
deba@1198
|
526 |
|
deba@1198
|
527 |
reader.nodeMap("node_map1", exp_node_map1);
|
deba@1198
|
528 |
reader.nodeMap("node_map2", exp_node_map2, ReaderConverter());
|
deba@1198
|
529 |
reader.redNodeMap("red_node_map1", exp_red_node_map1);
|
deba@1198
|
530 |
reader.redNodeMap("red_node_map2", exp_red_node_map2, ReaderConverter());
|
deba@1198
|
531 |
reader.blueNodeMap("blue_node_map1", exp_blue_node_map1);
|
deba@1198
|
532 |
reader.blueNodeMap("blue_node_map2", exp_blue_node_map2, ReaderConverter());
|
deba@1198
|
533 |
reader.edgeMap("edge_map1", exp_edge_map1);
|
deba@1198
|
534 |
reader.edgeMap("edge_map2", exp_edge_map2, ReaderConverter());
|
deba@1198
|
535 |
reader.arcMap("arc_map1", exp_arc_map1);
|
deba@1198
|
536 |
reader.arcMap("arc_map2", exp_arc_map2, ReaderConverter());
|
deba@1198
|
537 |
reader.node("node", exp_n);
|
deba@1198
|
538 |
reader.redNode("red_node", exp_rn1);
|
deba@1198
|
539 |
reader.blueNode("blue_node", exp_bn2);
|
deba@1198
|
540 |
reader.edge("edge", exp_e1);
|
deba@1198
|
541 |
reader.arc("arc", exp_a1);
|
deba@1198
|
542 |
reader.attribute("attr1", exp_attr1);
|
deba@1198
|
543 |
reader.attribute("attr2", exp_attr2, ReaderConverter());
|
deba@1198
|
544 |
|
deba@1198
|
545 |
reader.run();
|
deba@1198
|
546 |
|
deba@1198
|
547 |
check(lemon::countNodes(exp_graph) == 5, "Wrong number of nodes");
|
deba@1198
|
548 |
check(lemon::countRedNodes(exp_graph) == 3, "Wrong number of red nodes");
|
deba@1198
|
549 |
check(lemon::countBlueNodes(exp_graph) == 2, "Wrong number of blue nodes");
|
deba@1198
|
550 |
check(lemon::countEdges(exp_graph) == 2, "Wrong number of edges");
|
deba@1198
|
551 |
check(lemon::countArcs(exp_graph) == 4, "Wrong number of arcs");
|
deba@1198
|
552 |
check(exp_node_map1[exp_n] == 14, "Wrong map value");
|
deba@1198
|
553 |
check(exp_node_map2[exp_n] == 14, "Wrong map value");
|
deba@1198
|
554 |
check(exp_red_node_map1[exp_rn1] == 411, "Wrong map value");
|
deba@1198
|
555 |
check(exp_red_node_map2[exp_rn1] == 411, "Wrong map value");
|
deba@1198
|
556 |
check(exp_blue_node_map1[exp_bn2] == 415, "Wrong map value");
|
deba@1198
|
557 |
check(exp_blue_node_map2[exp_bn2] == 415, "Wrong map value");
|
deba@1198
|
558 |
check(exp_edge_map1[exp_e1] == 21, "Wrong map value");
|
deba@1198
|
559 |
check(exp_edge_map2[exp_e1] == 21, "Wrong map value");
|
deba@1198
|
560 |
check(exp_arc_map1[exp_a1] == 212, "Wrong map value");
|
deba@1198
|
561 |
check(exp_arc_map2[exp_a1] == 212, "Wrong map value");
|
deba@1198
|
562 |
check(exp_attr1 == 100, "Wrong attr value");
|
deba@1198
|
563 |
check(exp_attr2 == 100, "Wrong attr value");
|
deba@1198
|
564 |
}
|
deba@1198
|
565 |
|
deba@1198
|
566 |
|
deba@1198
|
567 |
int main() {
|
deba@1198
|
568 |
{ // Check digrpah
|
deba@1198
|
569 |
checkDigraphReaderWriter();
|
deba@1198
|
570 |
}
|
deba@1198
|
571 |
{ // Check graph
|
deba@1198
|
572 |
checkGraphReaderWriter();
|
deba@1198
|
573 |
}
|
deba@1198
|
574 |
{ // Check bipartite graph
|
deba@1198
|
575 |
checkBpGraphReaderWriter();
|
deba@1198
|
576 |
}
|
deba@1198
|
577 |
return 0;
|
deba@1198
|
578 |
}
|