lemon/lp_clp.h
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 12 Jan 2009 12:25:55 +0000
changeset 460 76ec7bd57026
permissions -rw-r--r--
Bypass warnings with gcc 4.3
deba@459
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@459
     2
 *
deba@459
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@459
     4
 *
deba@459
     5
 * Copyright (C) 2003-2008
deba@459
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@459
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@459
     8
 *
deba@459
     9
 * Permission to use, modify and distribute this software is granted
deba@459
    10
 * provided that this copyright notice appears in all copies. For
deba@459
    11
 * precise terms see the accompanying LICENSE file.
deba@459
    12
 *
deba@459
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@459
    14
 * express or implied, and with no claim as to its suitability for any
deba@459
    15
 * purpose.
deba@459
    16
 *
deba@459
    17
 */
deba@459
    18
deba@459
    19
#ifndef LEMON_LP_CLP_H
deba@459
    20
#define LEMON_LP_CLP_H
deba@459
    21
deba@459
    22
///\file
deba@459
    23
///\brief Header of the LEMON-CLP lp solver interface.
deba@459
    24
deba@459
    25
#include <vector>
deba@459
    26
#include <string>
deba@459
    27
deba@459
    28
#include <lemon/lp_base.h>
deba@459
    29
deba@459
    30
class ClpSimplex;
deba@459
    31
deba@459
    32
