lemon/lp_skeleton.h
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 23 Feb 2009 11:49:57 +0000
changeset 526 28b154307c0d
parent 458 7afc121e0689
child 529 f5bc148f7e1f
permissions -rw-r--r--
DIMACS solver utility (#226)
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@458
    19
#ifndef LEMON_LP_SKELETON
deba@458
    20
#define LEMON_LP_SKELETON
deba@458
    21
deba@458
    22
#include <lemon/lp_base.h>
deba@458
    23
deba@458
    24
///\file
deba@458
    25
///\brief A skeleton file to implement LP solver interfaces
deba@458
    26
namespace lemon {
deba@458
    27
deba@458
    28
  ///A skeleton class to implement LP solver interfaces
deba@459
    29
  class SkeletonSolverBase : public virtual LpBase {
deba@458
    30
    int col_num,row_num;
deba@458
    31
deba@458
    32
  protected:
deba@458
    33
deba@459
    34
    SkeletonSolverBase()
deba@459
    35
      : col_num(-1), row_num(-1) {}
deba@459
    36
deba@458
    37
    /// \e
deba@458
    38
    virtual int _addCol();
deba@458
    39
    /// \e
deba@458
    40
    virtual int _addRow();
deba@458
    41
    /// \e
deba@458
    42
    virtual void _eraseCol(int i);
deba@458
    43
    /// \e
deba@458
    44
    virtual void _eraseRow(int i);
deba@459
    45
deba@458
    46
    /// \e
deba@459
    47
    virtual void _getColName(int col, std::string& name) const;
deba@458
    48
    /// \e
deba@459
    49
    virtual void _setColName(int col, const std::string& name);
deba@458
    50
    /// \e
deba@458
    51
    virtual int _colByName(const std::string& name) const;
deba@458
    52
deba@458
    53
    /// \e
deba@459
    54
    virtual void _getRowName(int row, std::string& name) const;
deba@458
    55
    /// \e
deba@459
    56
    virtual void _setRowName(int row, const std::string& name);
deba@458
    57
    /// \e
deba@459
    58
    virtual int _rowByName(const std::string& name) const;
deba@459
    59
deba@458
    60
    /// \e
deba@459
    61
    virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
deba@459
    62
    /// \e
deba@459
    63
    virtual void _getRowCoeffs(int i, InsertIterator b) const;
deba@459
    64
    /// \e
deba@459
    65
    virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
deba@459
    66
    /// \e
deba@459
    67
    virtual void _getColCoeffs(int i, InsertIterator b) const;
deba@458
    68
deba@458
    69
    /// Set one element of the coefficient matrix
deba@458
    70
    virtual void _setCoeff(int row, int col, Value value);
deba@458
    71
deba@458
    72
    /// Get one element of the coefficient matrix
deba@458
    73
    virtual Value _getCoeff(int row, int col) const;
deba@458
    74
deba@458
    75
    /// The lower bound of a variable (column) have to be given by an
deba@458
    76
    /// extended number of type Value, i.e. a finite number of type
deba@458
    77
    /// Value or -\ref INF.
deba@458
    78
    virtual void _setColLowerBound(int i, Value value);
deba@458
    79
    /// \e
deba@458
    80
deba@458
    81
    /// The lower bound of a variable (column) is 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 Value _getColLowerBound(int i) const;
deba@458
    85
deba@458
    86
    /// The upper bound of a variable (column) have to be given by an
deba@458
    87
    /// extended number of type Value, i.e. a finite number of type
deba@458
    88
    /// Value or \ref INF.
deba@458
    89
    virtual void _setColUpperBound(int i, Value value);
deba@458
    90
    /// \e
deba@458
    91
deba@458
    92
    /// The upper bound of a variable (column) is 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 Value _getColUpperBound(int i) const;
deba@458
    96
deba@459
    97
    /// The lower bound of a constraint (row) have to be given by an
deba@458
    98
    /// extended number of type Value, i.e. a finite number of type
deba@459
    99
    /// Value or -\ref INF.
deba@459
   100
    virtual void _setRowLowerBound(int i, Value value);
deba@458
   101
    /// \e
deba@458
   102
deba@459
   103
    /// The lower bound of a constraint (row) is an
deba@459
   104
    /// extended number of type Value, i.e. a finite number of type
deba@459
   105
    /// Value or -\ref INF.
deba@459
   106
    virtual Value _getRowLowerBound(int i) const;
deba@458
   107
deba@459
   108
    /// The upper bound of a constraint (row) have to be given by an
deba@459
   109
    /// extended number of type Value, i.e. a finite number of type
deba@459
   110
    /// Value or \ref INF.
deba@459
   111
    virtual void _setRowUpperBound(int i, Value value);
deba@458
   112
    /// \e
deba@458
   113
deba@459
   114
    /// The upper bound of a constraint (row) is 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 Value _getRowUpperBound(int i) const;
deba@458
   118
deba@458
   119
    /// \e
deba@459
   120
    virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
deba@459
   121
    /// \e
deba@459
   122
    virtual void _getObjCoeffs(InsertIterator b) const;
deba@459
   123
deba@458
   124
    /// \e
deba@458
   125
    virtual void _setObjCoeff(int i, Value obj_coef);
deba@458
   126
    /// \e
deba@458
   127
    virtual Value _getObjCoeff(int i) const;
deba@458
   128
deba@458
   129
    ///\e
deba@459
   130
    virtual void _setSense(Sense);
deba@459
   131
    ///\e
deba@459
   132
    virtual Sense _getSense() const;
deba@459
   133
deba@459
   134
    ///\e
deba@459
   135
    virtual void _clear();
deba@459
   136
deba@459
   137
  };
deba@459
   138
deba@459
   139
  /// \brief Interface for a skeleton LP solver
deba@459
   140
  ///
deba@459
   141
  /// This class implements an interface for a skeleton LP solver.
deba@459
   142
  ///\ingroup lp_group
deba@459
   143
  class LpSkeleton : public SkeletonSolverBase, public LpSolver {
deba@459
   144
  public:
deba@459
   145
    LpSkeleton() : SkeletonSolverBase(), LpSolver() {}
deba@459
   146
deba@459
   147
  protected:
deba@459
   148
deba@459
   149
    ///\e
deba@459
   150
    virtual SolveExitStatus _solve();
deba@459
   151
deba@459
   152
    ///\e
deba@459
   153
    virtual Value _getPrimal(int i) const;
deba@459
   154
    ///\e
deba@459
   155
    virtual Value _getDual(int i) const;
deba@459
   156
deba@459
   157
    ///\e
deba@459
   158
    virtual Value _getPrimalValue() const;
deba@459
   159
deba@459
   160
    ///\e
deba@459
   161
    virtual Value _getPrimalRay(int i) const;
deba@459
   162
    ///\e
deba@459
   163
    virtual Value _getDualRay(int i) const;
deba@459
   164
deba@459
   165
    ///\e
deba@459
   166
    virtual ProblemType _getPrimalType() const;
deba@459
   167
    ///\e
deba@459
   168
    virtual ProblemType _getDualType() const;
deba@459
   169
deba@459
   170
    ///\e
deba@459
   171
    virtual VarStatus _getColStatus(int i) const;
deba@459
   172
    ///\e
deba@459
   173
    virtual VarStatus _getRowStatus(int i) const;
deba@459
   174
deba@459
   175
    ///\e
deba@459
   176
    virtual LpSkeleton* _newSolver() const;
deba@459
   177
    ///\e
deba@459
   178
    virtual LpSkeleton* _cloneSolver() const;
deba@459
   179
    ///\e
deba@459
   180
    virtual const char* _solverName() const;
deba@459
   181
deba@459
   182
  };
deba@459
   183
deba@459
   184
  /// \brief Interface for a skeleton MIP solver
deba@459
   185
  ///
deba@459
   186
  /// This class implements an interface for a skeleton MIP solver.
deba@459
   187
  ///\ingroup lp_group
deba@459
   188
  class MipSkeleton : public SkeletonSolverBase, public MipSolver {
deba@459
   189
  public:
deba@459
   190
    MipSkeleton() : SkeletonSolverBase(), MipSolver() {}
deba@459
   191
deba@459
   192
  protected:
deba@459
   193
    ///\e
deba@458
   194
deba@458
   195
    ///\bug Wrong interface
deba@458
   196
    ///
deba@458
   197
    virtual SolveExitStatus _solve();
deba@458
   198
deba@458
   199
    ///\e
deba@458
   200
deba@458
   201
    ///\bug Wrong interface
deba@458
   202
    ///
deba@459
   203
    virtual Value _getSol(int i) const;
deba@458
   204
deba@458
   205
    ///\e
deba@458
   206
deba@458
   207
    ///\bug Wrong interface
deba@458
   208
    ///
deba@459
   209
    virtual Value _getSolValue() const;
deba@458
   210
deba@458
   211
    ///\e
deba@458
   212
deba@458
   213
    ///\bug Wrong interface
deba@458
   214
    ///
deba@459
   215
    virtual ProblemType _getType() const;
deba@458
   216
deba@458
   217
    ///\e
deba@459
   218
    virtual MipSkeleton* _newSolver() const;
deba@458
   219
deba@458
   220
    ///\e
deba@459
   221
    virtual MipSkeleton* _cloneSolver() const;
deba@459
   222
    ///\e
deba@459
   223
    virtual const char* _solverName() const;
deba@458
   224
deba@458
   225
  };
deba@458
   226
deba@458
   227
} //namespace lemon
deba@458
   228
deba@458
   229
#endif // LEMON_LP_SKELETON