* This file is a part of LEMON, a generic C++ optimization library
* Copyright (C) 2003-2008
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
///\brief Demonstrating graph input and output
/// This simple demo program gives an example of how to read and write
/// a graph and additional maps (on the nodes or the edges) from/to a
/// \include reader_writer_demo.cc
#include <lemon/smart_graph.h>
#include <lemon/lgf_reader.h>
#include <lemon/lgf_writer.h>
#include <lemon/random.h>
int main(int argc, const char *argv[]) {
const int n = argc > 1 ? std::atoi(argv[1]) : 20;
const int e = argc > 2 ? std::atoi(argv[2]) : static_cast<int>(n * log(n));
const int m = argc > 3 ? std::atoi(argv[3]) : 100;
typedef SmartDigraph Digraph;
typedef Digraph::Node Node;
typedef Digraph::Arc Arc;
typedef Digraph::ArcIt ArcIt;
typedef Digraph::NodeMap<int> PotentialMap;
typedef Digraph::ArcMap<int> CapacityMap;
typedef Digraph::ArcMap<std::string> NameMap;
PotentialMap potential(digraph);
CapacityMap capacity(digraph);
for (int i = 0; i < n; ++i) {
Node node = digraph.addNode();
potential[node] = rnd[m];
for (int i = 0; i < e; ++i) {
Arc arc = digraph.addArc(nodes[s], nodes[t]);
os << "arc \t" << i << std::endl;
DigraphWriter<Digraph>(ss, digraph).
nodeMap("potential", potential).
arcMap("capacity", capacity).
node("source", nodes[0]).
node("target", nodes[1]).
arc("bottleneck", arcs[e / 2]).
attribute("creator", "lemon library").
} catch (DataFormatError& error) {
std::cerr << error.what() << std::endl;
typedef SmartDigraph Digraph;
typedef Digraph::Node Node;
typedef Digraph::Arc Arc;
typedef Digraph::ArcIt ArcIt;
typedef Digraph::NodeMap<int> LabelMap;
typedef Digraph::NodeMap<int> PotentialMap;
typedef Digraph::ArcMap<int> CapacityMap;
typedef Digraph::ArcMap<std::string> NameMap;
PotentialMap potential(digraph);
CapacityMap capacity(digraph);
for (int i = 0; i < n; ++i) {
Node node = digraph.addNode();
DigraphReader<Digraph>(ss, digraph).
nodeMap("potential", potential).
arcMap("capacity", capacity).
attribute("creator", creator).
DigraphWriter<Digraph>(std::cout, digraph).
nodeMap("potential", potential).
arcMap("capacity", capacity).
attribute("creator", creator).
} catch (DataFormatError& error) {
std::cerr << error.what() << std::endl;