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