demo/lgf_demo.cc
author Peter Kovacs <kpeter@inf.elte.hu>
Sun, 15 Jun 2008 22:05:23 +0200
changeset 171 02f4d5d9bfd7
parent 143 c3b45bb643b0
child 191 abc5b9d0c67e
child 192 7bf5f97d574f
permissions -rw-r--r--
Improve and redesign test programs + unify their output (ticket #25)
- Move graph related utilities form test_tools.h to graph_test.h.
- Move the contents of graph_utils_test.h to graph_utils_test.cc.
- Rename map_test.h -> graph_maps_test.h.
- Rename digraph_test.h -> graph_test.h.
- Many improvements in the following files:
* digraph_test.cc
* graph_test.cc
* graph_test.h
* graph_maps_test.h
* graph_utils_test.cc
* bfs_test.cc
* dfs_test.cc
* counter_test.cc
- Test programs print messages only if it really seems necessary.
- Remove \file commands form .cc test files.
     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 program gives an example of how to load a directed graph from
    24 /// an \ref lgf-format "LGF" file with the \ref lemon::DigraphReader
    25 /// "DigraphReader" class.
    26 ///
    27 /// The \c "digraph.lgf" file:
    28 /// \include digraph.lgf
    29 ///
    30 /// And the program which reads it:
    31 /// \include lgf_demo.cc
    32 
    33 #include <iostream>
    34 #include <lemon/smart_graph.h>
    35 #include <lemon/lgf_reader.h>
    36 #include <lemon/lgf_writer.h>
    37 #include <lemon/random.h>
    38 
    39 
    40 using namespace lemon;
    41 
    42 int main() {
    43   SmartDigraph g;
    44   SmartDigraph::ArcMap<int> cap(g);
    45   SmartDigraph::Node s, t;
    46 
    47   digraphReader("digraph.lgf", g). // read the directeg graph into g
    48     arcMap("capacity", cap).       // read the 'capacity' arc map into cap
    49     node("source", s).             // read 'source' node to s
    50     node("target", t).             // read 'target' node to t
    51     run();
    52 
    53   std::cout << "Digraph read from 'digraph.lgf'" << std::endl;
    54   std::cout << "Number of nodes: " << countNodes(g) << std::endl;
    55   std::cout << "Number of arcs: " << countArcs(g) << std::endl;
    56 
    57   std::cout << "We can write it to the standard output:" << std::endl;
    58 
    59   digraphWriter(std::cout, g).     // write g to the standard output
    60     arcMap("capacity", cap).       // write cap into 'capacity'
    61     node("source", s).             // write s to 'source'
    62     node("target", t).             // write t to 'target'
    63     run();
    64 
    65   return 0;
    66 }