1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
 
     3  * This file is a part of LEMON, a generic C++ optimization library.
 
     5  * Copyright (C) 2003-2008
 
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
 
     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.
 
    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
 
    19 #ifndef LEMON_LP_SKELETON_H
 
    20 #define LEMON_LP_SKELETON_H
 
    22 #include <lemon/lp_base.h>
 
    25 ///\brief Skeleton file to implement LP/MIP solver interfaces
 
    27 ///The classes in this file do nothing, but they can serve as skeletons when
 
    28 ///implementing an interface to new solvers.
 
    31   ///A skeleton class to implement LP/MIP solver base interface
 
    33   ///This class does nothing, but it can serve as a skeleton when
 
    34   ///implementing an interface to new solvers.
 
    35   class SkeletonSolverBase : public virtual LpBase {
 
    41       : col_num(-1), row_num(-1) {}
 
    44     virtual int _addCol();
 
    46     virtual int _addRow();
 
    48     virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
 
    50     virtual void _eraseCol(int i);
 
    52     virtual void _eraseRow(int i);
 
    55     virtual void _getColName(int col, std::string& name) const;
 
    57     virtual void _setColName(int col, const std::string& name);
 
    59     virtual int _colByName(const std::string& name) const;
 
    62     virtual void _getRowName(int row, std::string& name) const;
 
    64     virtual void _setRowName(int row, const std::string& name);
 
    66     virtual int _rowByName(const std::string& name) const;
 
    69     virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
 
    71     virtual void _getRowCoeffs(int i, InsertIterator b) const;
 
    73     virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
 
    75     virtual void _getColCoeffs(int i, InsertIterator b) const;
 
    77     /// Set one element of the coefficient matrix
 
    78     virtual void _setCoeff(int row, int col, Value value);
 
    80     /// Get one element of the coefficient matrix
 
    81     virtual Value _getCoeff(int row, int col) const;
 
    83     /// The lower bound of a variable (column) have to be given by an
 
    84     /// extended number of type Value, i.e. a finite number of type
 
    85     /// Value or -\ref INF.
 
    86     virtual void _setColLowerBound(int i, Value value);
 
    89     /// The lower bound of a variable (column) is an
 
    90     /// extended number of type Value, i.e. a finite number of type
 
    91     /// Value or -\ref INF.
 
    92     virtual Value _getColLowerBound(int i) const;
 
    94     /// The upper bound of a variable (column) have to be given by an
 
    95     /// extended number of type Value, i.e. a finite number of type
 
    96     /// Value or \ref INF.
 
    97     virtual void _setColUpperBound(int i, Value value);
 
   100     /// The upper bound of a variable (column) is an
 
   101     /// extended number of type Value, i.e. a finite number of type
 
   102     /// Value or \ref INF.
 
   103     virtual Value _getColUpperBound(int i) const;
 
   105     /// The lower bound of a constraint (row) have to be given by an
 
   106     /// extended number of type Value, i.e. a finite number of type
 
   107     /// Value or -\ref INF.
 
   108     virtual void _setRowLowerBound(int i, Value value);
 
   111     /// The lower bound of a constraint (row) is an
 
   112     /// extended number of type Value, i.e. a finite number of type
 
   113     /// Value or -\ref INF.
 
   114     virtual Value _getRowLowerBound(int i) const;
 
   116     /// The upper bound of a constraint (row) have to be given by an
 
   117     /// extended number of type Value, i.e. a finite number of type
 
   118     /// Value or \ref INF.
 
   119     virtual void _setRowUpperBound(int i, Value value);
 
   122     /// The upper bound of a constraint (row) is an
 
   123     /// extended number of type Value, i.e. a finite number of type
 
   124     /// Value or \ref INF.
 
   125     virtual Value _getRowUpperBound(int i) const;
 
   128     virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
 
   130     virtual void _getObjCoeffs(InsertIterator b) const;
 
   133     virtual void _setObjCoeff(int i, Value obj_coef);
 
   135     virtual Value _getObjCoeff(int i) const;
 
   138     virtual void _setSense(Sense);
 
   140     virtual Sense _getSense() const;
 
   143     virtual void _clear();
 
   146     virtual void _messageLevel(MessageLevel);
 
   149   /// \brief Skeleton class for an LP solver interface
 
   151   ///This class does nothing, but it can serve as a skeleton when
 
   152   ///implementing an interface to new solvers.
 
   155   class LpSkeleton : public LpSolver, public SkeletonSolverBase {
 
   158     LpSkeleton() : LpSolver(), SkeletonSolverBase() {}
 
   160     virtual LpSkeleton* newSolver() const;
 
   162     virtual LpSkeleton* cloneSolver() const;
 
   166     virtual SolveExitStatus _solve();
 
   169     virtual Value _getPrimal(int i) const;
 
   171     virtual Value _getDual(int i) const;
 
   174     virtual Value _getPrimalValue() const;
 
   177     virtual Value _getPrimalRay(int i) const;
 
   179     virtual Value _getDualRay(int i) const;
 
   182     virtual ProblemType _getPrimalType() const;
 
   184     virtual ProblemType _getDualType() const;
 
   187     virtual VarStatus _getColStatus(int i) const;
 
   189     virtual VarStatus _getRowStatus(int i) const;
 
   192     virtual const char* _solverName() const;
 
   196   /// \brief Skeleton class for a MIP solver interface
 
   198   ///This class does nothing, but it can serve as a skeleton when
 
   199   ///implementing an interface to new solvers.
 
   201   class MipSkeleton : public MipSolver, public SkeletonSolverBase {
 
   204     MipSkeleton() : MipSolver(), SkeletonSolverBase() {}
 
   206     virtual MipSkeleton* newSolver() const;
 
   208     virtual MipSkeleton* cloneSolver() const;
 
   212     virtual SolveExitStatus _solve();
 
   215     virtual Value _getSol(int i) const;
 
   218     virtual Value _getSolValue() const;
 
   221     virtual ProblemType _getType() const;
 
   224     virtual const char* _solverName() const;