COIN-OR::LEMON - Graph Library

source: lemon-1.2/demo/lgf_demo.cc @ 220:a5d8c039f218

Last change on this file since 220:a5d8c039f218 was 209:765619b7cbb2, checked in by Alpar Juttner <alpar@…>, 16 years ago

Apply unify-sources.sh to the source tree

File size: 2.2 KB
RevLine 
[209]1/* -*- mode: C++; indent-tabs-mode: nil; -*-
[127]2 *
[209]3 * This file is a part of LEMON, a generic C++ optimization library.
[127]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///
[191]23/// This program gives an example of how to read and write a digraph
[209]24/// and additional maps from/to a stream or a file using the
[191]25/// \ref lgf-format "LGF" format.
[127]26///
[164]27/// The \c "digraph.lgf" file:
28/// \include digraph.lgf
29///
[191]30/// And the program which reads it and prints the digraph to the
31/// standard output:
[164]32/// \include lgf_demo.cc
[127]33
34#include <iostream>
35#include <lemon/smart_graph.h>
36#include <lemon/lgf_reader.h>
37#include <lemon/lgf_writer.h>
38
39using namespace lemon;
40
[164]41int main() {
42  SmartDigraph g;
43  SmartDigraph::ArcMap<int> cap(g);
44  SmartDigraph::Node s, t;
[209]45
[191]46  try {
47    digraphReader("digraph.lgf", g). // read the directed 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  } catch (DataFormatError& error) { // check if there was any error
53    std::cerr << "Error: " << error.what() << std::endl;
54    return -1;
55  }
[127]56
[191]57  std::cout << "A digraph is read from 'digraph.lgf'." << std::endl;
[164]58  std::cout << "Number of nodes: " << countNodes(g) << std::endl;
59  std::cout << "Number of arcs: " << countArcs(g) << std::endl;
[127]60
[164]61  std::cout << "We can write it to the standard output:" << std::endl;
[127]62
[164]63  digraphWriter(std::cout, g).     // write g to the standard output
64    arcMap("capacity", cap).       // write cap into 'capacity'
65    node("source", s).             // write s to 'source'
66    node("target", t).             // write t to 'target'
67    run();
[127]68
69  return 0;
70}
Note: See TracBrowser for help on using the repository browser.