reader_writer_demo.cc File Reference


Detailed Description

This simple demo program gives an example of how to read and write a graph and additional maps (on the nodes or the edges) from/to a stream.

/* -*- C++ -*-
 *
 * This file is a part of LEMON, a generic C++ optimization library
 *
 * Copyright (C) 2003-2008
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
 *
 * Permission to use, modify and distribute this software is granted
 * provided that this copyright notice appears in all copies. For
 * precise terms see the accompanying LICENSE file.
 *
 * This software is provided "AS IS" with no warranty of any kind,
 * express or implied, and with no claim as to its suitability for any
 * purpose.
 *
 */


#include <iostream>
#include <lemon/smart_graph.h>
#include <lemon/graph_reader.h>
#include <lemon/graph_writer.h>


using namespace lemon;

int main() {
  SmartGraph graph;

  try {
    std::string filename="sample.lgf";
    std::string name;
    GraphReader<SmartGraph> reader(filename,graph);
    SmartGraph::EdgeMap<int> cap(graph);
    reader.readEdgeMap("capacity",cap);
    reader.readAttribute("name",name);
    reader.run();

    std::cout << "Hello! We have read a graph from file " << filename<< 
      " and some maps on it:\n now we write it to the standard output!" << 
      std::endl;


    GraphWriter<SmartGraph> writer(std::cout, graph);
    writer.writeEdgeMap("multiplicity", cap);
    writer.writeAttribute("name",name);
    writer.run();
     
  } catch (DataFormatError& error) {
    std::cerr << error.what() << std::endl;
  }


  return 0;
}
#include <iostream>
#include <lemon/smart_graph.h>
#include <lemon/graph_reader.h>
#include <lemon/graph_writer.h>

Generated on Thu Jun 4 04:03:10 2009 for LEMON by  doxygen 1.5.9