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