COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/reader_writer_demo.cc @ 1861:5f204c7a1318

Last change on this file since 1861:5f204c7a1318 was 1641:77f6ab7ad66f, checked in by Alpar Juttner, 19 years ago

Demos' documentations include the source.

File size: 1.6 KB
RevLine 
[1583]1/* -*- C++ -*-
[1636]2 * demo/reader_writer_demo.cc - Part of LEMON, a generic C++ optimization
3 * library
[1583]4 *
5 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
6 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 *
8 * Permission to use, modify and distribute this software is granted
9 * provided that this copyright notice appears in all copies. For
10 * precise terms see the accompanying LICENSE file.
11 *
12 * This software is provided "AS IS" with no warranty of any kind,
13 * express or implied, and with no claim as to its suitability for any
14 * purpose.
15 *
16 */
17
18///\ingroup demos
19///\file
20///\brief Demonstrating graph input and output
21///
22/// This simple demo program gives an example of how to read and write
23/// a graph and additional maps (on the nodes or the edges) from/to a
24/// stream.
[1641]25///
26/// \include reader_writer_demo.cc
[1583]27
[1528]28#include <iostream>
29#include <lemon/smart_graph.h>
30#include <lemon/graph_reader.h>
31#include <lemon/graph_writer.h>
32
33
34using namespace lemon;
35
36int main() {
37  SmartGraph graph;
38
39  try {
40    std::string filename="sample.lgf";
41    GraphReader<SmartGraph> reader(filename,graph);
42    SmartGraph::EdgeMap<int> cap(graph);
43    reader.readEdgeMap("capacity",cap);
44    reader.run();
45
46    std::cout << "Hello! We have read a graph from file " << filename<<
[1583]47      " and some maps on it:\n now we write it to the standard output!" <<
[1528]48      std::endl;
49
50
51    GraphWriter<SmartGraph> writer(std::cout, graph);
52    writer.writeEdgeMap("multiplicity", cap);
53    writer.run();
54     
55  } catch (DataFormatError& error) {
56    std::cerr << error.what() << std::endl;
57  }
58
59
60  return 0;
61}
Note: See TracBrowser for help on using the repository browser.