alpar@209: /* -*- mode: C++; indent-tabs-mode: nil; -*- deba@127: * alpar@209: * This file is a part of LEMON, a generic C++ optimization library. deba@127: * deba@127: * Copyright (C) 2003-2008 deba@127: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport deba@127: * (Egervary Research Group on Combinatorial Optimization, EGRES). deba@127: * deba@127: * Permission to use, modify and distribute this software is granted deba@127: * provided that this copyright notice appears in all copies. For deba@127: * precise terms see the accompanying LICENSE file. deba@127: * deba@127: * This software is provided "AS IS" with no warranty of any kind, deba@127: * express or implied, and with no claim as to its suitability for any deba@127: * purpose. deba@127: * deba@127: */ deba@127: deba@127: ///\ingroup demos deba@127: ///\file deba@127: ///\brief Demonstrating graph input and output deba@127: /// kpeter@191: /// This program gives an example of how to read and write a digraph alpar@209: /// and additional maps from/to a stream or a file using the kpeter@191: /// \ref lgf-format "LGF" format. deba@127: /// deba@164: /// The \c "digraph.lgf" file: deba@164: /// \include digraph.lgf deba@164: /// kpeter@191: /// And the program which reads it and prints the digraph to the kpeter@191: /// standard output: deba@164: /// \include lgf_demo.cc deba@127: deba@127: #include deba@127: #include deba@127: #include deba@127: #include deba@127: deba@127: using namespace lemon; deba@127: deba@164: int main() { deba@164: SmartDigraph g; deba@164: SmartDigraph::ArcMap cap(g); deba@164: SmartDigraph::Node s, t; alpar@209: kpeter@191: try { kpeter@191: digraphReader("digraph.lgf", g). // read the directed graph into g kpeter@191: arcMap("capacity", cap). // read the 'capacity' arc map into cap kpeter@191: node("source", s). // read 'source' node to s kpeter@191: node("target", t). // read 'target' node to t kpeter@191: run(); deba@290: } catch (Exception& error) { // check if there was any error kpeter@191: std::cerr << "Error: " << error.what() << std::endl; kpeter@191: return -1; kpeter@191: } deba@127: kpeter@191: std::cout << "A digraph is read from 'digraph.lgf'." << std::endl; deba@164: std::cout << "Number of nodes: " << countNodes(g) << std::endl; deba@164: std::cout << "Number of arcs: " << countArcs(g) << std::endl; deba@127: deba@164: std::cout << "We can write it to the standard output:" << std::endl; deba@127: deba@164: digraphWriter(std::cout, g). // write g to the standard output deba@164: arcMap("capacity", cap). // write cap into 'capacity' deba@164: node("source", s). // write s to 'source' deba@164: node("target", t). // write t to 'target' deba@164: run(); deba@127: deba@127: return 0; deba@127: }