namespace lemon {
deba@459
    33
deba@459
    34
  /// \ingroup lp_group
deba@459
    35
  ///
deba@459
    36
  /// \brief Interface for the CLP solver
deba@459
    37
  ///
deba@459
    38
  /// This class implements an interface for the Clp LP solver.  The
deba@459
    39
  /// Clp library is an object oriented lp solver library developed at
deba@459
    40
  /// the IBM. The CLP is part of the COIN-OR package and it can be
deba@459
    41
  /// used with Common Public License.
deba@459
    42
  class LpClp : public LpSolver {
deba@459
    43
  protected:
deba@459
    44
deba@459
    45
    ClpSimplex* _prob;
deba@459
    46
deba@459
    47
    std::map<std::string, int> _col_names_ref;
deba@459
    48
    std::map<std::string, int> _row_names_ref;
deba@459
    49
deba@459
    50
  public:
deba@459
    51
deba@459
    52
    /// \e
deba@459
    53
    LpClp();
deba@459
    54
    /// \e
deba@459
    55
    LpClp(const LpClp&);
deba@459
    56
    /// \e
deba@459
    57
    ~LpClp();
deba@459
    58
deba@459
    59
  protected:
deba@459
    60
deba@459
    61
    mutable double* _primal_ray;
deba@459
    62
    mutable double* _dual_ray;
deba@459
    63
deba@459
    64
    void _init_temporals();
deba@459
    65
    void _clear_temporals();
deba@459
    66
deba@459
    67
  protected:
deba@459
    68
deba@459
    69
    virtual LpClp* _newSolver() const;
deba@459
    70
    virtual LpClp* _cloneSolver() const;
deba@459
    71
deba@459
    72
    virtual const char* _solverName() const;
deba@459
    73
deba@459
    74
    virtual int _addCol();
deba@459
    75
    virtual int _addRow();
deba@459
    76
deba@459
    77
    virtual void _eraseCol(int i);
deba@459
    78
    virtual void _eraseRow(int i);
deba@459
    79
deba@459
    80
    virtual void _eraseColId(int i);
deba@459
    81
    virtual void _eraseRowId(int i);
deba@459
    82
deba@459
    83
    virtual void _getColName(int col, std::string& name) const;
deba@459
    84
    virtual void _setColName(int col, const std::string& name);
deba@459
    85
    virtual int _colByName(const std::string& name) const;
deba@459
    86
deba@459
    87
    virtual void _getRowName(int row, std::string& name) const;
deba@459
    88
    virtual void _setRowName(int row, const std::string& name);
deba@459
    89
    virtual int _rowByName(const std::string& name) const;
deba@459
    90
deba@459
    91
    virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
deba@459
    92
    virtual void _getRowCoeffs(int i, InsertIterator b) const;
deba@459
    93
deba@459
    94
    virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
deba@459
    95
    virtual void _getColCoeffs(int i, InsertIterator b) const;
deba@459
    96
deba@459
    97
    virtual void _setCoeff(int row, int col, Value value);
deba@459
    98
    virtual Value _getCoeff(int row, int col) const;
deba@459
    99
deba@459
   100
    virtual void _setColLowerBound(int i, Value value);
deba@459
   101
    virtual Value _getColLowerBound(int i) const;
deba@459
   102
    virtual void _setColUpperBound(int i, Value value);
deba@459
   103
    virtual Value _getColUpperBound(int i) const;
deba@459
   104
deba@459
   105
    virtual void _setRowLowerBound(int i, Value value);
deba@459
   106
    virtual Value _getRowLowerBound(int i) const;
deba@459
   107
    virtual void _setRowUpperBound(int i, Value value);
deba@459
   108
    virtual Value _getRowUpperBound(int i) const;
deba@459
   109
deba@459
   110
    virtual void _setObjCoeffs(ExprIterator, ExprIterator);
deba@459
   111
    virtual void _getObjCoeffs(InsertIterator) const;
deba@459
   112
deba@459
   113
    virtual void _setObjCoeff(int i, Value obj_coef);
deba@459
   114
    virtual Value _getObjCoeff(int i) const;
deba@459
   115
deba@459
   116
    virtual void _setSense(Sense sense);
deba@459
   117
    virtual Sense _getSense() const;
deba@459
   118
deba@459
   119
    virtual SolveExitStatus _solve();
deba@459
   120
deba@459
   121
    virtual Value _getPrimal(int i) const;
deba@459
   122
    virtual Value _getDual(int i) const;
deba@459
   123
deba@459
   124
    virtual Value _getPrimalValue() const;
deba@459
   125
deba@459
   126
    virtual Value _getPrimalRay(int i) const;
deba@459
   127
    virtual Value _getDualRay(int i) const;
deba@459
   128
deba@459
   129
    virtual VarStatus _getColStatus(int i) const;
deba@459
   130
    virtual VarStatus _getRowStatus(int i) const;
deba@459
   131
deba@459
   132
    virtual ProblemType _getPrimalType() const;
deba@459
   133
    virtual ProblemType _getDualType() const;
deba@459
   134
deba@459
   135
    virtual void _clear();
deba@459
   136
deba@459
   137
  public:
deba@459
   138
deba@459
   139
    ///Solves LP with primal simplex method.
deba@459
   140
    SolveExitStatus solvePrimal();
deba@459
   141
deba@459
   142
    ///Solves LP with dual simplex method.
deba@459
   143
    SolveExitStatus solveDual();
deba@459
   144
deba@459
   145
    ///Solves LP with barrier method.
deba@459
   146
    SolveExitStatus solveBarrier();
deba@459
   147
deba@459
   148
    ///Returns the constraint identifier understood by CLP.
deba@459
   149
    int clpRow(Row r) const { return rows(id(r)); }
deba@459
   150
deba@459
   151
    ///Returns the variable identifier understood by CLP.
deba@459
   152
    int clpCol(Col c) const { return cols(id(c)); }
deba@459
   153
deba@459
   154
    ///Enum for \c messageLevel() parameter
deba@459
   155
    enum MessageLevel {
deba@459
   156
      /// no output (default value)
deba@459
   157
      MESSAGE_NO_OUTPUT = 0,
deba@459
   158
      /// print final solution
deba@459
   159
      MESSAGE_FINAL_SOLUTION = 1,
deba@459
   160
      /// print factorization
deba@459
   161
      MESSAGE_FACTORIZATION = 2,
deba@459
   162
      /// normal output
deba@459
   163
      MESSAGE_NORMAL_OUTPUT = 3,
deba@459
   164
      /// verbose output
deba@459
   165
      MESSAGE_VERBOSE_OUTPUT = 4
deba@459
   166
    };
deba@459
   167
    ///Set the verbosity of the messages
deba@459
   168
deba@459
   169
    ///Set the verbosity of the messages
deba@459
   170
    ///
deba@459
   171
    ///\param m is the level of the messages output by the solver routines.
deba@459
   172
    void messageLevel(MessageLevel m);
deba@459
   173
deba@459
   174
  };
deba@459
   175
deba@459
   176
} //END OF NAMESPACE LEMON
deba@459
   177
deba@459
   178
#endif //LEMON_LP_CLP_H
deba@459
   179