src/lemon/lp_base.h
changeset 1326 85f1c483279e
parent 1312 48f9299b390d
child 1328 a8dd11348853
equal deleted inserted replaced
1:c9e70c3cf6eb 2:e502f15e6b79
    99   
    99   
   100   };
   100   };
   101     
   101     
   102   ///Common base class for LP solvers
   102   ///Common base class for LP solvers
   103   class LpSolverBase {
   103   class LpSolverBase {
   104     
   104 
   105   public:
   105   public:
   106 
   106 
   107     ///\e
   107     ///\e
   108     enum SolveExitStatus {
   108     enum SolveExitStatus {
   109       ///\e
   109       ///\e
   373 
   373 
   374   protected:
   374   protected:
   375     _FixId rows;
   375     _FixId rows;
   376     _FixId cols;
   376     _FixId cols;
   377 
   377 
       
   378     //Abstract virtual functions
   378     virtual int _addCol() = 0;
   379     virtual int _addCol() = 0;
   379     virtual int _addRow() = 0;
   380     virtual int _addRow() = 0;
   380     virtual void _setRowCoeffs(int i, 
   381     virtual void _setRowCoeffs(int i, 
   381 			       int length,
   382 			       int length,
   382                                int  const * indices, 
   383                                int  const * indices, 
   395     virtual Value _getPrimalValue() = 0;
   396     virtual Value _getPrimalValue() = 0;
   396     virtual SolutionStatus _getPrimalStatus() = 0;
   397     virtual SolutionStatus _getPrimalStatus() = 0;
   397     virtual void _setMax() = 0;
   398     virtual void _setMax() = 0;
   398     virtual void _setMin() = 0;
   399     virtual void _setMin() = 0;
   399     
   400     
   400 
   401     //Own protected stuff
       
   402     
       
   403     //Constant component of the objective function
       
   404     Value obj_const_comp;
       
   405     
       
   406     ///\e
       
   407     
       
   408     ///\bug Unimplemented
   401     void clearObj() {}
   409     void clearObj() {}
       
   410     
   402   public:
   411   public:
   403 
   412 
       
   413     ///\e
       
   414     LpSolverBase() : obj_const_comp(0) {}
   404 
   415 
   405     ///\e
   416     ///\e
   406     virtual ~LpSolverBase() {}
   417     virtual ~LpSolverBase() {}
   407 
   418 
   408     ///\name Build up and modify of the LP
   419     ///\name Build up and modify of the LP
   600     ///Set an element of the objective function
   611     ///Set an element of the objective function
   601     void objCoeff(Col c, Value v) {_setObjCoeff(cols.floatingId(c.id),v); };
   612     void objCoeff(Col c, Value v) {_setObjCoeff(cols.floatingId(c.id),v); };
   602     ///Set the objective function
   613     ///Set the objective function
   603     
   614     
   604     ///\param e is a linear expression of type \ref Expr.
   615     ///\param e is a linear expression of type \ref Expr.
   605     ///\todo What to do with the constant component?
   616     ///\bug The previous objective function is not cleared!
   606     void setObj(Expr e) {
   617     void setObj(Expr e) {
   607       clearObj();
   618       clearObj();
   608       for (Expr::iterator i=e.begin(); i!=e.end(); ++i)
   619       for (Expr::iterator i=e.begin(); i!=e.end(); ++i)
   609 	objCoeff((*i).first,(*i).second);
   620 	objCoeff((*i).first,(*i).second);
       
   621       obj_const_comp=e.constComp();
   610     }
   622     }
   611 
   623 
   612     ///Maximize
   624     ///Maximize
   613     void max() { _setMax(); }
   625     void max() { _setMax(); }
   614     ///Minimize
   626     ///Minimize
   644     ///\return
   656     ///\return
   645     ///- \ref INF or -\ref INF means either infeasibility or unboundedness
   657     ///- \ref INF or -\ref INF means either infeasibility or unboundedness
   646     /// of the primal problem, depending on whether we minimize or maximize.
   658     /// of the primal problem, depending on whether we minimize or maximize.
   647     ///- \ref NAN if no primal solution is found.
   659     ///- \ref NAN if no primal solution is found.
   648     ///- The (finite) objective value if an optimal solution is found.
   660     ///- The (finite) objective value if an optimal solution is found.
   649     Value primalValue() { return _getPrimalValue();}
   661     Value primalValue() { return _getPrimalValue()+obj_const_comp;}
   650     ///@}
   662     ///@}
   651     
   663     
   652   };  
   664   };  
   653 
   665 
   654   ///\e
   666   ///\e