lemon/lp_base.h
changeset 2346 c06a956a92fa
parent 2328 b4931ae52069
child 2363 2aabce558574
equal deleted inserted replaced
41:10f4d133b5f5 42:7fca608a5841
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 #ifndef LEMON_LP_BASE_H
    19 #ifndef LEMON_LP_BASE_H
    20 #define LEMON_LP_BASE_H
    20 #define LEMON_LP_BASE_H
       
    21 
       
    22 #include<iostream>
       
    23 
    21 
    24 
    22 #include<vector>
    25 #include<vector>
    23 #include<map>
    26 #include<map>
    24 #include<limits>
    27 #include<limits>
    25 #include<cmath>
    28 #include<cmath>
   267 
   270 
   268   public:
   271   public:
   269     
   272     
   270     ///Linear expression of variables and a constant component
   273     ///Linear expression of variables and a constant component
   271     
   274     
   272     ///This data structure strores a linear expression of the variables
   275     ///This data structure stores a linear expression of the variables
   273     ///(\ref Col "Col"s) and also has a constant component.
   276     ///(\ref Col "Col"s) and also has a constant component.
   274     ///
   277     ///
   275     ///There are several ways to access and modify the contents of this
   278     ///There are several ways to access and modify the contents of this
   276     ///container.
   279     ///container.
   277     ///- Its it fully compatible with \c std::map<Col,double>, so for expamle
   280     ///- Its it fully compatible with \c std::map<Col,double>, so for expamle
   325       
   328       
   326     protected:
   329     protected:
   327       typedef std::map<Col,Value> Base;
   330       typedef std::map<Col,Value> Base;
   328       
   331       
   329       Value const_comp;
   332       Value const_comp;
   330   public:
   333     public:
   331       typedef True IsLinExpression;
   334       typedef True IsLinExpression;
   332       ///\e
   335       ///\e
   333       Expr() : Base(), const_comp(0) { }
   336       Expr() : Base(), const_comp(0) { }
   334       ///\e
   337       ///\e
   335       Expr(const Key &v) : const_comp(0) {
   338       Expr(const Key &v) : const_comp(0) {
   402 	for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
   405 	for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
   403 	  j->second/=c;
   406 	  j->second/=c;
   404 	const_comp/=c;
   407 	const_comp/=c;
   405 	return *this;
   408 	return *this;
   406       }
   409       }
       
   410 
       
   411       //std::ostream &
       
   412       void prettyPrint(std::ostream &os) {
       
   413 	//std::fmtflags os.flags();
       
   414 	//os.setf(std::ios::showpos);
       
   415 	Base::iterator j=Base::begin();
       
   416 	if (j!=Base::end())
       
   417 	  os<<j->second<<"*x["<<id(j->first)<<"]";
       
   418 	++j;
       
   419 	for (; j!=Base::end(); ++j){
       
   420 	  if (j->second>=0)
       
   421 	    os<<"+";
       
   422 	  os<<j->second<<"*x["<<id(j->first)<<"]";
       
   423 	}
       
   424 	//Nem valami korrekt, de nem talaltam meg, hogy kell
       
   425 	//os.unsetf(std::ios::showpos);
       
   426 
       
   427 	//return os;
       
   428       }
       
   429 
   407     };
   430     };
   408     
   431     
   409     ///Linear constraint
   432     ///Linear constraint
   410 
   433 
   411     ///This data stucture represents a linear constraint in the LP.
   434     ///This data stucture represents a linear constraint in the LP.
   494       ///Is the constraint upper bounded?
   517       ///Is the constraint upper bounded?
   495       bool upperBounded() const {
   518       bool upperBounded() const {
   496 	using namespace std;
   519 	using namespace std;
   497 	return finite(_ub);
   520 	return finite(_ub);
   498       }
   521       }
       
   522 
       
   523       void prettyPrint(std::ostream &os) {
       
   524 	if (_lb==-LpSolverBase::INF||isNaN(_lb))
       
   525 	  os<<"-infty<=";
       
   526 	else
       
   527 	  os<<_lb<<"<=";
       
   528 	_expr.prettyPrint(os);
       
   529 	if (_ub==LpSolverBase::INF)
       
   530 	  os<<"<=infty";
       
   531 	else
       
   532 	  os<<"<="<<_ub;
       
   533 	//return os;
       
   534       }
       
   535 
   499     };
   536     };
   500     
   537     
   501     ///Linear expression of rows
   538     ///Linear expression of rows
   502     
   539     
   503     ///This data structure represents a column of the matrix,
   540     ///This data structure represents a column of the matrix,
  1488   {
  1525   {
  1489     return LpSolverBase::Constr(f,e);
  1526     return LpSolverBase::Constr(f,e);
  1490   }
  1527   }
  1491 
  1528 
  1492   ///\e
  1529   ///\e
       
  1530 
       
  1531   ///\relates LpSolverBase::Constr
       
  1532   ///
       
  1533   inline LpSolverBase::Constr operator==(const LpSolverBase::Expr &e,
       
  1534 					 const LpSolverBase::Value &f) 
       
  1535   {
       
  1536     return LpSolverBase::Constr(f,e,f);
       
  1537   }
       
  1538 
       
  1539   ///\e
  1493   
  1540   
  1494   ///\relates LpSolverBase::Constr
  1541   ///\relates LpSolverBase::Constr
  1495   ///
  1542   ///
  1496   inline LpSolverBase::Constr operator==(const LpSolverBase::Expr &e,
  1543   inline LpSolverBase::Constr operator==(const LpSolverBase::Expr &e,
  1497 					 const LpSolverBase::Expr &f) 
  1544 					 const LpSolverBase::Expr &f)