One important thing only: equality-type constraint can now be added to an lp. The prettyPrint functions are not too pretty yet, I accept.
authorathos
Fri, 12 Jan 2007 16:29:06 +0000
changeset 2345bfcaad2b84e8
parent 2344 48ecc4feb42b
child 2346 c06a956a92fa
One important thing only: equality-type constraint can now be added to an lp. The prettyPrint functions are not too pretty yet, I accept.
lemon/lp_base.h
lemon/lp_glpk.cc
test/lp_test.cc
     1.1 --- a/lemon/lp_base.h	Thu Jan 11 22:08:18 2007 +0000
     1.2 +++ b/lemon/lp_base.h	Fri Jan 12 16:29:06 2007 +0000
     1.3 @@ -19,6 +19,9 @@
     1.4  #ifndef LEMON_LP_BASE_H
     1.5  #define LEMON_LP_BASE_H
     1.6  
     1.7 +#include<iostream>
     1.8 +
     1.9 +
    1.10  #include<vector>
    1.11  #include<map>
    1.12  #include<limits>
    1.13 @@ -269,7 +272,7 @@
    1.14      
    1.15      ///Linear expression of variables and a constant component
    1.16      
    1.17 -    ///This data structure strores a linear expression of the variables
    1.18 +    ///This data structure stores a linear expression of the variables
    1.19      ///(\ref Col "Col"s) and also has a constant component.
    1.20      ///
    1.21      ///There are several ways to access and modify the contents of this
    1.22 @@ -327,7 +330,7 @@
    1.23        typedef std::map<Col,Value> Base;
    1.24        
    1.25        Value const_comp;
    1.26 -  public:
    1.27 +    public:
    1.28        typedef True IsLinExpression;
    1.29        ///\e
    1.30        Expr() : Base(), const_comp(0) { }
    1.31 @@ -404,6 +407,26 @@
    1.32  	const_comp/=c;
    1.33  	return *this;
    1.34        }
    1.35 +
    1.36 +      //std::ostream &
    1.37 +      void prettyPrint(std::ostream &os) {
    1.38 +	//std::fmtflags os.flags();
    1.39 +	//os.setf(std::ios::showpos);
    1.40 +	Base::iterator j=Base::begin();
    1.41 +	if (j!=Base::end())
    1.42 +	  os<<j->second<<"*x["<<id(j->first)<<"]";
    1.43 +	++j;
    1.44 +	for (; j!=Base::end(); ++j){
    1.45 +	  if (j->second>=0)
    1.46 +	    os<<"+";
    1.47 +	  os<<j->second<<"*x["<<id(j->first)<<"]";
    1.48 +	}
    1.49 +	//Nem valami korrekt, de nem talaltam meg, hogy kell
    1.50 +	//os.unsetf(std::ios::showpos);
    1.51 +
    1.52 +	//return os;
    1.53 +      }
    1.54 +
    1.55      };
    1.56      
    1.57      ///Linear constraint
    1.58 @@ -496,6 +519,20 @@
    1.59  	using namespace std;
    1.60  	return finite(_ub);
    1.61        }
    1.62 +
    1.63 +      void prettyPrint(std::ostream &os) {
    1.64 +	if (_lb==-LpSolverBase::INF||isNaN(_lb))
    1.65 +	  os<<"-infty<=";
    1.66 +	else
    1.67 +	  os<<_lb<<"<=";
    1.68 +	_expr.prettyPrint(os);
    1.69 +	if (_ub==LpSolverBase::INF)
    1.70 +	  os<<"<=infty";
    1.71 +	else
    1.72 +	  os<<"<="<<_ub;
    1.73 +	//return os;
    1.74 +      }
    1.75 +
    1.76      };
    1.77      
    1.78      ///Linear expression of rows
    1.79 @@ -1490,6 +1527,16 @@
    1.80    }
    1.81  
    1.82    ///\e
    1.83 +
    1.84 +  ///\relates LpSolverBase::Constr
    1.85 +  ///
    1.86 +  inline LpSolverBase::Constr operator==(const LpSolverBase::Expr &e,
    1.87 +					 const LpSolverBase::Value &f) 
    1.88 +  {
    1.89 +    return LpSolverBase::Constr(f,e,f);
    1.90 +  }
    1.91 +
    1.92 +  ///\e
    1.93    
    1.94    ///\relates LpSolverBase::Constr
    1.95    ///
     2.1 --- a/lemon/lp_glpk.cc	Thu Jan 11 22:08:18 2007 +0000
     2.2 +++ b/lemon/lp_glpk.cc	Fri Jan 12 16:29:06 2007 +0000
     2.3 @@ -526,6 +526,9 @@
     2.4  
     2.5    LpGlpk::SolveExitStatus LpGlpk::_solve()
     2.6    {
     2.7 +    // A way to check the problem to be solved
     2.8 +    //lpx_write_cpxlp(lp,"naittvan.cpx");    
     2.9 +
    2.10      int i =  lpx_simplex(lp);
    2.11      switch (i) {
    2.12      case LPX_E_OK: 
     3.1 --- a/test/lp_test.cc	Thu Jan 11 22:08:18 2007 +0000
     3.2 +++ b/test/lp_test.cc	Fri Jan 12 16:29:06 2007 +0000
     3.3 @@ -194,11 +194,13 @@
     3.4      buf << "Coeff. of p2 should be 0";
     3.5      //    std::cout<<e[p1]<<e[p2]<<e[p3]<<std::endl;
     3.6      check(e.find(p2)==e.end(), buf.str());
     3.7 -
     3.8 +    
     3.9       
    3.10  
    3.11  
    3.12      e=((p1+p2)+(p1-0.99*p2));
    3.13 +    //e.prettyPrint(std::cout);
    3.14 +    //(e<=2).prettyPrint(std::cout);
    3.15      double tolerance=0.001;
    3.16      e.simplify(tolerance);
    3.17      buf << "Coeff. of p2 should be 0.01";