COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/reader_writer_demo.cc @ 1528:1aa71600000c

Last change on this file since 1528:1aa71600000c was 1528:1aa71600000c, checked in by athos, 19 years ago

Graph input-output demo, some documentation.

File size: 2.4 KB
Line 
1#include <iostream>
2#include <lemon/smart_graph.h>
3#include <lemon/invalid.h>
4#include <lemon/graph_reader.h>
5#include <lemon/graph_writer.h>
6
7
8using namespace lemon;
9
10int main() {
11  SmartGraph graph;
12
13  try {
14    std::string filename="sample.lgf";
15    GraphReader<SmartGraph> reader(filename,graph);
16    SmartGraph::EdgeMap<int> cap(graph);
17    reader.readEdgeMap("capacity",cap);
18//     reader.readNode("source",s).readNode("target",t)
19//       .readEdgeMap("capacity",cap).run();
20    reader.run();
21
22    std::cout << "Hello! We have read a graph from file " << filename<<
23      " and some maps on it: now we write this to the standard output!" <<
24      std::endl;
25
26
27    GraphWriter<SmartGraph> writer(std::cout, graph);
28    writer.writeEdgeMap("multiplicity", cap);
29//     writer.writeNode("source", s);
30//     writer.writeNode("target", t);
31    writer.run();
32     
33//     LemonReader reader(std::cin);
34
35//     NodeSetReader<SmartGraph> nodeset(reader, graph);
36//     SmartGraph::NodeMap<int> cost(graph);
37//     nodeset.readMap("cost", cost);
38//     SmartGraph::NodeMap<char> mmap(graph);
39//     nodeset.readMap("mmap", mmap);
40
41//     EdgeSetReader<SmartGraph> edgeset(reader, graph, nodeset);
42//     SmartGraph::EdgeMap<std::string> description(graph);
43//     edgeset.readMap<QuotedStringReader>("description", description);
44
45//     NodeReader<SmartGraph> nodes(reader, nodeset);
46//     SmartGraph::Node source;
47//     nodes.readNode("source", source);
48//     SmartGraph::Node target;
49//     nodes.readNode("target", target);
50
51//     AttributeReader<> attribute(reader, "gui");
52//     std::string author;
53//     attribute.readAttribute<LineReader>("author", author);
54//     int count;
55//     attribute.readAttribute("count", count);
56
57//     PrintReader print(reader);
58
59//     reader.run();
60
61
62//     for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
63//       std::cout << cost[it] << ' ' << mmap[it] << std::endl;
64//     }
65
66//     for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
67//       std::cout << description[it] << std::endl;
68//     }
69
70//     std::cout << "author: " << author << std::endl;
71//     std::cout << "count: " << count << std::endl;
72
73//     std::cout << "source cost: " << cost[source] << std::endl;
74//     std::cout << "target cost: " << cost[target] << std::endl;
75
76//     std::cout.flush();
77  } catch (DataFormatError& error) {
78    std::cerr << error.what() << std::endl;
79  }
80
81
82  return 0;
83}
Note: See TracBrowser for help on using the repository browser.