This demo program shows how to solve the maximum flow problem using the LEMON LP solver interface. We would like to lay the emphasis on the simplicity of the way one can formulate LP constraints that arise in graph theory using LEMON.
using namespace lemon;
template <typename GR, typename CAP>
double maxFlow(const GR &g, const CAP &capacity,
typename GR::Node source, typename GR::Node target)
{
typename GR::template ArcMap<Lp::Col> f(g);
for (ArcIt a(g); a !=
INVALID; ++a) {
}
for (NodeIt n(g); n !=
INVALID; ++n) {
if (n == source || n == target) continue;
for (OutArcIt a(g, n); a !=
INVALID; ++a) e += f[a];
for (InArcIt a(g, n); a !=
INVALID; ++a) e -= f[a];
}
for (OutArcIt a(g, source); a !=
INVALID; ++a) o += f[a];
for (InArcIt a(g, source); a !=
INVALID; ++a) o -= f[a];
}
int main(int argc, char *argv[])
{
if (argc < 2) {
std::cerr <<
"The given input file has to contain a maximum flow\n"
<< "problem in LGF format (like 'maxflow.lgf')."
return 0;
}
SmartDigraph::ArcMap<double> cap(g);
SmartDigraph::Node s, t;
.arcMap("capacity", cap)
.node("source", s)
.node("target", t)
.run();
return 0;
}