lemon/lp_skeleton.h
author Peter Kovacs <kpeter@inf.elte.hu>
Sun, 26 Apr 2009 16:44:53 +0200
changeset 625 029a48052c67
parent 541 89e29e22d479
child 746 e4554cd6b2bf
permissions -rw-r--r--
Modify the interface of MinCostArborescence + improvements (#267)

- Rename arborescenceValue() to arborescenceCost().
- Rename DefXyz template named paramaters to SetXyz.
- Rearrange public functions (for better doc).
- Doc improvements.
- Extend the test file with interface checking.
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     5  * Copyright (C) 2003-2008
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #ifndef LEMON_LP_SKELETON_H
    20 #define LEMON_LP_SKELETON_H
    21 
    22 #include <lemon/lp_base.h>
    23 
    24 ///\file
    25 ///\brief Skeleton file to implement LP/MIP solver interfaces
    26 ///  
    27 ///The classes in this file do nothing, but they can serve as skeletons when
    28 ///implementing an interface to new solvers.
    29 namespace lemon {
    30 
    31   ///A skeleton class to implement LP/MIP solver base interface
    32   
    33   ///This class does nothing, but it can serve as a skeleton when
    34   ///implementing an interface to new solvers.
    35   class SkeletonSolverBase : public virtual LpBase {
    36     int col_num,row_num;
    37 
    38   protected:
    39 
    40     SkeletonSolverBase()
    41       : col_num(-1), row_num(-1) {}
    42 
    43     /// \e
    44     virtual int _addCol();
    45     /// \e
    46     virtual int _addRow();
    47     /// \e
    48     virtual void _eraseCol(int i);
    49     /// \e
    50     virtual void _eraseRow(int i);
    51 
    52     /// \e
    53     virtual void _getColName(int col, std::string& name) const;
    54     /// \e
    55     virtual void _setColName(int col, const std::string& name);
    56     /// \e
    57     virtual int _colByName(const std::string& name) const;
    58 
    59     /// \e
    60     virtual void _getRowName(int row, std::string& name) const;
    61     /// \e
    62     virtual void _setRowName(int row, const std::string& name);
    63     /// \e
    64     virtual int _rowByName(const std::string& name) const;
    65 
    66     /// \e
    67     virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
    68     /// \e
    69     virtual void _getRowCoeffs(int i, InsertIterator b) const;
    70     /// \e
    71     virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
    72     /// \e
    73     virtual void _getColCoeffs(int i, InsertIterator b) const;
    74 
    75     /// Set one element of the coefficient matrix
    76     virtual void _setCoeff(int row, int col, Value value);
    77 
    78     /// Get one element of the coefficient matrix
    79     virtual Value _getCoeff(int row, int col) const;
    80 
    81     /// The lower bound of a variable (column) have to be given by an
    82     /// extended number of type Value, i.e. a finite number of type
    83     /// Value or -\ref INF.
    84     virtual void _setColLowerBound(int i, Value value);
    85     /// \e
    86 
    87     /// The lower bound of a variable (column) is an
    88     /// extended number of type Value, i.e. a finite number of type
    89     /// Value or -\ref INF.
    90     virtual Value _getColLowerBound(int i) const;
    91 
    92     /// The upper bound of a variable (column) have to be given by an
    93     /// extended number of type Value, i.e. a finite number of type
    94     /// Value or \ref INF.
    95     virtual void _setColUpperBound(int i, Value value);
    96     /// \e
    97 
    98     /// The upper bound of a variable (column) is an
    99     /// extended number of type Value, i.e. a finite number of type
   100     /// Value or \ref INF.
   101     virtual Value _getColUpperBound(int i) const;
   102 
   103     /// The lower bound of a constraint (row) have to be given by an
   104     /// extended number of type Value, i.e. a finite number of type
   105     /// Value or -\ref INF.
   106     virtual void _setRowLowerBound(int i, Value value);
   107     /// \e
   108 
   109     /// The lower bound of a constraint (row) is an
   110     /// extended number of type Value, i.e. a finite number of type
   111     /// Value or -\ref INF.
   112     virtual Value _getRowLowerBound(int i) const;
   113 
   114     /// The upper bound of a constraint (row) have to be given by an
   115     /// extended number of type Value, i.e. a finite number of type
   116     /// Value or \ref INF.
   117     virtual void _setRowUpperBound(int i, Value value);
   118     /// \e
   119 
   120     /// The upper bound of a constraint (row) is an
   121     /// extended number of type Value, i.e. a finite number of type
   122     /// Value or \ref INF.
   123     virtual Value _getRowUpperBound(int i) const;
   124 
   125     /// \e
   126     virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
   127     /// \e
   128     virtual void _getObjCoeffs(InsertIterator b) const;
   129 
   130     /// \e
   131     virtual void _setObjCoeff(int i, Value obj_coef);
   132     /// \e
   133     virtual Value _getObjCoeff(int i) const;
   134 
   135     ///\e
   136     virtual void _setSense(Sense);
   137     ///\e
   138     virtual Sense _getSense() const;
   139 
   140     ///\e
   141     virtual void _clear();
   142 
   143     ///\e
   144     virtual void _messageLevel(MessageLevel);
   145   };
   146 
   147   /// \brief Skeleton class for an LP solver interface
   148   ///
   149   ///This class does nothing, but it can serve as a skeleton when
   150   ///implementing an interface to new solvers.
   151 
   152   ///\ingroup lp_group
   153   class LpSkeleton : public LpSolver, public SkeletonSolverBase {
   154   public:
   155     ///\e
   156     LpSkeleton() : LpSolver(), SkeletonSolverBase() {}
   157     ///\e
   158     virtual LpSkeleton* newSolver() const;
   159     ///\e
   160     virtual LpSkeleton* cloneSolver() const;
   161   protected:
   162 
   163     ///\e
   164     virtual SolveExitStatus _solve();
   165 
   166     ///\e
   167     virtual Value _getPrimal(int i) const;
   168     ///\e
   169     virtual Value _getDual(int i) const;
   170 
   171     ///\e
   172     virtual Value _getPrimalValue() const;
   173 
   174     ///\e
   175     virtual Value _getPrimalRay(int i) const;
   176     ///\e
   177     virtual Value _getDualRay(int i) const;
   178 
   179     ///\e
   180     virtual ProblemType _getPrimalType() const;
   181     ///\e
   182     virtual ProblemType _getDualType() const;
   183 
   184     ///\e
   185     virtual VarStatus _getColStatus(int i) const;
   186     ///\e
   187     virtual VarStatus _getRowStatus(int i) const;
   188 
   189     ///\e
   190     virtual const char* _solverName() const;
   191 
   192   };
   193 
   194   /// \brief Skeleton class for a MIP solver interface
   195   ///
   196   ///This class does nothing, but it can serve as a skeleton when
   197   ///implementing an interface to new solvers.
   198   ///\ingroup lp_group
   199   class MipSkeleton : public MipSolver, public SkeletonSolverBase {
   200   public:
   201     ///\e
   202     MipSkeleton() : MipSolver(), SkeletonSolverBase() {}
   203     ///\e
   204     virtual MipSkeleton* newSolver() const;
   205     ///\e
   206     virtual MipSkeleton* cloneSolver() const;
   207 
   208   protected:
   209     ///\e
   210     virtual SolveExitStatus _solve();
   211 
   212     ///\e
   213     virtual Value _getSol(int i) const;
   214 
   215     ///\e
   216     virtual Value _getSolValue() const;
   217 
   218     ///\e
   219     virtual ProblemType _getType() const;
   220 
   221     ///\e
   222     virtual const char* _solverName() const;
   223   };
   224 
   225 } //namespace lemon
   226 
   227 #endif