[Lemon-commits] [lemon_svn] alpar: r2116 - in hugo/trunk: demo lemon

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


Author: alpar
Date: Mon Aug  1 23:16:08 2005
New Revision: 2116

Added:
   hugo/trunk/lemon/lp.h
Modified:
   hugo/trunk/demo/lp_demo.cc
   hugo/trunk/demo/lp_maxflow_demo.cc
   hugo/trunk/lemon/lp_base.h

Log:
A default LP solver is defined in lp.h

Modified: hugo/trunk/demo/lp_demo.cc
==============================================================================
--- hugo/trunk/demo/lp_demo.cc	(original)
+++ hugo/trunk/demo/lp_demo.cc	Mon Aug  1 23:16:08 2005
@@ -24,40 +24,21 @@
 /// example). For the detailed documentation of the LEMON LP solver
 /// interface read \ref lemon::LpSolverBase "this".
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include <lemon/lp.h>
 
 #include <iostream>
 
-
-#ifdef HAVE_GLPK
-#include <lemon/lp_glpk.h>
-#elif HAVE_CPLEX
-#include <lemon/lp_cplex.h>
-#endif
-
 using namespace lemon;
 
-
-
-#ifdef HAVE_GLPK
-typedef LpGlpk LpDefault;
-const char default_solver_name[]="GLPK";
-#elif HAVE_CPLEX
-typedef LpCplex LpDefault;
-const char default_solver_name[]="CPLEX";
-#endif
-
 int main()
 {     
  //The following example is taken from the documentation of the GLPK library.
  //See it in the GLPK reference manual and among the GLPK sample files (sample.c)
 
   //A default solver is taken
-  LpDefault lp;
-  typedef LpDefault::Row Row;
-  typedef LpDefault::Col Col;
+  Lp lp;
+  typedef Lp::Row Row;
+  typedef Lp::Col Col;
   
 
   std::cout<<"A program demonstrating the LEMON LP solver interface"<<std::endl; 

Modified: hugo/trunk/demo/lp_maxflow_demo.cc
==============================================================================
--- hugo/trunk/demo/lp_maxflow_demo.cc	(original)
+++ hugo/trunk/demo/lp_maxflow_demo.cc	Mon Aug  1 23:16:08 2005
@@ -23,38 +23,21 @@
 /// the emphasis on the simplicity of the way one can formulate LP
 /// constraints that arise in graph theory in our library LEMON .
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include<lemon/graph_reader.h>
 #include<lemon/list_graph.h>
+#include <lemon/lp.h>
 
 #include <fstream>
 #include <iostream>
 
 
-#ifdef HAVE_GLPK
-#include <lemon/lp_glpk.h>
-#elif HAVE_CPLEX
-#include <lemon/lp_cplex.h>
-#endif
 
 using namespace lemon;
 
-#ifdef HAVE_GLPK
-typedef LpGlpk LpDefault;
-const char default_solver_name[]="GLPK";
-#elif HAVE_CPLEX
-typedef LpCplex LpDefault;
-const char default_solver_name[]="CPLEX";
-#endif
-
-
 template<class G,class C>
 double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t)
 {
-  LpDefault lp;
+  Lp lp;
   
   typedef G Graph;
   typedef typename G::Node Node;
@@ -65,7 +48,7 @@
   typedef typename G::InEdgeIt InEdgeIt;
   
   //Define a map on the edges for the variables of the LP problem
-  typename G::template EdgeMap<LpDefault::Col> x(g);
+  typename G::template EdgeMap<Lp::Col> x(g);
   lp.addColSet(x);
   
   //Nonnegativity and capacity constraints
@@ -77,14 +60,14 @@
 
   //Flow conservation constraints for the nodes (except for 's' and 't')
   for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
-    LpDefault::Expr ex;
+    Lp::Expr ex;
     for(InEdgeIt  e(g,n);e!=INVALID;++e) ex+=x[e];
     for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
     lp.addRow(ex==0);
   }
   
   //Objective function: the flow value entering 't'
-  LpDefault::Expr obj;
+  Lp::Expr obj;
   for(InEdgeIt  e(g,t);e!=INVALID;++e) obj+=x[e];
   for(OutEdgeIt e(g,t);e!=INVALID;++e) obj-=x[e];
   lp.setObj(obj);
@@ -93,7 +76,7 @@
   //Maximization
   lp.max();
 
-#ifdef HAVE_GLPK
+#if DEFAULT_LP==GLPK
   lp.presolver(true);
   lp.messageLevel(3);
 #endif

Added: hugo/trunk/lemon/lp.h
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/lp.h	Mon Aug  1 23:16:08 2005
@@ -0,0 +1,71 @@
+/* -*- C++ -*-
+ * lemon/lp.h - 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.
+ *
+ */
+
+#ifndef LEMON_LP_H
+#define LEMON_LP_H
+
+#ifdef HAVE_CONFIG_H
+#include<lemon/config.h>
+#endif
+
+#ifdef HAVE_GLPK
+#include <lemon/lp_glpk.h>
+#elif HAVE_CPLEX
+#include <lemon/lp_cplex.h>
+#endif
+
+///\file
+///\brief Defines a default LP solver
+///\ingroup gen_opt_group
+namespace lemon {
+ 
+#ifdef DOXYGEN
+  ///The default LP solver identifier
+
+  ///The default LP solver identifier.
+  ///\ingroup gen_opt_group
+  ///
+  ///Currently, the possible values are \c GLPK or \c CPLEX
+#define DEFAULT_LP SOLVER
+  ///The default LP solver
+
+  ///The default LP solver.
+  ///\ingroup gen_opt_group
+  ///
+  ///Currently, it is either \c LpGlpk or \c LpCplex
+  typedef LpGlpk Lp;
+  ///The default LP solver identifier string
+
+  ///The default LP solver identifier string.
+  ///\ingroup gen_opt_group
+  ///
+  ///Currently, the possible values are "GLPK" or "CPLEX"
+  const char default_solver_name[]="SOLVER";  
+#else
+#ifdef HAVE_GLPK
+#define DEFAULT_LP GLPK
+  typedef LpGlpk Lp;
+  const char default_solver_name[]="GLPK";
+#elif HAVE_CPLEX
+#define DEFAULT_LP CPLEX
+  typedef LpCplex Lp;
+  const char default_solver_name[]="CPLEX";
+#endif
+#endif
+ 
+} //namespace lemon
+
+#endif //LEMON_LP_BASE_H

Modified: hugo/trunk/lemon/lp_base.h
==============================================================================
--- hugo/trunk/lemon/lp_base.h	(original)
+++ hugo/trunk/lemon/lp_base.h	Mon Aug  1 23:16:08 2005
@@ -26,8 +26,6 @@
 #include<lemon/error.h>
 #include<lemon/invalid.h>
 
-//#include"lin_expr.h"
-
 ///\file
 ///\brief The interface of the LP solver interface.
 ///\ingroup gen_opt_group



More information about the Lemon-commits mailing list