3  * This file is a part of LEMON, a generic C++ optimization library
 
     5  * Copyright (C) 2003-2007
 
     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/graph_reader.h>
 
    35 #include <lemon/graph_writer.h>
 
    37 using namespace lemon;
 
    40 int main (int, char*[])
 
    43     typedef ListGraph Graph;
 
    44     typedef Graph::Node Node;
 
    45     typedef Graph::NodeIt NodeIt;
 
    46     typedef Graph::Edge Edge;
 
    47     typedef Graph::EdgeIt EdgeIt;
 
    48     typedef Graph::EdgeMap<int> EdgeMap;
 
    49     typedef Graph::NodeMap<int> NodeMap;
 
    50     typedef Graph::NodeMap<double> DNodeMap;
 
    62     GraphReader<Graph>("circulation-input.lgf", g).
 
    63       readEdgeMap("lo_cap", lo).
 
    64       readEdgeMap("up_cap", up).
 
    65       readNodeMap("delta", delta).
 
    66       readEdgeMap("label", eid).
 
    67       readNodeMap("label", nid).
 
    68       readNodeMap("coordinates_x", cx).
 
    69       readNodeMap("coordinates_y", cy).
 
    72     Circulation<Graph,int> gen(g,lo,up,delta,x);
 
    76 	std::cout << "\nA feasible flow has been found.\n";
 
    77 	if(!gen.checkX(x)) std::cerr << "Oops!!!\n";
 
    78 	GraphWriter<Graph>("circulation-output.lgf", g).
 
    79 	  writeEdgeMap("lo_cap", lo).
 
    80 	  writeEdgeMap("up_cap", up).
 
    81 	  writeEdgeMap("flow", x).
 
    82 	  writeNodeMap("delta", delta).
 
    83 	  writeEdgeMap("label", eid).
 
    84 	  writeNodeMap("label", nid).
 
    85 	  writeNodeMap("coordinates_x", cx).
 
    86 	  writeNodeMap("coordinates_y", cy).
 
    90       std::cout << "\nThere is no such a flow\n";
 
    91       Graph::NodeMap<int> bar(g);
 
    93       if(!gen.checkBarrier(bar)) std::cerr << "Dual Oops!!!\n";
 
    95       GraphWriter<Graph>("circulation-output.lgf", g).
 
    96 	writeEdgeMap("lo_cap", lo).
 
    97 	writeEdgeMap("up_cap", up).
 
    98 	writeNodeMap("barrier", bar).
 
    99 	writeNodeMap("delta", delta).
 
   100 	writeEdgeMap("label", eid).
 
   101 	writeNodeMap("label", nid).
 
   102 	writeNodeMap("coordinates_x", cx).
 
   103 	writeNodeMap("coordinates_y", cy).
 
   106   std::cout << "The output is written to file 'circulation-output.lgf'\n\n";