deba@1032
|
1 |
#include <lemon/smart_graph.h>
|
deba@1037
|
2 |
|
deba@1037
|
3 |
#include "map_utils.h"
|
deba@1037
|
4 |
|
deba@1037
|
5 |
|
deba@1036
|
6 |
#include "graph_reader.h"
|
deba@1037
|
7 |
#include "graph_writer.h"
|
deba@1032
|
8 |
|
deba@1032
|
9 |
#include <iostream>
|
deba@1032
|
10 |
#include <fstream>
|
deba@1032
|
11 |
|
deba@1032
|
12 |
using namespace std;
|
deba@1032
|
13 |
using namespace lemon;
|
deba@1032
|
14 |
|
deba@1032
|
15 |
int main() {
|
deba@1032
|
16 |
ifstream input("test.lgf");
|
deba@1032
|
17 |
SmartGraph graph;
|
deba@1032
|
18 |
GraphReader<SmartGraph> reader(input, graph);
|
deba@1037
|
19 |
|
deba@1036
|
20 |
SmartGraph::NodeMap<int> id(graph);
|
deba@1115
|
21 |
reader.addNodeMap("id", id);
|
deba@1037
|
22 |
|
deba@1032
|
23 |
SmartGraph::NodeMap<int> cost(graph);
|
deba@1115
|
24 |
reader.addNodeMap("cost", cost);
|
deba@1037
|
25 |
|
deba@1032
|
26 |
SmartGraph::NodeMap<string> color(graph);
|
deba@1115
|
27 |
reader.addNodeMap("color", color);
|
deba@1037
|
28 |
|
deba@1036
|
29 |
SmartGraph::NodeMap<string> description(graph);
|
deba@1115
|
30 |
reader.addNodeMap<QuotedStringReader>("description", description);
|
deba@1037
|
31 |
|
deba@1036
|
32 |
SmartGraph::EdgeMap<char> mmap(graph);
|
deba@1115
|
33 |
reader.addEdgeMap("mmap", mmap);
|
deba@1037
|
34 |
|
deba@1036
|
35 |
reader.skipEdgeMap<QuotedStringReader>("description");
|
deba@1037
|
36 |
|
deba@1037
|
37 |
SmartGraph::Node source;
|
deba@1115
|
38 |
reader.addNode("source", source);
|
deba@1037
|
39 |
|
deba@1037
|
40 |
SmartGraph::Edge newedge;
|
deba@1115
|
41 |
reader.addEdge("newedge", newedge);
|
deba@1037
|
42 |
|
deba@1036
|
43 |
try {
|
deba@1036
|
44 |
reader.read();
|
deba@1036
|
45 |
} catch (IOException& e) {
|
deba@1036
|
46 |
cerr << e.what() << endl;
|
deba@1036
|
47 |
} catch (Exception e) {
|
deba@1036
|
48 |
cerr << e.what() << endl;
|
deba@1036
|
49 |
}
|
deba@1115
|
50 |
|
deba@1032
|
51 |
for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
|
deba@1036
|
52 |
cout << cost[it] << ' ' << color[it] << ' ' << description[it] << endl;
|
deba@1036
|
53 |
}
|
deba@1036
|
54 |
|
deba@1036
|
55 |
for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
|
deba@1115
|
56 |
cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' <<
|
deba@1115
|
57 |
id[graph.target(it)] << endl;
|
deba@1032
|
58 |
}
|
deba@1037
|
59 |
|
deba@1115
|
60 |
cout << id[source] << ' ' << cost[source] << ' ' <<
|
deba@1115
|
61 |
color[source] << ' ' << description[source] << endl;
|
deba@1115
|
62 |
cout << mmap[newedge] << ' ' << id[graph.source(newedge)] <<
|
deba@1115
|
63 |
' ' << id[graph.target(newedge)] << endl;
|
deba@1037
|
64 |
|
deba@1037
|
65 |
ofstream output("copy.lgf");
|
deba@1037
|
66 |
GraphWriter<SmartGraph> writer(output, graph);
|
deba@1037
|
67 |
|
deba@1115
|
68 |
DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeMap<int> >
|
deba@1115
|
69 |
node_ids(graph);
|
deba@1037
|
70 |
|
deba@1115
|
71 |
writer.addNodeMap("id", node_ids);
|
deba@1115
|
72 |
writer.addNodeMap<QuotedStringWriter>("format", description);
|
deba@1037
|
73 |
|
deba@1115
|
74 |
IdMap<SmartGraph, SmartGraph::Edge > edge_ids(graph);
|
deba@1037
|
75 |
|
deba@1115
|
76 |
writer.addEdgeMap("id", edge_ids);
|
deba@1115
|
77 |
writer.addEdgeMap("chars", mmap);
|
deba@1037
|
78 |
|
deba@1115
|
79 |
writer.addNode("source", node_ids.inverse()[3]);
|
deba@1115
|
80 |
// writer.addEdge("elek", edge_ids.inverse()[6]);
|
deba@1037
|
81 |
writer.write();
|
deba@1037
|
82 |
|
deba@1032
|
83 |
return 0;
|
deba@1032
|
84 |
}
|