lemon/lp_skeleton.h
changeset 502 8668e1b5dafb
parent 458 7afc121e0689
child 514 f5bc148f7e1f
equal deleted inserted replaced
0:e5e0d0916404 1:da79975c6d0e
    24 ///\file
    24 ///\file
    25 ///\brief A skeleton file to implement LP solver interfaces
    25 ///\brief A skeleton file to implement LP solver interfaces
    26 namespace lemon {
    26 namespace lemon {
    27 
    27 
    28   ///A skeleton class to implement LP solver interfaces
    28   ///A skeleton class to implement LP solver interfaces
    29   class LpSkeleton :public LpSolverBase {
    29   class SkeletonSolverBase : public virtual LpBase {
    30     int col_num,row_num;
    30     int col_num,row_num;
    31 
    31 
    32   protected:
    32   protected:
    33 
    33 
    34     ///\e
    34     SkeletonSolverBase()
    35     virtual LpSolverBase* _newLp();
    35       : col_num(-1), row_num(-1) {}
    36     ///\e
    36 
    37     virtual LpSolverBase* _copyLp();
       
    38     /// \e
    37     /// \e
    39     virtual int _addCol();
    38     virtual int _addCol();
    40     /// \e
    39     /// \e
    41     virtual int _addRow();
    40     virtual int _addRow();
    42     /// \e
    41     /// \e
    43     virtual void _eraseCol(int i);
    42     virtual void _eraseCol(int i);
    44     /// \e
    43     /// \e
    45     virtual void _eraseRow(int i);
    44     virtual void _eraseRow(int i);
    46     /// \e
    45 
    47     virtual void _getColName(int col, std::string & name) const;
    46     /// \e
    48     /// \e
    47     virtual void _getColName(int col, std::string& name) const;
    49     virtual void _setColName(int col, const std::string & name);
    48     /// \e
       
    49     virtual void _setColName(int col, const std::string& name);
    50     /// \e
    50     /// \e
    51     virtual int _colByName(const std::string& name) const;
    51     virtual int _colByName(const std::string& name) const;
    52 
    52 
    53     /// \e
    53     /// \e
    54     virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e);
    54     virtual void _getRowName(int row, std::string& name) const;
    55     /// \e
    55     /// \e
    56     virtual void _getRowCoeffs(int i, RowIterator b) const;
    56     virtual void _setRowName(int row, const std::string& name);
    57     /// \e
    57     /// \e
    58     virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e);
    58     virtual int _rowByName(const std::string& name) const;
    59     /// \e
    59 
    60     virtual void _getColCoeffs(int i, ColIterator b) const;
    60     /// \e
       
    61     virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
       
    62     /// \e
       
    63     virtual void _getRowCoeffs(int i, InsertIterator b) const;
       
    64     /// \e
       
    65     virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
       
    66     /// \e
       
    67     virtual void _getColCoeffs(int i, InsertIterator b) const;
    61 
    68 
    62     /// Set one element of the coefficient matrix
    69     /// Set one element of the coefficient matrix
    63     virtual void _setCoeff(int row, int col, Value value);
    70     virtual void _setCoeff(int row, int col, Value value);
    64 
    71 
    65     /// Get one element of the coefficient matrix
    72     /// Get one element of the coefficient matrix
    85     /// The upper bound of a variable (column) is an
    92     /// The upper bound of a variable (column) is an
    86     /// extended number of type Value, i.e. a finite number of type
    93     /// extended number of type Value, i.e. a finite number of type
    87     /// Value or \ref INF.
    94     /// Value or \ref INF.
    88     virtual Value _getColUpperBound(int i) const;
    95     virtual Value _getColUpperBound(int i) const;
    89 
    96 
    90 //     /// The lower bound of a linear expression (row) have to be given by an
    97     /// The lower bound of a constraint (row) have to be given by an
    91 //     /// extended number of type Value, i.e. a finite number of type
    98     /// extended number of type Value, i.e. a finite number of type
    92 //     /// Value or -\ref INF.
    99     /// Value or -\ref INF.
    93 //     virtual void _setRowLowerBound(int i, Value value);
   100     virtual void _setRowLowerBound(int i, Value value);
    94 //     /// \e
   101     /// \e
    95 
   102 
    96 //     /// The upper bound of a linear expression (row) have to be given by an
   103     /// The lower bound of a constraint (row) is an
    97 //     /// extended number of type Value, i.e. a finite number of type
   104     /// extended number of type Value, i.e. a finite number of type
    98 //     /// Value or \ref INF.
   105     /// Value or -\ref INF.
    99 //     virtual void _setRowUpperBound(int i, Value value);
   106     virtual Value _getRowLowerBound(int i) const;
   100 
   107 
   101     /// The lower and upper bound of a linear expression (row) have to be
   108     /// The upper bound of a constraint (row) have to be given by an
   102     /// given by an
   109     /// extended number of type Value, i.e. a finite number of type
   103     /// extended number of type Value, i.e. a finite number of type
   110     /// Value or \ref INF.
   104     /// Value or +/-\ref INF.
   111     virtual void _setRowUpperBound(int i, Value value);
   105     virtual void _setRowBounds(int i, Value lb, Value ub);
   112     /// \e
   106     /// \e
   113 
   107 
   114     /// The upper bound of a constraint (row) is an
   108 
   115     /// extended number of type Value, i.e. a finite number of type
   109     /// The lower and the upper bound of
   116     /// Value or \ref INF.
   110     /// a constraint (row) are
   117     virtual Value _getRowUpperBound(int i) const;
   111     /// extended numbers of type Value, i.e.  finite numbers of type
   118 
   112     /// Value, -\ref INF or \ref INF.
   119     /// \e
   113     virtual void _getRowBounds(int i, Value &lb, Value &ub) const;
   120     virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
   114     /// \e
   121     /// \e
   115 
   122     virtual void _getObjCoeffs(InsertIterator b) const;
   116 
   123 
   117     /// \e
       
   118     virtual void _clearObj();
       
   119     /// \e
   124     /// \e
   120     virtual void _setObjCoeff(int i, Value obj_coef);
   125     virtual void _setObjCoeff(int i, Value obj_coef);
   121 
       
   122     /// \e
   126     /// \e
   123     virtual Value _getObjCoeff(int i) const;
   127     virtual Value _getObjCoeff(int i) const;
   124 
   128 
   125     ///\e
   129     ///\e
   126 
   130     virtual void _setSense(Sense);
   127     ///\bug Wrong interface
   131     ///\e
   128     ///
   132     virtual Sense _getSense() const;
       
   133 
       
   134     ///\e
       
   135     virtual void _clear();
       
   136 
       
   137   };
       
   138 
       
   139   /// \brief Interface for a skeleton LP solver
       
   140   ///
       
   141   /// This class implements an interface for a skeleton LP solver.
       
   142   ///\ingroup lp_group
       
   143   class LpSkeleton : public SkeletonSolverBase, public LpSolver {
       
   144   public:
       
   145     LpSkeleton() : SkeletonSolverBase(), LpSolver() {}
       
   146 
       
   147   protected:
       
   148 
       
   149     ///\e
   129     virtual SolveExitStatus _solve();
   150     virtual SolveExitStatus _solve();
   130 
   151 
   131     ///\e
   152     ///\e
   132 
       
   133     ///\bug Wrong interface
       
   134     ///
       
   135     virtual Value _getPrimal(int i) const;
   153     virtual Value _getPrimal(int i) const;
   136 
   154     ///\e
   137     ///\e
       
   138 
       
   139     ///\bug Wrong interface
       
   140     ///
       
   141     virtual Value _getDual(int i) const;
   155     virtual Value _getDual(int i) const;
   142 
   156 
   143     ///\e
   157     ///\e
   144 
       
   145     ///\bug Wrong interface
       
   146     ///
       
   147     virtual Value _getPrimalValue() const;
   158     virtual Value _getPrimalValue() const;
   148 
   159 
   149     ///\e
   160     ///\e
   150 
   161     virtual Value _getPrimalRay(int i) const;
   151     ///\bug Wrong interface
   162     ///\e
   152     ///
   163     virtual Value _getDualRay(int i) const;
   153     virtual SolutionStatus _getPrimalStatus() const;
   164 
   154 
   165     ///\e
   155     ////e
   166     virtual ProblemType _getPrimalType() const;
   156     virtual SolutionStatus _getDualStatus() const;
   167     ///\e
   157 
   168     virtual ProblemType _getDualType() const;
   158 
   169 
   159     ///\e
   170     ///\e
   160     virtual ProblemTypes _getProblemType() const;
   171     virtual VarStatus _getColStatus(int i) const;
   161 
   172     ///\e
   162     ///\e
   173     virtual VarStatus _getRowStatus(int i) const;
   163     virtual void _setMax();
   174 
   164     ///\e
   175     ///\e
   165     virtual void _setMin();
   176     virtual LpSkeleton* _newSolver() const;
   166 
   177     ///\e
   167     ///\e
   178     virtual LpSkeleton* _cloneSolver() const;
   168     virtual bool _isMax() const;
   179     ///\e
   169 
   180     virtual const char* _solverName() const;
   170 
   181 
   171 
   182   };
   172     ///\e
   183 
   173     virtual bool _isBasicCol(int i) const;
   184   /// \brief Interface for a skeleton MIP solver
   174 
   185   ///
   175 
   186   /// This class implements an interface for a skeleton MIP solver.
   176 
   187   ///\ingroup lp_group
       
   188   class MipSkeleton : public SkeletonSolverBase, public MipSolver {
   177   public:
   189   public:
   178     LpSkeleton() : LpSolverBase(), col_num(0), row_num(0) {}
   190     MipSkeleton() : SkeletonSolverBase(), MipSolver() {}
       
   191 
       
   192   protected:
       
   193     ///\e
       
   194 
       
   195     ///\bug Wrong interface
       
   196     ///
       
   197     virtual SolveExitStatus _solve();
       
   198 
       
   199     ///\e
       
   200 
       
   201     ///\bug Wrong interface
       
   202     ///
       
   203     virtual Value _getSol(int i) const;
       
   204 
       
   205     ///\e
       
   206 
       
   207     ///\bug Wrong interface
       
   208     ///
       
   209     virtual Value _getSolValue() const;
       
   210 
       
   211     ///\e
       
   212 
       
   213     ///\bug Wrong interface
       
   214     ///
       
   215     virtual ProblemType _getType() const;
       
   216 
       
   217     ///\e
       
   218     virtual MipSkeleton* _newSolver() const;
       
   219 
       
   220     ///\e
       
   221     virtual MipSkeleton* _cloneSolver() const;
       
   222     ///\e
       
   223     virtual const char* _solverName() const;
       
   224 
   179   };
   225   };
   180 
   226 
   181 } //namespace lemon
   227 } //namespace lemon
   182 
   228 
   183 #endif // LEMON_LP_SKELETON
   229 #endif // LEMON_LP_SKELETON