lemon/lp_skeleton.h
author Alpar Juttner <alpar@cs.elte.hu>
Tue, 06 Aug 2013 12:28:37 +0200
changeset 1079 5958cc5c0a98
parent 877 141f9c0db4a3
child 1092 dceba191c00d
permissions -rw-r--r--
Merge further fixes #470
     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-2010
     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 int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
    49     /// \e
    50     virtual void _eraseCol(int i);
    51     /// \e
    52     virtual void _eraseRow(int i);
    53 
    54     /// \e
    55     virtual void _getColName(int col, std::string& name) const;
    56     /// \e
    57     virtual void _setColName(int col, const std::string& name);
    58     /// \e
    59     virtual int _colByName(const std::string& name) const;
    60 
    61     /// \e
    62     virtual void _getRowName(int row, std::string& name) const;
    63     /// \e
    64     virtual void _setRowName(int row, const std::string& name);
    65     /// \e
    66     virtual int _rowByName(const std::string& name) const;
    67 
    68     /// \e
    69     virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
    70     /// \e
    71     virtual void _getRowCoeffs(int i, InsertIterator b) const;
    72     /// \e
    73     virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
    74     /// \e
    75     virtual void _getColCoeffs(int i, InsertIterator b) const;
    76 
    77     /// Set one element of the coefficient matrix
    78     virtual void _setCoeff(int row, int col, Value value);
    79 
    80     /// Get one element of the coefficient matrix
    81     virtual Value _getCoeff(int row, int col) const;
    82 
    83     /// The lower bound of a variable (column) have to be given by an
    84     /// extended number of type Value, i.e. a finite number of type
    85     /// Value or -\ref INF.
    86     virtual void _setColLowerBound(int i, Value value);
    87     /// \e
    88 
    89     /// The lower bound of a variable (column) is an
    90     /// extended number of type Value, i.e. a finite number of type
    91     /// Value or -\ref INF.
    92     virtual Value _getColLowerBound(int i) const;
    93 
    94     /// The upper bound of a variable (column) have to be given by an
    95     /// extended number of type Value, i.e. a finite number of type
    96     /// Value or \ref INF.
    97     virtual void _setColUpperBound(int i, Value value);
    98     /// \e
    99 
   100     /// The upper bound of a variable (column) is an
   101     /// extended number of type Value, i.e. a finite number of type
   102     /// Value or \ref INF.
   103     virtual Value _getColUpperBound(int i) const;
   104 
   105     /// The lower bound of a constraint (row) have to be given by an
   106     /// extended number of type Value, i.e. a finite number of type
   107     /// Value or -\ref INF.
   108     virtual void _setRowLowerBound(int i, Value value);
   109     /// \e
   110 
   111     /// The lower bound of a constraint (row) is an
   112     /// extended number of type Value, i.e. a finite number of type
   113     /// Value or -\ref INF.
   114     virtual Value _getRowLowerBound(int i) const;
   115 
   116     /// The upper bound of a constraint (row) have to be given by an
   117     /// extended number of type Value, i.e. a finite number of type
   118     /// Value or \ref INF.
   119     virtual void _setRowUpperBound(int i, Value value);
   120     /// \e
   121 
   122     /// The upper bound of a constraint (row) is an
   123     /// extended number of type Value, i.e. a finite number of type
   124     /// Value or \ref INF.
   125     virtual Value _getRowUpperBound(int i) const;
   126 
   127     /// \e
   128     virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
   129     /// \e
   130     virtual void _getObjCoeffs(InsertIterator b) const;
   131 
   132     /// \e
   133     virtual void _setObjCoeff(int i, Value obj_coef);
   134     /// \e
   135     virtual Value _getObjCoeff(int i) const;
   136 
   137     ///\e
   138     virtual void _setSense(Sense);
   139     ///\e
   140     virtual Sense _getSense() const;
   141 
   142     ///\e
   143     virtual void _clear();
   144 
   145     ///\e
   146     virtual void _messageLevel(MessageLevel);
   147 
   148     ///\e
   149     virtual void _write(std::string file, std::string format) const;
   150 
   151   };
   152 
   153   /// \brief Skeleton class for an LP solver interface
   154   ///
   155   ///This class does nothing, but it can serve as a skeleton when
   156   ///implementing an interface to new solvers.
   157 
   158   ///\ingroup lp_group
   159   class LpSkeleton : public LpSolver, public SkeletonSolverBase {
   160   public:
   161     ///\e
   162     LpSkeleton() : LpSolver(), SkeletonSolverBase() {}
   163     ///\e
   164     virtual LpSkeleton* newSolver() const;
   165     ///\e
   166     virtual LpSkeleton* cloneSolver() const;
   167   protected:
   168 
   169     ///\e
   170     virtual SolveExitStatus _solve();
   171 
   172     ///\e
   173     virtual Value _getPrimal(int i) const;
   174     ///\e
   175     virtual Value _getDual(int i) const;
   176 
   177     ///\e
   178     virtual Value _getPrimalValue() const;
   179 
   180     ///\e
   181     virtual Value _getPrimalRay(int i) const;
   182     ///\e
   183     virtual Value _getDualRay(int i) const;
   184 
   185     ///\e
   186     virtual ProblemType _getPrimalType() const;
   187     ///\e
   188     virtual ProblemType _getDualType() const;
   189 
   190     ///\e
   191     virtual VarStatus _getColStatus(int i) const;
   192     ///\e
   193     virtual VarStatus _getRowStatus(int i) const;
   194 
   195     ///\e
   196     virtual const char* _solverName() const;
   197 
   198   };
   199 
   200   /// \brief Skeleton class for a MIP solver interface
   201   ///
   202   ///This class does nothing, but it can serve as a skeleton when
   203   ///implementing an interface to new solvers.
   204   ///\ingroup lp_group
   205   class MipSkeleton : public MipSolver, public SkeletonSolverBase {
   206   public:
   207     ///\e
   208     MipSkeleton() : MipSolver(), SkeletonSolverBase() {}
   209     ///\e
   210     virtual MipSkeleton* newSolver() const;
   211     ///\e
   212     virtual MipSkeleton* cloneSolver() const;
   213 
   214   protected:
   215     ///\e
   216     virtual SolveExitStatus _solve();
   217 
   218     ///\e
   219     virtual Value _getSol(int i) const;
   220 
   221     ///\e
   222     virtual Value _getSolValue() const;
   223 
   224     ///\e
   225     virtual ProblemType _getType() const;
   226 
   227     ///\e
   228     virtual const char* _solverName() const;
   229 
   230   };
   231 
   232 } //namespace lemon
   233 
   234 #endif