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