lemon/lp_base.h
changeset 2605 852361980706
parent 2569 12c2c5c4330b
child 2609 c36f00f19f2b
equal deleted inserted replaced
60:62131f55fe10 61:455c5fcf02ae
   369 	  j->second/=c;
   369 	  j->second/=c;
   370 	const_comp/=c;
   370 	const_comp/=c;
   371 	return *this;
   371 	return *this;
   372       }
   372       }
   373 
   373 
   374       //std::ostream &
       
   375       void prettyPrint(std::ostream &os) {
       
   376 	//std::fmtflags os.flags();
       
   377 	//os.setf(std::ios::showpos);
       
   378 	Base::iterator j=Base::begin();
       
   379 	if (j!=Base::end())
       
   380 	  os<<j->second<<"*x["<<id(j->first)<<"]";
       
   381 	++j;
       
   382 	for (; j!=Base::end(); ++j){
       
   383 	  if (j->second>=0)
       
   384 	    os<<"+";
       
   385 	  os<<j->second<<"*x["<<id(j->first)<<"]";
       
   386 	}
       
   387 	//Nem valami korrekt, de nem talaltam meg, hogy kell
       
   388 	//os.unsetf(std::ios::showpos);
       
   389 
       
   390 	//return os;
       
   391       }
       
   392 
       
   393     };
   374     };
   394     
   375     
   395     ///Linear constraint
   376     ///Linear constraint
   396 
   377 
   397     ///This data stucture represents a linear constraint in the LP.
   378     ///This data stucture represents a linear constraint in the LP.
   479       ///Is the constraint upper bounded?
   460       ///Is the constraint upper bounded?
   480       bool upperBounded() const {
   461       bool upperBounded() const {
   481 	return isFinite(_ub);
   462 	return isFinite(_ub);
   482       }
   463       }
   483 
   464 
   484       void prettyPrint(std::ostream &os) {
       
   485 	if (_lb==-LpSolverBase::INF||isNaN(_lb))
       
   486 	  os<<"-infty<=";
       
   487 	else
       
   488 	  os<<_lb<<"<=";
       
   489 	_expr.prettyPrint(os);
       
   490 	if (_ub==LpSolverBase::INF)
       
   491 	  os<<"<=infty";
       
   492 	else
       
   493 	  os<<"<="<<_ub;
       
   494 	//return os;
       
   495       }
       
   496 
       
   497     };
   465     };
   498     
   466     
   499     ///Linear expression of rows
   467     ///Linear expression of rows
   500     
   468     
   501     ///This data structure represents a column of the matrix,
   469     ///This data structure represents a column of the matrix,
   733     typedef MappedOutputIterator<Expr> RowIterator;
   701     typedef MappedOutputIterator<Expr> RowIterator;
   734     /// STL compatible iterator for lp row
   702     /// STL compatible iterator for lp row
   735     typedef MappedOutputIterator<DualExpr> ColIterator;
   703     typedef MappedOutputIterator<DualExpr> ColIterator;
   736 
   704 
   737     //Abstract virtual functions
   705     //Abstract virtual functions
   738     virtual LpSolverBase &_newLp() = 0;
   706     virtual LpSolverBase* _newLp() = 0;
   739     virtual LpSolverBase &_copyLp(){
   707     virtual LpSolverBase* _copyLp(){
   740       ///\todo This should be implemented here, too, when we have
   708       LpSolverBase* newlp = _newLp();
   741       ///problem retrieving routines. It can be overriden.
   709 
   742 
   710       std::map<Col, Col> ref;
   743       //Starting:
   711       for (LpSolverBase::ColIt it(*this); it != INVALID; ++it) {
   744       LpSolverBase & newlp(_newLp());
   712 	Col ccol = newlp->addCol();
       
   713 	ref[it] = ccol;
       
   714 	newlp->colName(ccol, colName(it));
       
   715 	newlp->colLowerBound(ccol, colLowerBound(it));
       
   716 	newlp->colUpperBound(ccol, colUpperBound(it));
       
   717       }
       
   718 
       
   719       for (LpSolverBase::RowIt it(*this); it != INVALID; ++it) {
       
   720 	Expr e = row(it), ce;
       
   721 	for (Expr::iterator jt = e.begin(); jt != e.end(); ++jt) {
       
   722 	  ce[ref[jt->first]] = jt->second;
       
   723 	}
       
   724 	ce += e.constComp();
       
   725 	Row r = newlp->addRow(ce);
       
   726 
       
   727         double lower, upper;
       
   728         getRowBounds(it, lower, upper);
       
   729 	newlp->rowBounds(r, lower, upper);
       
   730       }
       
   731 
   745       return newlp;
   732       return newlp;
   746       //return *(LpSolverBase*)0;
       
   747     };
   733     };
   748 
   734 
   749     virtual int _addCol() = 0;
   735     virtual int _addCol() = 0;
   750     virtual int _addRow() = 0; 
   736     virtual int _addRow() = 0; 
   751 
   737 
   802 
   788 
   803     ///\e
   789     ///\e
   804     virtual ~LpSolverBase() {}
   790     virtual ~LpSolverBase() {}
   805 
   791 
   806     ///Creates a new LP problem
   792     ///Creates a new LP problem
   807     LpSolverBase &newLp() {return _newLp();}
   793     LpSolverBase* newLp() {return _newLp();}
   808     ///Makes a copy of the LP problem
   794     ///Makes a copy of the LP problem
   809     LpSolverBase &copyLp() {return _copyLp();}
   795     LpSolverBase* copyLp() {return _copyLp();}
   810     
   796     
   811     ///\name Build up and modify the LP
   797     ///\name Build up and modify the LP
   812 
   798 
   813     ///@{
   799     ///@{
   814 
   800