lemon/clp.h
author Peter Kovacs <kpeter@inf.elte.hu>
Fri, 17 Apr 2009 18:04:36 +0200
changeset 609 e6927fe719e6
parent 461 08d495d48089
child 540 9db62975c32b
permissions -rw-r--r--
Support >= and <= constraints in NetworkSimplex (#219, #234)

By default the same inequality constraints are supported as by
Circulation (the GEQ form), but the LEQ form can also be selected
using the problemType() function.

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