# HG changeset patch # User athos # Date 1121443315 0 # Node ID 01707a8a4ca6064e09e376e29b8270ed378ce9f4 # Parent 030f1015f898681a57f2252431fc931c1d672299 Some demo programs got some interface. Most progress with lp_maxflow_demo.cc, which also got documented. diff -r 030f1015f898 -r 01707a8a4ca6 demo/coloring.cc --- a/demo/coloring.cc Fri Jul 15 14:35:07 2005 +0000 +++ b/demo/coloring.cc Fri Jul 15 16:01:55 2005 +0000 @@ -5,10 +5,26 @@ #include #include +#include +#include + + using namespace std; using namespace lemon; -int main() { +int main(int argc, char *argv[]) +{ + if(argc<2) + { + std::cerr << "USAGE: coloring " << std::endl; + std::cerr << "The file 'input_file.lgf' has to contain a graph in LEMON format together with a nodemap called 'coords' to draw the graph (e.g. sample.lgf is not such a file)." << std::endl; + return 0; + } + + + //input stream to read the graph from + std::ifstream is(argv[1]); + typedef UndirSmartGraph Graph; typedef Graph::Node Node; typedef Graph::NodeIt NodeIt; @@ -17,7 +33,7 @@ Graph graph; - UndirGraphReader reader(std::cin, graph); + UndirGraphReader reader(is, graph); Graph::NodeMap > coords(graph); reader.readNodeMap("coords", coords); diff -r 030f1015f898 -r 01707a8a4ca6 demo/lp_maxflow_demo.cc --- a/demo/lp_maxflow_demo.cc Fri Jul 15 14:35:07 2005 +0000 +++ b/demo/lp_maxflow_demo.cc Fri Jul 15 16:01:55 2005 +0000 @@ -1,3 +1,28 @@ +/* -*- C++ -*- + * demo/lp_maxflow_demo.cc - Part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2005 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 Max flow problem solved with an LP solver (demo). +/// +///This demo program shows how to solve a maximum (or maximal) flow +///problem using the LEMON LP solver interface. We would like to lay +///the emphasis on the simplicity of the way one can formulate the LP +///constraints with LEMON that arise in graph theory. + #ifdef HAVE_CONFIG_H #include #endif @@ -5,6 +30,9 @@ #include #include +#include +#include + #ifdef HAVE_GLPK #include @@ -75,21 +103,30 @@ return lp.primalValue(); } -int main() +int main(int argc, char *argv[]) { + if(argc<2) + { + std::cerr << "USAGE: lp_maxflow_demo " << std::endl; + std::cerr << "The file 'input_file.lgf' has to contain a max flow instance in LEMON format (e.g. sample.lgf is such a file)." << std::endl; + return 0; + } + + + //input stream to read the graph from + std::ifstream is(argv[1]); + + ListGraph g; ListGraph::Node s; ListGraph::Node t; ListGraph::EdgeMap cap(g); - GraphReader reader(std::cin,g); + GraphReader reader(is,g); reader.readNode("source",s).readNode("target",t) .readEdgeMap("capacity",cap).run(); - // std::ifstream file("../test/preflow_"); -// readDimacs(file, g, cap, s, t); - std::cout << "Max flow value = " << maxFlow(g,cap,s,t) << std::endl; } diff -r 030f1015f898 -r 01707a8a4ca6 demo/sub_graph_adaptor_demo.cc --- a/demo/sub_graph_adaptor_demo.cc Fri Jul 15 14:35:07 2005 +0000 +++ b/demo/sub_graph_adaptor_demo.cc Fri Jul 15 16:01:55 2005 +0000 @@ -1,6 +1,6 @@ // -*- c++ -*- -// Use a DIMACS max flow file as stdin. +// Use a DIMACS max flow file as input. // sub_graph_adaptor_demo < dimacs_max_flow_file // This program computes a maximum number of edge-disjoint shortest paths // between s and t. @@ -21,8 +21,19 @@ using std::cout; using std::endl; -int main() -{ +int main(int argc, char *argv[]) +{ + if(argc<2) + { + std::cerr << "USAGE: sub_graph_adaptor_demo " << std::endl; + std::cerr << "The file 'input_file.dim' has to contain a max flow instance in DIMACS format (e.g. sub_graph_adaptor_demo.dim 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; @@ -35,7 +46,7 @@ Node s, t; LengthMap length(g); - readDimacs(std::cin, g, length, s, t); + readDimacs(is, g, length, s, t); cout << "edges with lengths (of form id, source--length->target): " << endl; for(EdgeIt e(g); e!=INVALID; ++e)