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