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

NumVar.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 "NumVar.h"
00033 #include "Constant.h"
00034 #include "Model.h"
00035 #include <iostream>
00036 
00037 namespace Modelib {
00038 
00039 using namespace std;
00040 
00041 
00042 /*-----------------------------------------------------------------------------------------------------------*/
00058 NumVar::NumVar(Model & _modele,
00059        float _lb,
00060        float _ub,
00061        MuteVar::VarType _type,
00062        const std::string & _nom )
00063 :varId( _modele.AddVar( MuteVar( _type, 0, _lb, _ub),_nom ) ), modele(&_modele)
00064 {}
00065 
00071 NumVar::NumVar( const Model * _modele,VarId _varId)
00072 :varId(0), modele(0)
00073 {
00074    //si le modèle existe et si la variable est definie
00075    if( _modele && _modele->GetName( _varId ) != defaultGetName )
00076    {
00077       modele = const_cast<Model *>(_modele);
00078       //le modele est constant il faut donc le transtyper
00079       varId = _varId;
00080    }
00081    else
00082      if(_modele)
00083        cerr << "Warning in NumVar::NumVar : undefined variable" << endl;
00084      else
00085        cerr << "Warning in NumVar::NumVar : undefined model" << endl;
00086 
00087 }
00088 
00089 /*-----------------------------------------------------------------------------------------------------------*/
00095 float NumVar::GetValue() const
00096 {
00097    //si le modele existe
00098    if(modele)
00099      return modele->GetMuteVar(varId).GetValue();
00100      //on recupere l'instance de MuteVar puis sa valeur
00101    else
00102    {
00103      cerr << "Warning in NumVar::GetValue : undefined model" << endl;
00104      return 0;
00105      //on retourne 0.
00106    }
00107 }
00108 
00114 std::string NumVar::GetName() const
00115 {
00116    //si le modele existe
00117     if(modele)
00118     return modele->GetName(varId);
00119      //on recupere le nom de la variable dans Model::unkownMap
00120   else
00121     cerr << "Warning in NumVar::GetName : undefined model" << endl;
00122   return noModel;
00123 }
00124 
00130 void NumVar::SetName(const std::string & name)
00131 {
00132   //si le modele existe
00133     if(modele)
00134      modele->SetName(varId, name );
00135      //on redefinit le nom de la variable dans Model::unkownMap
00136   else
00137     cerr << "Warning in NumVar::GetName : undefined model" << endl;
00138 }
00139 
00140 /*-----------------------------------------------------------------------------------------------------------*/
00146 float NumVar::GetLowerBound() const
00147 {
00148     if(!modele)
00149     cerr << "Warning in NumVar::GetLowerBound : undefined model" << endl;
00150   return (modele?modele->GetMuteVarLB(varId):0);
00151 }
00152 
00158 void NumVar::SetLowerBound(float _value)
00159 {
00160     if(!modele)
00161     cerr << "Warning in NumVar::SetLowerBound : undefined model" << endl;
00162     if(modele) modele->SetMuteVarLB(varId,_value);
00163 }
00164 
00165 /*-----------------------------------------------------------------------------------------------------------*/
00171 float NumVar::GetUpperBound() const
00172 {
00173     if(!modele)
00174     cerr << "Warning in NumVar::GetUpperBound : undefined model" << endl;
00175     return (modele?modele->GetMuteVarUB(varId):0);
00176 }
00177 
00183 void NumVar::SetUpperBound(float _value)
00184 {
00185     if(!modele)
00186     cerr << "Warning in NumVar::SetUpperBound : undefined model" << endl;
00187     if(modele) modele->SetMuteVarUB(varId,_value);
00188 }
00189 
00190 /*-----------------------------------------------------------------------------------------------------------*/
00196 bool NumVar::IsLowerBoundStrict() const
00197 {
00198     if(!modele)
00199     cerr << "Warning in NumVar::IsLowerBoundStrict : undefined model" << endl;
00200   return (modele?modele->GetMuteVar(varId).IsLowerBoundStrict():false);
00201 }
00202 
00208 void NumVar::SetLowerBoundStrict( bool _value )
00209 {
00210     if(!modele)
00211     cerr << "Warning in NumVar::SetLowerBoundStrict : undefined model" << endl;
00212     if(modele) modele->SetMuteVarLBStrict(varId,_value);
00213 }
00214 
00215 /*-----------------------------------------------------------------------------------------------------------*/
00221 bool NumVar::IsUpperBoundStrict() const
00222 {
00223     if(!modele)
00224     cerr << "Warning in NumVar::IsUpperBoundStrict : undefined model" << endl;
00225   return (modele?modele->GetMuteVar(varId).IsUpperBoundStrict():false);
00226 }
00227 
00233 void NumVar::SetUpperBoundStrict( bool _value )
00234 {
00235     if(!modele)
00236     cerr << "Warning in NumVar::SetUpperBoundStrict : undefined model" << endl;
00237     if(modele) modele->SetMuteVarUBStrict(varId,_value);
00238 }
00239 
00240 /*-----------------------------------------------------------------------------------------------------------*/
00247 MuteVar::VarType NumVar::GetType() const
00248 {
00249     if(!modele)
00250     cerr << "Warning in NumVar::GetType : undefined model" << endl;
00251   return (modele?modele->GetMuteVar(varId).GetType():MuteVar::FLOAT);
00252 }
00253 
00259 void NumVar::SetType( MuteVar::VarType _type)
00260 {
00261     if(!modele)
00262     cerr << "Warning in NumVar::SetType : undefined model" << endl;
00263     if(modele) modele->SetType(varId,_type);
00264 }
00265 
00266 
00267 #ifdef COMPILE_FOR_PYTHON
00268        #include "py_NumVar.cxx"
00269 #endif
00270 
00271 
00272 }

Généré le Sun Oct 2 19:13:12 2005 pour Modelib par  doxygen 1.4.4