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.
deba@127
     1
/* -*- C++ -*-
deba@127
     2
 *
deba@127
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@127
     4
 *
deba@127
     5
 * Copyright (C) 2003-2008
deba@127
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@127
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@127
     8
 *
deba@127
     9
 * Permission to use, modify and distribute this software is granted
deba@127
    10
 * provided that this copyright notice appears in all copies. For
deba@127
    11
 * precise terms see the accompanying LICENSE file.
deba@127
    12
 *
deba@127
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@127
    14
 * express or implied, and with no claim as to its suitability for any
deba@127
    15
 * purpose.
deba@127
    16
 *
deba@127
    17
 */
deba@127
    18
deba@127
    19
///\ingroup demos
deba@127
    20
///\file
deba@127
    21
///\brief Demonstrating graph input and output
deba@127
    22
///
deba@164
    23
/// This program gives an example of how to load a directed graph from
deba@164
    24
/// an \ref lgf-format "LGF" file with the \ref lemon::DigraphReader
deba@164
    25
/// "DigraphReader" class.
deba@127
    26
///
deba@164
    27
/// The \c "digraph.lgf" file:
deba@164
    28
/// \include digraph.lgf
deba@164
    29
///
deba@164
    30
/// And the program which reads it:
deba@164
    31
/// \include lgf_demo.cc
deba@127
    32
deba@127
    33
#include <iostream>
deba@127
    34
#include <lemon/smart_graph.h>
deba@127
    35
#include <lemon/lgf_reader.h>
deba@127
    36
#include <lemon/lgf_writer.h>
deba@127
    37
#include <lemon/random.h>
deba@127
    38
deba@127
    39
deba@127
    40
using namespace lemon;
deba@127
    41
deba@164
    42
int main() {
deba@164
    43
  SmartDigraph g;
deba@164
    44
  SmartDigraph::ArcMap<int> cap(g);
deba@164
    45
  SmartDigraph::Node s, t;
deba@127
    46
deba@164
    47
  digraphReader("digraph.lgf", g). // read the directeg graph into g
deba@164
    48
    arcMap("capacity", cap).       // read the 'capacity' arc map into cap
deba@164
    49
    node("source", s).             // read 'source' node to s
deba@164
    50
    node("target", t).             // read 'target' node to t
deba@164
    51
    run();
deba@127
    52
deba@164
    53
  std::cout << "Digraph read from 'digraph.lgf'" << std::endl;
deba@164
    54
  std::cout << "Number of nodes: " << countNodes(g) << std::endl;
deba@164
    55
  std::cout << "Number of arcs: " << countArcs(g) << std::endl;
deba@127
    56
deba@164
    57
  std::cout << "We can write it to the standard output:" << std::endl;
deba@127
    58
deba@164
    59
  digraphWriter(std::cout, g).     // write g to the standard output
deba@164
    60
    arcMap("capacity", cap).       // write cap into 'capacity'
deba@164
    61
    node("source", s).             // write s to 'source'
deba@164
    62
    node("target", t).             // write t to 'target'
deba@164
    63
    run();
deba@127
    64
deba@127
    65
  return 0;
deba@127
    66
}