00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __NUMVAR_H_
00033 #define __NUMVAR_H_
00034
00035 #include "Config.h"
00036 #include "Constant.h"
00037 #include "MuteVar.h"
00038 #include <string>
00039
00040 namespace Modelib {
00041
00042 class Model;
00043
00045
00060 class NumVar
00061 {
00062 protected:
00063 VarId varId;
00064 Model * modele;
00065 public:
00067 NumVar():varId(0),modele(0) {}
00068
00069 NumVar(Model & _modele,
00070 float _lb= 0,
00071 float _ub= Infinity,
00072 MuteVar::VarType _type = MuteVar::FLOAT,
00073 const std::string & _nom = "unknow" );
00074
00075 NumVar(Model & _modele,
00076 MuteVar::VarType _type = MuteVar::FLOAT,
00077 const std::string & _nom = "unknow" )
00078 {
00079 NumVar(_modele,0,Infinity,MuteVar::FLOAT,_nom);
00080 }
00081
00082 NumVar(const Model *,VarId);
00083
00085 NumVar(const NumVar & _n):varId( _n.varId), modele(_n.modele) {}
00086
00088 NumVar & operator= (const NumVar & _n)
00089 {
00090 modele = _n.modele;
00091 varId = _n.varId;
00092 return *this;
00093 }
00094
00095
00099 VarId GetVarId() const { return varId;}
00100
00104 Model * GetModel() const { return modele;}
00105
00106 float GetValue() const;
00107
00108 std::string GetName() const;
00109 void SetName(const std::string &);
00110
00111 float GetLowerBound() const;
00112 void SetLowerBound(float _value);
00113
00114 float GetUpperBound() const;
00115 void SetUpperBound(float _value);
00116
00117 bool IsLowerBoundStrict() const;
00118 void SetLowerBoundStrict( bool _value = true );
00119
00120 bool IsUpperBoundStrict() const;
00121 void SetUpperBoundStrict( bool _value = true );
00122
00123 MuteVar::VarType GetType() const;
00124 void SetType( MuteVar::VarType _type);
00125
00126
00127 ~NumVar() {}
00128 };
00129
00130
00137 inline bool operator==( const NumVar & n1, const NumVar & n2)
00138 {
00139 return ( n1.GetVarId()==n2.GetVarId() && n1.GetModel()==n2.GetModel() );
00140 }
00141
00142
00144 class IntVar:public NumVar
00145 {
00146 public:
00147
00148 #ifdef COMPILE_FOR_PYTHON
00149 IntVar( Model &_modele,
00150 float lowerBound = 0,
00151 float upperBound = Infinity,
00152 const std::string & nom = "unknow" )
00153 :NumVar(_modele,lowerBound,upperBound,MuteVar::INT,nom)
00154 {}
00155 #else
00156 IntVar( Model &_modele,
00157 int lowerBound = 0,
00158 int upperBound = Infinity,
00159 const std::string & nom = "unknow" )
00160 :NumVar( _modele,
00161 (lowerBound > -MaxInt? static_cast<float>(lowerBound) : -Infinity),
00162 (upperBound < MaxInt? static_cast<float>(upperBound) : Infinity),
00163 MuteVar::INT,nom)
00164 {}
00165
00166 IntVar(Model & _modele,
00167 const std::string & _nom = "unknow" )
00168 :NumVar(_modele,0,Infinity,MuteVar::INT,_nom)
00169 {}
00170
00171 #endif
00172
00173 };
00174
00176 class FloatVar:public NumVar
00177 {
00178 public:
00179 FloatVar( Model &_modele,
00180 float lowerBound = 0,
00181 float upperBound = Infinity,
00182 const std::string & nom = "unknow" )
00183 :NumVar(_modele,lowerBound,upperBound,MuteVar::FLOAT,nom)
00184 {}
00185
00186 FloatVar(Model & _modele,
00187 const std::string & _nom = "unknow" )
00188 :NumVar(_modele,0,Infinity,MuteVar::FLOAT,_nom)
00189 {}
00190 };
00191
00193 class BoolVar:public NumVar
00194 {
00195 public:
00196 BoolVar( Model &_modele,
00197 const std::string & nom = "unknow" )
00198 :NumVar(_modele,0.0f,1.0f,MuteVar::BOOL,nom)
00199 {}
00200 };
00201
00202 #ifdef COMPILE_FOR_PYTHON
00203 void export_NumVar();
00204 #endif
00205
00206 }
00207
00208 #endif