/* -*- C++ -*- * * This file is a part of LEMON, a generic C++ optimization library * * Copyright (C) 2003-2006 * 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 Computing maximum number of edge-disjoint shortest paths /// /// This program computes a maximum number of edge-disjoint shortest paths /// between nodes \c s and \c t. /// /// \include sub_graph_adaptor_demo.cc // Use a DIMACS max flow file as input. // sub_graph_adaptor_demo < dimacs_max_flow_file // Modified to eat lemon graph format! #include #include #include #include #include #include #include #include #include #include using namespace lemon; using std::cout; using std::endl; int main(int argc, char *argv[]) { if(argc<2) { std::cerr << "USAGE: sub_graph_adaptor_demo input_file.lgf" << std::endl; std::cerr << "The file 'input_file.lgf' has to contain a max flow " << "instance in \n LEMON format " << "(e.g. sub_gad_input.lgf is such a file)." << std::endl; return 0; } //input stream to read the graph from std::ifstream is(argv[1]); typedef SmartGraph Graph; typedef Graph::Edge Edge; typedef Graph::Node Node; typedef Graph::EdgeIt EdgeIt; typedef Graph::NodeIt NodeIt; typedef Graph::EdgeMap LengthMap; Graph g; Node s, t; LengthMap length(g); //readDimacs(is, g, length, s, t); GraphReader reader(is,g); reader.readNode("source",s).readNode("target",t) .readEdgeMap("length",length).run(); cout << "edges with lengths (of form id, source--length->target): " << endl; for(EdgeIt e(g); e!=INVALID; ++e) cout << " " << g.id(e) << ", " << g.id(g.source(e)) << "--" << length[e] << "->" << g.id(g.target(e)) << endl; cout << "s: " << g.id(s) << " t: " << g.id(t) << endl; typedef Dijkstra Dijkstra; Dijkstra dijkstra(g, length); dijkstra.run(s); // This map returns true exactly for those edges which are // tight w.r.t the length funcion and the potential // given by the dijkstra algorithm. typedef TightEdgeFilterMap TightEdgeFilter; TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length); // ConstMap const_true_map(true); // This graph contains exaclty the tight edges. // typedef SubGraphAdaptor, TightEdgeFilter> SubGW; typedef EdgeSubGraphAdaptor SubGW; SubGW gw(g, tight_edge_filter); ConstMap const_1_map(1); Graph::EdgeMap flow(g, 0); // Max flow between s and t in the graph of tight edges. Preflow, Graph::EdgeMap > preflow(gw, s, t, const_1_map, flow); preflow.run(); cout << "maximum number of edge-disjoint shortest paths: " << preflow.flowValue() << endl; cout << "edges of the maximum number of edge-disjoint shortest s-t paths: " << endl; for(EdgeIt e(g); e!=INVALID; ++e) if (flow[e]) cout << " " << g.id(e) << ", " << g.id(g.source(e)) << "--" << length[e] << "->" << g.id(g.target(e)) << endl; }