sub_graph_adaptor_demo.cc File Reference
Detailed Description
This program computes a maximum number of edge-disjoint shortest paths between nodes
s and
t.
#include <iostream>
#include <fstream>
#include <lemon/smart_graph.h>
#include <lemon/dijkstra.h>
#include <lemon/maps.h>
#include <lemon/graph_adaptor.h>
#include <lemon/dimacs.h>
#include <lemon/preflow.h>
#include "tight_edge_filter_map.h"
#include <lemon/graph_reader.h>
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;
}
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<int> LengthMap;
Graph g;
Node s, t;
LengthMap length(g);
GraphReader<SmartGraph> 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<Graph, LengthMap> Dijkstra;
Dijkstra dijkstra(g, length);
dijkstra.run(s);
typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap>
TightEdgeFilter;
TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
typedef EdgeSubGraphAdaptor<Graph, TightEdgeFilter> SubGW;
SubGW gw(g, tight_edge_filter);
ConstMap<Edge, int> const_1_map(1);
Preflow<SubGW, ConstMap<Edge, int> > preflow(gw, const_1_map, s, t);
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 (preflow.flow(e) != 0)
cout << " " << g.id(e) << ", "
<< g.id(g.source(e)) << "--"
<< length[e] << "->" << g.id(g.target(e)) << endl;
}
#include <iostream>
#include <fstream>
#include <lemon/smart_graph.h>
#include <lemon/dijkstra.h>
#include <lemon/maps.h>
#include <lemon/graph_adaptor.h>
#include <lemon/dimacs.h>
#include <lemon/preflow.h>
#include "tight_edge_filter_map.h"
#include <lemon/graph_reader.h>