Modelib: Fichier source de NumVarMatrix.cpp

Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

# NumVarMatrix.cpp

Aller à la documentation de ce fichier.

    00001 /*
    00002     Copyright (c) 2005, Quentin Lequy and Romain Gaucher
    00003     All rights reserved.
    00004
    00005     Redistribution and use in source and binary forms, with or
    00006     without modification, are permitted provided that the following
    00007     conditions are met:
    00008
    00009         * Redistributions of source code must retain the above copyright
    00010           notice, this list of conditions and the following disclaimer.
    00011
    00012         * Redistributions in binary form must reproduce the above copyright
    00013           notice, this list of conditions and the following disclaimer in the
    00014           documentation and/or other materials provided with the distribution.
    00015
    00016         * Neither the name of Quentin Lequy or Romain Gaucher nor the names
    00017           of its contributors may be used to endorse or promote products
    00018           derived from this software without specific prior written permission.
    00019
    00020     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    00021     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00022     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00023     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    00024     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    00025     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    00026     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
    00027     AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00028     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00029     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00030 */
    00031
    00032 #include "NumVarMatrix.h"
    00033 #include "NumVarArray.h"
    00034 #include "Model.h"
    00035
    00036 namespace Modelib {
    00037
    00038 /*----------------------------------------------------------------------------*/
    00039
    00046 NumVarMatrix::NumVarMatrix( Model & _modele,
    00047                             unsigned sizeI,
    00048                             unsigned sizeJ,
    00049                             float _lb,
    00050                             float _ub,
    00051                             MuteVar::VarType _type,
    00052                             const std::string & nom,
    00053                             const std::string & milieu,
    00054                             const std::string & fin)
    00055 : modele(&_modele),type(_type)
    00056 {
    00057
    00058   if(nom != "unknow")
    00059     for(unsigned i=0;i < sizeI; ++i)
    00060     {
    00061       char id[16];
    00062       sprintf(id,"%d",i);
    00063       varMatrix.push_back(new NumVarArray(_modele, sizeJ, _lb, _ub, _type, nom+id+milieu, fin));
    00064     }
    00065   else
    00066   for(unsigned i=0;i < sizeI; ++i)
    00067     varMatrix.push_back(new NumVarArray(_modele, sizeJ, _lb, _ub, _type));
    00068 }
    00069
    00073 NumVarMatrix::NumVarMatrix( const NumVarMatrix & nva )
    00074 :type(nva.type)
    00075 {
    00076   for(unsigned i = 0; i < nva.varMatrix.size(); ++i)
    00077     varMatrix.push_back(new NumVarArray(*(nva.varMatrix[i])));
    00078 }
    00079
    00084 NumVarMatrix::NumVarMatrix( const std::vector<NumVarArray *> & nva )
    00085 {
    00086   if( nva.size()!=0 )
    00087   {
    00088     type = nva[0]->GetType();
    00089     for(unsigned i = 0; i < nva.size(); ++i)
    00090         varMatrix.push_back(new NumVarArray(*(nva[i])));
    00091   }
    00092 }
    00093
    00094
    00095 /*----------------------------------------------------------------------------*/
    00096
    00100 NumVarMatrix & NumVarMatrix::operator= ( const NumVarMatrix & nva )
    00101 {
    00102   type = nva.type;
    00103   for(unsigned i = 0; i < nva.varMatrix.size(); ++i)
    00104     varMatrix.push_back(new NumVarArray(*nva.varMatrix[i]));
    00105   return *this;
    00106 }
    00107
    00111 unsigned NumVarMatrix::GetNbCols() const
    00112 {
    00113     if( varMatrix.size() != 0)
    00114         return varMatrix[0]->Size();
    00115     else
    00116         return 0;
    00117 }
    00118
    00122 NumVarArray NumVarMatrix::GetCol(unsigned j) const
    00123 {
    00124   if( varMatrix.size() != 0)
    00125   {
    00126     if( j < varMatrix.size())
    00127     {
    00128         std::vector<NumVar> tmp;
    00129         for(unsigned i=0; i < varMatrix.size(); ++i)
    00130             tmp.push_back( *varMatrix[i]->Get(j));
    00131         return NumVarArray(tmp);
    00132     }
    00133     else
    00134         throw std::out_of_range("NumVarArray::GetRow : index out of range");
    00135   }
    00136   else
    00137     return NumVarArray();
    00138 }
    00139
    00143 NumVarArray NumVarMatrix::GetRow(unsigned i) const
    00144 {
    00145     if( varMatrix.size())
    00146         if( i<varMatrix.size() )
    00147             return *(varMatrix[i]);
    00148         else
    00149             throw std::out_of_range("NumVarArray::GetRow : index out of range");
    00150     else
    00151         return NumVarArray();
    00152
    00153 }
    00154
    00155
    00161 NumVar  NumVarMatrix::operator() (unsigned i,unsigned j) const
    00162 {
    00163     if( i < varMatrix.size() )
    00164     {
    00165         if( j < varMatrix[i]->Size() )
    00166             return *(varMatrix[i]->Get(j));
    00167         else
    00168             throw std::out_of_range("NumVarray::operator[] : second index out of range");
    00169    }
    00170     else
    00171         throw std::out_of_range("NumVarray::operator[] : first index out of range");
    00172 }
    00173
    00180 #ifndef COMPILE_FOR_PYTHON
    00181 NumVar * NumVarMatrix::Get(unsigned i, unsigned j)
    00182 {
    00183     if( i < varMatrix.size() )
    00184     {
    00185         if( j < varMatrix[i]->Size() )
    00186             return varMatrix[i]->Get(j);
    00187         else
    00188             throw std::out_of_range("NumVarray::operator[] : second index out of range");
    00189    }
    00190     else
    00191         throw std::out_of_range("NumVarray::operator[] : first index out of range");
    00192 }
    00193 #else
    00194 NumVar&   NumVarMatrix::Get(unsigned i, unsigned j)
    00195 {
    00196     if( i < varMatrix.size() )
    00197     {
    00198         if( j < varMatrix[i]->Size() )
    00199             return *(varMatrix[i]->Get(j));
    00200         else
    00201             throw std::out_of_range("NumVarray::operator[] : second index out of range");
    00202    }
    00203     else
    00204         throw std::out_of_range("NumVarray::operator[] : first index out of range");
    00205 }
    00206 #endif
    00207
    00208 /*----------------------------------------------------------------------------*/
    00209
    00213 NumVarMatrix::~NumVarMatrix()
    00214 {
    00215   for(unsigned i = 0; i < varMatrix.size(); ++i)
    00216     delete varMatrix[i];
    00217 }
    00218
    00219
    00220 #ifdef COMPILE_FOR_PYTHON
    00221        #include "py_NumVarMatrix.cxx"
    00222 #endif
    00223
    00224
    00225 }