[Lemon-commits] [lemon_svn] athos: r2058 - hugo/trunk/demo

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:49:49 CET 2006


Author: athos
Date: Fri Jul 15 18:01:55 2005
New Revision: 2058

Modified:
   hugo/trunk/demo/coloring.cc
   hugo/trunk/demo/lp_maxflow_demo.cc
   hugo/trunk/demo/sub_graph_adaptor_demo.cc

Log:
Some demo programs got some interface. Most progress with lp_maxflow_demo.cc, which also got documented.

Modified: hugo/trunk/demo/coloring.cc
==============================================================================
--- hugo/trunk/demo/coloring.cc	(original)
+++ hugo/trunk/demo/coloring.cc	Fri Jul 15 18:01:55 2005
@@ -5,10 +5,26 @@
 #include <lemon/graph_reader.h>
 #include <lemon/graph_to_eps.h>
 
+#include <fstream>
+#include <iostream>
+
+
 using namespace std;
 using namespace lemon;
 
-int main() {
+int main(int argc, char *argv[]) 
+{
+  if(argc<2)
+  {
+      std::cerr << "USAGE: coloring <input_file.lgf>" << 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<Graph> reader(std::cin, graph);
+  UndirGraphReader<Graph> reader(is, graph);
   Graph::NodeMap<xy<double> > coords(graph);
   reader.readNodeMap("coords", coords);
   

Modified: hugo/trunk/demo/lp_maxflow_demo.cc
==============================================================================
--- hugo/trunk/demo/lp_maxflow_demo.cc	(original)
+++ hugo/trunk/demo/lp_maxflow_demo.cc	Fri Jul 15 18:01:55 2005
@@ -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 <config.h>
 #endif
@@ -5,6 +30,9 @@
 #include<lemon/graph_reader.h>
 #include<lemon/list_graph.h>
 
+#include <fstream>
+#include <iostream>
+
 
 #ifdef HAVE_GLPK
 #include <lemon/lp_glpk.h>
@@ -75,21 +103,30 @@
   return lp.primalValue();
 }
 
-int main() 
+int main(int argc, char *argv[]) 
 {
+  if(argc<2)
+  {
+      std::cerr << "USAGE: lp_maxflow_demo <input_file.lgf>" << 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<double> cap(g);
   
-  GraphReader<ListGraph> reader(std::cin,g);
+  GraphReader<ListGraph> 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;
 
 }

Modified: hugo/trunk/demo/sub_graph_adaptor_demo.cc
==============================================================================
--- hugo/trunk/demo/sub_graph_adaptor_demo.cc	(original)
+++ hugo/trunk/demo/sub_graph_adaptor_demo.cc	Fri Jul 15 18:01:55 2005
@@ -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 <input_file.dim>" << 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) 



More information about the Lemon-commits mailing list