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@1036
|
21 |
reader.readNodeMap("id", id);
|
deba@1037
|
22 |
|
deba@1032
|
23 |
SmartGraph::NodeMap<int> cost(graph);
|
deba@1032
|
24 |
reader.readNodeMap("cost", cost);
|
deba@1037
|
25 |
|
deba@1032
|
26 |
SmartGraph::NodeMap<string> color(graph);
|
deba@1032
|
27 |
reader.readNodeMap("color", color);
|
deba@1037
|
28 |
|
deba@1036
|
29 |
SmartGraph::NodeMap<string> description(graph);
|
deba@1036
|
30 |
reader.readNodeMap<QuotedStringReader>("description", description);
|
deba@1037
|
31 |
|
deba@1036
|
32 |
SmartGraph::EdgeMap<char> mmap(graph);
|
deba@1036
|
33 |
reader.readEdgeMap("mmap", mmap);
|
deba@1037
|
34 |
|
deba@1036
|
35 |
reader.skipEdgeMap<QuotedStringReader>("description");
|
deba@1037
|
36 |
|
deba@1037
|
37 |
SmartGraph::Node source;
|
deba@1037
|
38 |
reader.readNode("source", source);
|
deba@1037
|
39 |
|
deba@1037
|
40 |
SmartGraph::Edge newedge;
|
deba@1037
|
41 |
reader.readEdge("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@1032
|
50 |
for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
|
deba@1036
|
51 |
cout << cost[it] << ' ' << color[it] << ' ' << description[it] << endl;
|
deba@1036
|
52 |
}
|
deba@1036
|
53 |
|
deba@1036
|
54 |
for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
|
deba@1036
|
55 |
cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' << id[graph.target(it)] << endl;
|
deba@1032
|
56 |
}
|
deba@1037
|
57 |
|
deba@1037
|
58 |
cout << id[source] << ' ' << cost[source] << ' ' << color[source] << ' ' << description[source] << endl;
|
deba@1037
|
59 |
cout << mmap[newedge] << ' ' << id[graph.source(newedge)] << ' ' << id[graph.target(newedge)] << endl;
|
deba@1037
|
60 |
|
deba@1037
|
61 |
ofstream output("copy.lgf");
|
deba@1037
|
62 |
GraphWriter<SmartGraph> writer(output, graph);
|
deba@1037
|
63 |
|
deba@1037
|
64 |
DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeIt, SmartGraph::NodeMap<int> > node_ids(graph);
|
deba@1037
|
65 |
|
deba@1037
|
66 |
writer.writeNodeMap("id", node_ids);
|
deba@1037
|
67 |
writer.writeNodeMap<QuotedStringWriter>("format", description);
|
deba@1037
|
68 |
|
deba@1037
|
69 |
DescriptorMap<SmartGraph, SmartGraph::Edge, SmartGraph::EdgeIt, SmartGraph::EdgeMap<int> > edge_ids(graph);
|
deba@1037
|
70 |
|
deba@1037
|
71 |
writer.writeEdgeMap("id", edge_ids);
|
deba@1037
|
72 |
writer.writeEdgeMap("chars", mmap);
|
deba@1037
|
73 |
|
deba@1037
|
74 |
writer.writeNode("source", node_ids.inverse()[3]);
|
deba@1037
|
75 |
writer.writeEdge("elek", edge_ids.inverse()[6]);
|
deba@1037
|
76 |
writer.write();
|
deba@1037
|
77 |
|
deba@1032
|
78 |
return 0;
|
deba@1032
|
79 |
}
|