demo/lgf_demo.cc
author Balazs Dezso <deba@inf.elte.hu>
Tue, 01 Jul 2008 21:21:49 +0200
changeset 185 33e45a9b868c
parent 143 c3b45bb643b0
child 191 abc5b9d0c67e
child 192 7bf5f97d574f
permissions -rw-r--r--
Fix skip*() functions is GraphWriters (Ticket #107)
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
}