1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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.
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
21 ///\brief Demonstrating the usage of LEMON's General Flow algorithm
23 /// This demo program reads a general network circulation problem from the
24 /// file 'circulation-input.lgf', runs the preflow based algorithm for
25 /// finding a feasible solution and writes the output
26 /// to 'circulation-input.lgf'
28 /// \include circulation_demo.cc
32 #include <lemon/list_graph.h>
33 #include <lemon/circulation.h>
34 #include <lemon/lgf_reader.h>
35 #include <lemon/lgf_writer.h>
37 using namespace lemon;
40 int main (int, char*[])
43 typedef ListDigraph Digraph;
44 typedef Digraph::Node Node;
45 typedef Digraph::NodeIt NodeIt;
46 typedef Digraph::Arc Arc;
47 typedef Digraph::ArcIt ArcIt;
48 typedef Digraph::ArcMap<int> ArcMap;
49 typedef Digraph::NodeMap<int> NodeMap;
50 typedef Digraph::NodeMap<double> DNodeMap;
61 DigraphReader<Digraph>(g,"circulation-input.lgf").
64 nodeMap("delta", delta).
66 nodeMap("label", nid).
67 nodeMap("coordinates_x", cx).
68 nodeMap("coordinates_y", cy).
71 Circulation<Digraph> gen(g,lo,up,delta);
75 std::cout << "\nA feasible flow has been found.\n";
76 if(!gen.checkFlow()) std::cerr << "Oops!!!\n";
77 DigraphWriter<Digraph>(g, "circulation-output.lgf").
80 arcMap("flow", gen.flowMap()).
81 nodeMap("delta", delta).
83 nodeMap("label", nid).
84 nodeMap("coordinates_x", cx).
85 nodeMap("coordinates_y", cy).
89 std::cout << "\nThere is no such a flow\n";
90 Digraph::NodeMap<int> bar(g);
92 if(!gen.checkBarrier()) std::cerr << "Dual Oops!!!\n";
94 DigraphWriter<Digraph>(g, "circulation-output.lgf").
97 nodeMap("barrier", bar).
98 nodeMap("delta", delta).
100 nodeMap("label", nid).
101 nodeMap("coordinates_x", cx).
102 nodeMap("coordinates_y", cy).
105 std::cout << "The output is written to file 'circulation-output.lgf'\n\n";