alpar@399: /* -*- mode: C++; indent-tabs-mode: nil; -*- alpar@399: * alpar@399: * This file is a part of LEMON, a generic C++ optimization library. alpar@399: * alpar@399: * Copyright (C) 2003-2008 alpar@399: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@399: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@399: * alpar@399: * Permission to use, modify and distribute this software is granted alpar@399: * provided that this copyright notice appears in all copies. For alpar@399: * precise terms see the accompanying LICENSE file. alpar@399: * alpar@399: * This software is provided "AS IS" with no warranty of any kind, alpar@399: * express or implied, and with no claim as to its suitability for any alpar@399: * purpose. alpar@399: * alpar@399: */ alpar@399: alpar@399: ///\ingroup demos alpar@399: ///\file alpar@399: ///\brief Demonstrating the usage of LEMON's General Flow algorithm alpar@399: /// alpar@399: /// This demo program reads a general network circulation problem from the alpar@399: /// file 'circulation-input.lgf', runs the preflow based algorithm for alpar@399: /// finding a feasible solution and writes the output alpar@399: /// to 'circulation-input.lgf' alpar@399: /// alpar@399: /// \include circulation_demo.cc alpar@399: alpar@399: #include alpar@399: alpar@399: #include alpar@399: #include alpar@399: #include alpar@399: #include alpar@399: alpar@399: using namespace lemon; alpar@399: alpar@399: alpar@399: int main (int, char*[]) alpar@399: { alpar@399: alpar@399: typedef ListDigraph Digraph; alpar@399: typedef Digraph::Node Node; alpar@399: typedef Digraph::NodeIt NodeIt; alpar@399: typedef Digraph::Arc Arc; alpar@399: typedef Digraph::ArcIt ArcIt; alpar@399: typedef Digraph::ArcMap ArcMap; alpar@399: typedef Digraph::NodeMap NodeMap; alpar@399: typedef Digraph::NodeMap DNodeMap; alpar@399: alpar@399: Digraph g; alpar@399: ArcMap lo(g); alpar@399: ArcMap up(g); alpar@399: NodeMap delta(g); alpar@399: NodeMap nid(g); alpar@399: ArcMap eid(g); alpar@399: DNodeMap cx(g); alpar@399: DNodeMap cy(g); alpar@399: alpar@399: DigraphReader(g,"circulation-input.lgf"). alpar@399: arcMap("lo_cap", lo). alpar@399: arcMap("up_cap", up). alpar@399: nodeMap("delta", delta). alpar@399: arcMap("label", eid). alpar@399: nodeMap("label", nid). alpar@399: nodeMap("coordinates_x", cx). alpar@399: nodeMap("coordinates_y", cy). alpar@399: run(); alpar@399: alpar@399: Circulation gen(g,lo,up,delta); alpar@399: bool ret=gen.run(); alpar@399: if(ret) alpar@399: { alpar@399: std::cout << "\nA feasible flow has been found.\n"; alpar@399: if(!gen.checkFlow()) std::cerr << "Oops!!!\n"; alpar@399: DigraphWriter(g, "circulation-output.lgf"). alpar@399: arcMap("lo_cap", lo). alpar@399: arcMap("up_cap", up). alpar@399: arcMap("flow", gen.flowMap()). alpar@399: nodeMap("delta", delta). alpar@399: arcMap("label", eid). alpar@399: nodeMap("label", nid). alpar@399: nodeMap("coordinates_x", cx). alpar@399: nodeMap("coordinates_y", cy). alpar@399: run(); alpar@399: } alpar@399: else { alpar@399: std::cout << "\nThere is no such a flow\n"; alpar@399: Digraph::NodeMap bar(g); alpar@399: gen.barrierMap(bar); alpar@399: if(!gen.checkBarrier()) std::cerr << "Dual Oops!!!\n"; alpar@399: alpar@399: DigraphWriter(g, "circulation-output.lgf"). alpar@399: arcMap("lo_cap", lo). alpar@399: arcMap("up_cap", up). alpar@399: nodeMap("barrier", bar). alpar@399: nodeMap("delta", delta). alpar@399: arcMap("label", eid). alpar@399: nodeMap("label", nid). alpar@399: nodeMap("coordinates_x", cx). alpar@399: nodeMap("coordinates_y", cy). alpar@399: run(); alpar@399: } alpar@399: std::cout << "The output is written to file 'circulation-output.lgf'\n\n"; alpar@399: alpar@399: }