lemon/lp_skeleton.h
changeset 708 994c7df296c9
parent 529 89e29e22d479
child 761 f1398882a928
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lemon/lp_skeleton.h	Thu Dec 10 17:05:35 2009 +0100
     1.3 @@ -0,0 +1,227 @@
     1.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library.
     1.7 + *
     1.8 + * Copyright (C) 2003-2008
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#ifndef LEMON_LP_SKELETON_H
    1.23 +#define LEMON_LP_SKELETON_H
    1.24 +
    1.25 +#include <lemon/lp_base.h>
    1.26 +
    1.27 +///\file
    1.28 +///\brief Skeleton file to implement LP/MIP solver interfaces
    1.29 +///  
    1.30 +///The classes in this file do nothing, but they can serve as skeletons when
    1.31 +///implementing an interface to new solvers.
    1.32 +namespace lemon {
    1.33 +
    1.34 +  ///A skeleton class to implement LP/MIP solver base interface
    1.35 +  
    1.36 +  ///This class does nothing, but it can serve as a skeleton when
    1.37 +  ///implementing an interface to new solvers.
    1.38 +  class SkeletonSolverBase : public virtual LpBase {
    1.39 +    int col_num,row_num;
    1.40 +
    1.41 +  protected:
    1.42 +
    1.43 +    SkeletonSolverBase()
    1.44 +      : col_num(-1), row_num(-1) {}
    1.45 +
    1.46 +    /// \e
    1.47 +    virtual int _addCol();
    1.48 +    /// \e
    1.49 +    virtual int _addRow();
    1.50 +    /// \e
    1.51 +    virtual void _eraseCol(int i);
    1.52 +    /// \e
    1.53 +    virtual void _eraseRow(int i);
    1.54 +
    1.55 +    /// \e
    1.56 +    virtual void _getColName(int col, std::string& name) const;
    1.57 +    /// \e
    1.58 +    virtual void _setColName(int col, const std::string& name);
    1.59 +    /// \e
    1.60 +    virtual int _colByName(const std::string& name) const;
    1.61 +
    1.62 +    /// \e
    1.63 +    virtual void _getRowName(int row, std::string& name) const;
    1.64 +    /// \e
    1.65 +    virtual void _setRowName(int row, const std::string& name);
    1.66 +    /// \e
    1.67 +    virtual int _rowByName(const std::string& name) const;
    1.68 +
    1.69 +    /// \e
    1.70 +    virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
    1.71 +    /// \e
    1.72 +    virtual void _getRowCoeffs(int i, InsertIterator b) const;
    1.73 +    /// \e
    1.74 +    virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
    1.75 +    /// \e
    1.76 +    virtual void _getColCoeffs(int i, InsertIterator b) const;
    1.77 +
    1.78 +    /// Set one element of the coefficient matrix
    1.79 +    virtual void _setCoeff(int row, int col, Value value);
    1.80 +
    1.81 +    /// Get one element of the coefficient matrix
    1.82 +    virtual Value _getCoeff(int row, int col) const;
    1.83 +
    1.84 +    /// The lower bound of a variable (column) have to be given by an
    1.85 +    /// extended number of type Value, i.e. a finite number of type
    1.86 +    /// Value or -\ref INF.
    1.87 +    virtual void _setColLowerBound(int i, Value value);
    1.88 +    /// \e
    1.89 +
    1.90 +    /// The lower bound of a variable (column) is an
    1.91 +    /// extended number of type Value, i.e. a finite number of type
    1.92 +    /// Value or -\ref INF.
    1.93 +    virtual Value _getColLowerBound(int i) const;
    1.94 +
    1.95 +    /// The upper bound of a variable (column) have to be given by an
    1.96 +    /// extended number of type Value, i.e. a finite number of type
    1.97 +    /// Value or \ref INF.
    1.98 +    virtual void _setColUpperBound(int i, Value value);
    1.99 +    /// \e
   1.100 +
   1.101 +    /// The upper bound of a variable (column) is an
   1.102 +    /// extended number of type Value, i.e. a finite number of type
   1.103 +    /// Value or \ref INF.
   1.104 +    virtual Value _getColUpperBound(int i) const;
   1.105 +
   1.106 +    /// The lower bound of a constraint (row) have to be given by an
   1.107 +    /// extended number of type Value, i.e. a finite number of type
   1.108 +    /// Value or -\ref INF.
   1.109 +    virtual void _setRowLowerBound(int i, Value value);
   1.110 +    /// \e
   1.111 +
   1.112 +    /// The lower bound of a constraint (row) is an
   1.113 +    /// extended number of type Value, i.e. a finite number of type
   1.114 +    /// Value or -\ref INF.
   1.115 +    virtual Value _getRowLowerBound(int i) const;
   1.116 +
   1.117 +    /// The upper bound of a constraint (row) have to be given by an
   1.118 +    /// extended number of type Value, i.e. a finite number of type
   1.119 +    /// Value or \ref INF.
   1.120 +    virtual void _setRowUpperBound(int i, Value value);
   1.121 +    /// \e
   1.122 +
   1.123 +    /// The upper bound of a constraint (row) is an
   1.124 +    /// extended number of type Value, i.e. a finite number of type
   1.125 +    /// Value or \ref INF.
   1.126 +    virtual Value _getRowUpperBound(int i) const;
   1.127 +
   1.128 +    /// \e
   1.129 +    virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
   1.130 +    /// \e
   1.131 +    virtual void _getObjCoeffs(InsertIterator b) const;
   1.132 +
   1.133 +    /// \e
   1.134 +    virtual void _setObjCoeff(int i, Value obj_coef);
   1.135 +    /// \e
   1.136 +    virtual Value _getObjCoeff(int i) const;
   1.137 +
   1.138 +    ///\e
   1.139 +    virtual void _setSense(Sense);
   1.140 +    ///\e
   1.141 +    virtual Sense _getSense() const;
   1.142 +
   1.143 +    ///\e
   1.144 +    virtual void _clear();
   1.145 +
   1.146 +    ///\e
   1.147 +    virtual void _messageLevel(MessageLevel);
   1.148 +  };
   1.149 +
   1.150 +  /// \brief Skeleton class for an LP solver interface
   1.151 +  ///
   1.152 +  ///This class does nothing, but it can serve as a skeleton when
   1.153 +  ///implementing an interface to new solvers.
   1.154 +
   1.155 +  ///\ingroup lp_group
   1.156 +  class LpSkeleton : public LpSolver, public SkeletonSolverBase {
   1.157 +  public:
   1.158 +    ///\e
   1.159 +    LpSkeleton() : LpSolver(), SkeletonSolverBase() {}
   1.160 +    ///\e
   1.161 +    virtual LpSkeleton* newSolver() const;
   1.162 +    ///\e
   1.163 +    virtual LpSkeleton* cloneSolver() const;
   1.164 +  protected:
   1.165 +
   1.166 +    ///\e
   1.167 +    virtual SolveExitStatus _solve();
   1.168 +
   1.169 +    ///\e
   1.170 +    virtual Value _getPrimal(int i) const;
   1.171 +    ///\e
   1.172 +    virtual Value _getDual(int i) const;
   1.173 +
   1.174 +    ///\e
   1.175 +    virtual Value _getPrimalValue() const;
   1.176 +
   1.177 +    ///\e
   1.178 +    virtual Value _getPrimalRay(int i) const;
   1.179 +    ///\e
   1.180 +    virtual Value _getDualRay(int i) const;
   1.181 +
   1.182 +    ///\e
   1.183 +    virtual ProblemType _getPrimalType() const;
   1.184 +    ///\e
   1.185 +    virtual ProblemType _getDualType() const;
   1.186 +
   1.187 +    ///\e
   1.188 +    virtual VarStatus _getColStatus(int i) const;
   1.189 +    ///\e
   1.190 +    virtual VarStatus _getRowStatus(int i) const;
   1.191 +
   1.192 +    ///\e
   1.193 +    virtual const char* _solverName() const;
   1.194 +
   1.195 +  };
   1.196 +
   1.197 +  /// \brief Skeleton class for a MIP solver interface
   1.198 +  ///
   1.199 +  ///This class does nothing, but it can serve as a skeleton when
   1.200 +  ///implementing an interface to new solvers.
   1.201 +  ///\ingroup lp_group
   1.202 +  class MipSkeleton : public MipSolver, public SkeletonSolverBase {
   1.203 +  public:
   1.204 +    ///\e
   1.205 +    MipSkeleton() : MipSolver(), SkeletonSolverBase() {}
   1.206 +    ///\e
   1.207 +    virtual MipSkeleton* newSolver() const;
   1.208 +    ///\e
   1.209 +    virtual MipSkeleton* cloneSolver() const;
   1.210 +
   1.211 +  protected:
   1.212 +    ///\e
   1.213 +    virtual SolveExitStatus _solve();
   1.214 +
   1.215 +    ///\e
   1.216 +    virtual Value _getSol(int i) const;
   1.217 +
   1.218 +    ///\e
   1.219 +    virtual Value _getSolValue() const;
   1.220 +
   1.221 +    ///\e
   1.222 +    virtual ProblemType _getType() const;
   1.223 +
   1.224 +    ///\e
   1.225 +    virtual const char* _solverName() const;
   1.226 +  };
   1.227 +
   1.228 +} //namespace lemon
   1.229 +
   1.230 +#endif