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