lemon/lp_skeleton.h
author Peter Kovacs <kpeter@inf.elte.hu>
Fri, 27 Mar 2009 07:24:52 +0100
changeset 545 b779c4dc7496
parent 528 9db62975c32b
child 568 745e182d0139
permissions -rw-r--r--
Fix and extend the migration script (#245)
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@459
   143
  };
deba@459
   144
alpar@528
   145
  /// \brief Skeleton class for an LP solver interface
deba@459
   146
  ///
alpar@528
   147
  ///This class does nothing, but it can serve as a skeleton when
alpar@528
   148
  ///implementing an interface to new solvers.
alpar@528
   149
deba@459
   150
  ///\ingroup lp_group
alpar@528
   151
  class LpSkeleton : public LpSolver, public SkeletonSolverBase {
deba@459
   152
  public:
alpar@528
   153
    ///\e
alpar@528
   154
    LpSkeleton() : LpSolver(), SkeletonSolverBase() {}
alpar@528
   155
    ///\e
alpar@528
   156
    virtual LpSkeleton* newSolver() const;
alpar@528
   157
    ///\e
alpar@528
   158
    virtual LpSkeleton* cloneSolver() const;
deba@459
   159
  protected:
deba@459
   160
deba@459
   161
    ///\e
deba@459
   162
    virtual SolveExitStatus _solve();
deba@459
   163
deba@459
   164
    ///\e
deba@459
   165
    virtual Value _getPrimal(int i) const;
deba@459
   166
    ///\e
deba@459
   167
    virtual Value _getDual(int i) const;
deba@459
   168
deba@459
   169
    ///\e
deba@459
   170
    virtual Value _getPrimalValue() const;
deba@459
   171
deba@459
   172
    ///\e
deba@459
   173
    virtual Value _getPrimalRay(int i) const;
deba@459
   174
    ///\e
deba@459
   175
    virtual Value _getDualRay(int i) const;
deba@459
   176
deba@459
   177
    ///\e
deba@459
   178
    virtual ProblemType _getPrimalType() const;
deba@459
   179
    ///\e
deba@459
   180
    virtual ProblemType _getDualType() const;
deba@459
   181
deba@459
   182
    ///\e
deba@459
   183
    virtual VarStatus _getColStatus(int i) const;
deba@459
   184
    ///\e
deba@459
   185
    virtual VarStatus _getRowStatus(int i) const;
deba@459
   186
deba@459
   187
    ///\e
deba@459
   188
    virtual const char* _solverName() const;
deba@459
   189
deba@459
   190
  };
deba@459
   191
alpar@528
   192
  /// \brief Skeleton class for a MIP solver interface
deba@459
   193
  ///
alpar@528
   194
  ///This class does nothing, but it can serve as a skeleton when
alpar@528
   195
  ///implementing an interface to new solvers.
deba@459
   196
  ///\ingroup lp_group
alpar@528
   197
  class MipSkeleton : public MipSolver, public SkeletonSolverBase {
deba@459
   198
  public:
alpar@528
   199
    ///\e
alpar@528
   200
    MipSkeleton() : MipSolver(), SkeletonSolverBase() {}
alpar@528
   201
    ///\e
alpar@528
   202
    virtual MipSkeleton* newSolver() const;
alpar@528
   203
    ///\e
alpar@528
   204
    virtual MipSkeleton* cloneSolver() const;
deba@459
   205
deba@459
   206
  protected:
deba@459
   207
    ///\e
deba@458
   208
    virtual SolveExitStatus _solve();
deba@458
   209
deba@458
   210
    ///\e
deba@459
   211
    virtual Value _getSol(int i) const;
deba@458
   212
deba@458
   213
    ///\e
deba@459
   214
    virtual Value _getSolValue() const;
deba@458
   215
deba@458
   216
    ///\e
deba@459
   217
    virtual ProblemType _getType() const;
deba@458
   218
deba@458
   219
    ///\e
deba@459
   220
    virtual const char* _solverName() const;
deba@458
   221
  };
deba@458
   222
deba@458
   223
} //namespace lemon
deba@458
   224
deba@514
   225
#endif