lemon/lp_skeleton.h
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 25 Feb 2009 11:10:57 +0000
changeset 545 e72bacfea6b7
parent 459 ed54c0d13df0
child 540 9db62975c32b
permissions -rw-r--r--
Remane GomoryHuTree to GomoryHu (#66)
     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 A skeleton file to implement LP solver interfaces
    26 namespace lemon {
    27 
    28   ///A skeleton class to implement LP solver interfaces
    29   class SkeletonSolverBase : public virtual LpBase {
    30     int col_num,row_num;
    31 
    32   protected:
    33 
    34     SkeletonSolverBase()
    35       : col_num(-1), row_num(-1) {}
    36 
    37     /// \e
    38     virtual int _addCol();
    39     /// \e
    40     virtual int _addRow();
    41     /// \e
    42     virtual void _eraseCol(int i);
    43     /// \e
    44     virtual void _eraseRow(int i);
    45 
    46     /// \e
    47     virtual void _getColName(int col, std::string& name) const;
    48     /// \e
    49     virtual void _setColName(int col, const std::string& name);
    50     /// \e
    51     virtual int _colByName(const std::string& name) const;
    52 
    53     /// \e
    54     virtual void _getRowName(int row, std::string& name) const;
    55     /// \e
    56     virtual void _setRowName(int row, const std::string& name);
    57     /// \e
    58     virtual int _rowByName(const std::string& name) const;
    59 
    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;
    68 
    69     /// Set one element of the coefficient matrix
    70     virtual void _setCoeff(int row, int col, Value value);
    71 
    72     /// Get one element of the coefficient matrix
    73     virtual Value _getCoeff(int row, int col) const;
    74 
    75     /// The lower bound of a variable (column) have to be given by an
    76     /// extended number of type Value, i.e. a finite number of type
    77     /// Value or -\ref INF.
    78     virtual void _setColLowerBound(int i, Value value);
    79     /// \e
    80 
    81     /// The lower bound of a variable (column) is an
    82     /// extended number of type Value, i.e. a finite number of type
    83     /// Value or -\ref INF.
    84     virtual Value _getColLowerBound(int i) const;
    85 
    86     /// The upper bound of a variable (column) have to be given by an
    87     /// extended number of type Value, i.e. a finite number of type
    88     /// Value or \ref INF.
    89     virtual void _setColUpperBound(int i, Value value);
    90     /// \e
    91 
    92     /// The upper bound of a variable (column) is an
    93     /// extended number of type Value, i.e. a finite number of type
    94     /// Value or \ref INF.
    95     virtual Value _getColUpperBound(int i) const;
    96 
    97     /// The lower bound of a constraint (row) have to be given by an
    98     /// extended number of type Value, i.e. a finite number of type
    99     /// Value or -\ref INF.
   100     virtual void _setRowLowerBound(int i, Value value);
   101     /// \e
   102 
   103     /// The lower bound of a constraint (row) is an
   104     /// extended number of type Value, i.e. a finite number of type
   105     /// Value or -\ref INF.
   106     virtual Value _getRowLowerBound(int i) const;
   107 
   108     /// The upper bound of a constraint (row) have to be given by an
   109     /// extended number of type Value, i.e. a finite number of type
   110     /// Value or \ref INF.
   111     virtual void _setRowUpperBound(int i, Value value);
   112     /// \e
   113 
   114     /// The upper bound of a constraint (row) is an
   115     /// extended number of type Value, i.e. a finite number of type
   116     /// Value or \ref INF.
   117     virtual Value _getRowUpperBound(int i) const;
   118 
   119     /// \e
   120     virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
   121     /// \e
   122     virtual void _getObjCoeffs(InsertIterator b) const;
   123 
   124     /// \e
   125     virtual void _setObjCoeff(int i, Value obj_coef);
   126     /// \e
   127     virtual Value _getObjCoeff(int i) const;
   128 
   129     ///\e
   130     virtual void _setSense(Sense);
   131     ///\e
   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
   150     virtual SolveExitStatus _solve();
   151 
   152     ///\e
   153     virtual Value _getPrimal(int i) const;
   154     ///\e
   155     virtual Value _getDual(int i) const;
   156 
   157     ///\e
   158     virtual Value _getPrimalValue() const;
   159 
   160     ///\e
   161     virtual Value _getPrimalRay(int i) const;
   162     ///\e
   163     virtual Value _getDualRay(int i) const;
   164 
   165     ///\e
   166     virtual ProblemType _getPrimalType() const;
   167     ///\e
   168     virtual ProblemType _getDualType() const;
   169 
   170     ///\e
   171     virtual VarStatus _getColStatus(int i) const;
   172     ///\e
   173     virtual VarStatus _getRowStatus(int i) const;
   174 
   175     ///\e
   176     virtual LpSkeleton* _newSolver() const;
   177     ///\e
   178     virtual LpSkeleton* _cloneSolver() const;
   179     ///\e
   180     virtual const char* _solverName() const;
   181 
   182   };
   183 
   184   /// \brief Interface for a skeleton MIP solver
   185   ///
   186   /// This class implements an interface for a skeleton MIP solver.
   187   ///\ingroup lp_group
   188   class MipSkeleton : public SkeletonSolverBase, public MipSolver {
   189   public:
   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 
   225   };
   226 
   227 } //namespace lemon
   228 
   229 #endif