This is not ready yet, but I have to go home...
1 #include <lemon/smart_graph.h>
6 #include "graph_reader.h"
7 #include "graph_writer.h"
13 using namespace lemon;
16 ifstream input("test.lgf");
18 GraphReader<SmartGraph> reader(input, graph);
20 SmartGraph::NodeMap<int> id(graph);
21 reader.addNodeMap("id", id);
23 SmartGraph::NodeMap<int> cost(graph);
24 reader.addNodeMap("cost", cost);
26 SmartGraph::NodeMap<string> color(graph);
27 reader.addNodeMap("color", color);
29 SmartGraph::NodeMap<string> description(graph);
30 reader.addNodeMap<QuotedStringReader>("description", description);
32 SmartGraph::EdgeMap<char> mmap(graph);
33 reader.addEdgeMap("mmap", mmap);
35 reader.skipEdgeMap<QuotedStringReader>("description");
37 SmartGraph::Node source;
38 reader.addNode("source", source);
40 SmartGraph::Edge newedge;
41 reader.addEdge("newedge", newedge);
45 } catch (IOException& e) {
46 cerr << e.what() << endl;
47 } catch (Exception e) {
48 cerr << e.what() << endl;
51 for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
52 cout << cost[it] << ' ' << color[it] << ' ' << description[it] << endl;
55 for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
56 cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' <<
57 id[graph.target(it)] << endl;
60 cout << id[source] << ' ' << cost[source] << ' ' <<
61 color[source] << ' ' << description[source] << endl;
62 cout << mmap[newedge] << ' ' << id[graph.source(newedge)] <<
63 ' ' << id[graph.target(newedge)] << endl;
65 ofstream output("copy.lgf");
66 GraphWriter<SmartGraph> writer(output, graph);
68 DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeMap<int> >
71 writer.addNodeMap("id", node_ids);
72 writer.addNodeMap<QuotedStringWriter>("format", description);
74 IdMap<SmartGraph, SmartGraph::Edge > edge_ids(graph);
76 writer.addEdgeMap("id", edge_ids);
77 writer.addEdgeMap("chars", mmap);
79 writer.addNode("source", node_ids.inverse()[3]);
80 // writer.addEdge("elek", edge_ids.inverse()[6]);