lemon/clp.h
author Balazs Dezso <deba@inf.elte.hu>
Thu, 24 Jun 2010 09:27:53 +0200
changeset 894 bb70ad62c95f
parent 540 9db62975c32b
child 746 e4554cd6b2bf
permissions -rw-r--r--
Fix critical bug in preflow (#372)

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