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