[414] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
| 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 the usage of LEMON's General Flow algorithm |
---|
| 22 | /// |
---|
| 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' |
---|
| 27 | /// |
---|
| 28 | /// \include circulation_demo.cc |
---|
| 29 | |
---|
| 30 | #include <iostream> |
---|
| 31 | |
---|
| 32 | #include <lemon/list_graph.h> |
---|
| 33 | #include <lemon/circulation.h> |
---|
| 34 | #include <lemon/lgf_reader.h> |
---|
| 35 | #include <lemon/lgf_writer.h> |
---|
| 36 | |
---|
| 37 | using namespace lemon; |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | int main (int, char*[]) |
---|
| 41 | { |
---|
| 42 | |
---|
| 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; |
---|
| 51 | |
---|
| 52 | Digraph g; |
---|
| 53 | ArcMap lo(g); |
---|
| 54 | ArcMap up(g); |
---|
| 55 | NodeMap delta(g); |
---|
| 56 | NodeMap nid(g); |
---|
| 57 | ArcMap eid(g); |
---|
| 58 | DNodeMap cx(g); |
---|
| 59 | DNodeMap cy(g); |
---|
| 60 | |
---|
| 61 | DigraphReader<Digraph>(g,"circulation-input.lgf"). |
---|
| 62 | arcMap("lo_cap", lo). |
---|
| 63 | arcMap("up_cap", up). |
---|
| 64 | nodeMap("delta", delta). |
---|
| 65 | arcMap("label", eid). |
---|
| 66 | nodeMap("label", nid). |
---|
| 67 | nodeMap("coordinates_x", cx). |
---|
| 68 | nodeMap("coordinates_y", cy). |
---|
| 69 | run(); |
---|
| 70 | |
---|
| 71 | Circulation<Digraph> gen(g,lo,up,delta); |
---|
| 72 | bool ret=gen.run(); |
---|
| 73 | if(ret) |
---|
| 74 | { |
---|
| 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"). |
---|
| 78 | arcMap("lo_cap", lo). |
---|
| 79 | arcMap("up_cap", up). |
---|
| 80 | arcMap("flow", gen.flowMap()). |
---|
| 81 | nodeMap("delta", delta). |
---|
| 82 | arcMap("label", eid). |
---|
| 83 | nodeMap("label", nid). |
---|
| 84 | nodeMap("coordinates_x", cx). |
---|
| 85 | nodeMap("coordinates_y", cy). |
---|
| 86 | run(); |
---|
| 87 | } |
---|
| 88 | else { |
---|
| 89 | std::cout << "\nThere is no such a flow\n"; |
---|
| 90 | Digraph::NodeMap<int> bar(g); |
---|
| 91 | gen.barrierMap(bar); |
---|
| 92 | if(!gen.checkBarrier()) std::cerr << "Dual Oops!!!\n"; |
---|
| 93 | |
---|
| 94 | DigraphWriter<Digraph>(g, "circulation-output.lgf"). |
---|
| 95 | arcMap("lo_cap", lo). |
---|
| 96 | arcMap("up_cap", up). |
---|
| 97 | nodeMap("barrier", bar). |
---|
| 98 | nodeMap("delta", delta). |
---|
| 99 | arcMap("label", eid). |
---|
| 100 | nodeMap("label", nid). |
---|
| 101 | nodeMap("coordinates_x", cx). |
---|
| 102 | nodeMap("coordinates_y", cy). |
---|
| 103 | run(); |
---|
| 104 | } |
---|
| 105 | std::cout << "The output is written to file 'circulation-output.lgf'\n\n"; |
---|
| 106 | |
---|
| 107 | } |
---|