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