COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/deba/graph_io_test.cc @ 1174:5dccf1916ed8

Last change on this file since 1174:5dccf1916ed8 was 1115:444f69240539, checked in by Balazs Dezso, 20 years ago

Some changes in the IO and map utilities.

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