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