[Lemon-commits] athos: r3137 - in hugo/trunk: lemon test

Lemon SVN svn at lemon.cs.elte.hu
Fri Jan 12 17:29:07 CET 2007


Author: athos
Date: Fri Jan 12 17:29:06 2007
New Revision: 3137

Modified:
   hugo/trunk/lemon/lp_base.h
   hugo/trunk/lemon/lp_glpk.cc
   hugo/trunk/test/lp_test.cc

Log:
One important thing only: equality-type constraint can now be added to an lp. The prettyPrint functions are not too pretty yet, I accept.

Modified: hugo/trunk/lemon/lp_base.h
==============================================================================
--- hugo/trunk/lemon/lp_base.h	(original)
+++ hugo/trunk/lemon/lp_base.h	Fri Jan 12 17:29:06 2007
@@ -19,6 +19,9 @@
 #ifndef LEMON_LP_BASE_H
 #define LEMON_LP_BASE_H
 
+#include<iostream>
+
+
 #include<vector>
 #include<map>
 #include<limits>
@@ -269,7 +272,7 @@
     
     ///Linear expression of variables and a constant component
     
-    ///This data structure strores a linear expression of the variables
+    ///This data structure stores a linear expression of the variables
     ///(\ref Col "Col"s) and also has a constant component.
     ///
     ///There are several ways to access and modify the contents of this
@@ -327,7 +330,7 @@
       typedef std::map<Col,Value> Base;
       
       Value const_comp;
-  public:
+    public:
       typedef True IsLinExpression;
       ///\e
       Expr() : Base(), const_comp(0) { }
@@ -404,6 +407,26 @@
 	const_comp/=c;
 	return *this;
       }
+
+      //std::ostream &
+      void prettyPrint(std::ostream &os) {
+	//std::fmtflags os.flags();
+	//os.setf(std::ios::showpos);
+	Base::iterator j=Base::begin();
+	if (j!=Base::end())
+	  os<<j->second<<"*x["<<id(j->first)<<"]";
+	++j;
+	for (; j!=Base::end(); ++j){
+	  if (j->second>=0)
+	    os<<"+";
+	  os<<j->second<<"*x["<<id(j->first)<<"]";
+	}
+	//Nem valami korrekt, de nem talaltam meg, hogy kell
+	//os.unsetf(std::ios::showpos);
+
+	//return os;
+      }
+
     };
     
     ///Linear constraint
@@ -496,6 +519,20 @@
 	using namespace std;
 	return finite(_ub);
       }
+
+      void prettyPrint(std::ostream &os) {
+	if (_lb==-LpSolverBase::INF||isNaN(_lb))
+	  os<<"-infty<=";
+	else
+	  os<<_lb<<"<=";
+	_expr.prettyPrint(os);
+	if (_ub==LpSolverBase::INF)
+	  os<<"<=infty";
+	else
+	  os<<"<="<<_ub;
+	//return os;
+      }
+
     };
     
     ///Linear expression of rows
@@ -1490,6 +1527,16 @@
   }
 
   ///\e
+
+  ///\relates LpSolverBase::Constr
+  ///
+  inline LpSolverBase::Constr operator==(const LpSolverBase::Expr &e,
+					 const LpSolverBase::Value &f) 
+  {
+    return LpSolverBase::Constr(f,e,f);
+  }
+
+  ///\e
   
   ///\relates LpSolverBase::Constr
   ///

Modified: hugo/trunk/lemon/lp_glpk.cc
==============================================================================
--- hugo/trunk/lemon/lp_glpk.cc	(original)
+++ hugo/trunk/lemon/lp_glpk.cc	Fri Jan 12 17:29:06 2007
@@ -526,6 +526,9 @@
 
   LpGlpk::SolveExitStatus LpGlpk::_solve()
   {
+    // A way to check the problem to be solved
+    //lpx_write_cpxlp(lp,"naittvan.cpx");    
+
     int i =  lpx_simplex(lp);
     switch (i) {
     case LPX_E_OK: 

Modified: hugo/trunk/test/lp_test.cc
==============================================================================
--- hugo/trunk/test/lp_test.cc	(original)
+++ hugo/trunk/test/lp_test.cc	Fri Jan 12 17:29:06 2007
@@ -194,11 +194,13 @@
     buf << "Coeff. of p2 should be 0";
     //    std::cout<<e[p1]<<e[p2]<<e[p3]<<std::endl;
     check(e.find(p2)==e.end(), buf.str());
-
+    
      
 
 
     e=((p1+p2)+(p1-0.99*p2));
+    //e.prettyPrint(std::cout);
+    //(e<=2).prettyPrint(std::cout);
     double tolerance=0.001;
     e.simplify(tolerance);
     buf << "Coeff. of p2 should be 0.01";



More information about the Lemon-commits mailing list