1 /* 2 ================================================================================ 3 PROJECT: 4 5 John Eddy's Genetic Algorithms (JEGA) 6 7 CONTENTS: 8 9 Implementation of class DesignVariableInfo. 10 11 NOTES: 12 13 See notes of DesignVariableInfo.hpp. 14 15 PROGRAMMERS: 16 17 John Eddy (jpeddy@sandia.gov) (JE) 18 19 ORGANIZATION: 20 21 Sandia National Laboratories 22 23 COPYRIGHT: 24 25 See the LICENSE file in the top level JEGA directory. 26 27 VERSION: 28 29 1.0.0 30 31 CHANGES: 32 33 Tue Jun 03 07:34:36 2003 - Original Version (JE) 34 35 ================================================================================ 36 */ 37 38 39 40 41 /* 42 ================================================================================ 43 Document This File 44 ================================================================================ 45 */ 46 /** \file 47 * \brief Contains the implementation of the DesignVariableInfo class. 48 */ 49 50 51 52 53 /* 54 ================================================================================ 55 Includes 56 ================================================================================ 57 */ 58 // JEGAConfig.hpp should be the first include in all JEGA files. 59 #include <../Utilities/include/JEGAConfig.hpp> 60 61 #include <../Utilities/include/Design.hpp> 62 #include <../Utilities/include/Logging.hpp> 63 #include <../Utilities/include/DesignVariableInfo.hpp> 64 #include <../Utilities/include/RealDesignVariableType.hpp> 65 66 //#include <boost/math/special_functions/round.hpp> 67 /* 68 ================================================================================ 69 Namespace Using Directives 70 ================================================================================ 71 */ 72 using namespace std; 73 //using namespace JEGA::Logging; 74 75 76 77 78 79 80 81 /* 82 ================================================================================ 83 Begin Namespace 84 ================================================================================ 85 */ 86 namespace JEGA { 87 namespace Utilities { 88 89 90 91 92 93 94 95 /* 96 ================================================================================ 97 Static Member Data Definitions 98 ================================================================================ 99 */ 100 101 102 103 104 105 106 107 108 /* 109 ================================================================================ 110 Mutators 111 ================================================================================ 112 */ 113 void SetType(DesignVariableTypeBase * type)114DesignVariableInfo::SetType( 115 DesignVariableTypeBase* type 116 ) 117 { 118 EDDY_FUNC_DEBUGSCOPE 119 delete this->_type; 120 this->_type = (type == 0x0) ? new RealDesignVariableType(*this) : type; 121 } 122 123 124 125 126 127 128 129 /* 130 ================================================================================ 131 Accessors 132 ================================================================================ 133 */ 134 135 136 137 138 139 140 141 142 /* 143 ================================================================================ 144 Public Methods 145 ================================================================================ 146 */ 147 bool AddDiscreteValues(const JEGA::DoubleVector & values)148DesignVariableInfo::AddDiscreteValues( 149 const JEGA::DoubleVector& values 150 ) 151 { 152 EDDY_FUNC_DEBUGSCOPE 153 bool ret = true; 154 155 for(JEGA::DoubleVector::const_iterator it(values.begin()); 156 it!=values.end(); ++it) ret &= AddDiscreteValue(*it); 157 158 return ret; 159 } 160 161 162 double GetRepBoundViolation(double rep) const163DesignVariableInfo::GetRepBoundViolation( 164 double rep 165 ) const 166 { 167 EDDY_FUNC_DEBUGSCOPE 168 return (rep < this->GetMinRep()) ? this->GetMinRep() - rep : 169 (rep > this->GetMaxRep()) ? rep - this->GetMaxRep() : 170 0.0; 171 } 172 173 double GetValueBoundViolation(double val) const174DesignVariableInfo::GetValueBoundViolation( 175 double val 176 ) const 177 { 178 EDDY_FUNC_DEBUGSCOPE 179 return (val < this->GetMinValue()) ? this->GetMinValue() - val : 180 (val > this->GetMaxValue()) ? val - this->GetMaxValue() : 181 0.0; 182 } 183 184 const DesignVariableInfo& operator =(const DesignVariableInfo & right)185DesignVariableInfo::operator = ( 186 const DesignVariableInfo &right 187 ) 188 { 189 EDDY_FUNC_DEBUGSCOPE 190 EDDY_ASSERT(&this->GetDesignTarget() == &right.GetDesignTarget()); 191 192 if(this == &right) return *this; 193 SetType(right.GetType().Clone(*this)); 194 return *this; 195 } 196 197 double GetNearestValidValue(double value) const198DesignVariableInfo::GetNearestValidValue( 199 double value 200 ) const 201 { 202 EDDY_FUNC_DEBUGSCOPE 203 return this->GetType().GetNearestValidValue(value); 204 } 205 206 var_rep_t GetNearestValidRep(var_rep_t rep) const207DesignVariableInfo::GetNearestValidRep( 208 var_rep_t rep 209 ) const 210 { 211 EDDY_FUNC_DEBUGSCOPE 212 return this->GetType().GetNearestValidRep(rep); 213 } 214 215 double WhichValue(const Design & des) const216DesignVariableInfo::WhichValue( 217 const Design& des 218 ) const 219 { 220 EDDY_FUNC_DEBUGSCOPE 221 return des.GetVariableValue(this->GetNumber()); 222 } 223 224 var_rep_t WhichRep(const Design & des) const225DesignVariableInfo::WhichRep( 226 const Design& des 227 ) const 228 { 229 EDDY_FUNC_DEBUGSCOPE 230 return des.GetVariableRep(this->GetNumber()); 231 } 232 233 234 235 /* 236 ================================================================================ 237 Subclass Visible Methods 238 ================================================================================ 239 */ 240 241 242 243 244 245 246 247 248 /* 249 ================================================================================ 250 Subclass Overridable Methods 251 ================================================================================ 252 */ 253 254 255 256 257 258 259 260 261 /* 262 ================================================================================ 263 Private Methods 264 ================================================================================ 265 */ 266 267 268 269 270 271 272 273 274 /* 275 ================================================================================ 276 Structors 277 ================================================================================ 278 */ DesignVariableInfo(DesignTarget & target)279DesignVariableInfo::DesignVariableInfo( 280 DesignTarget& target 281 ) : 282 InfoBase(target), 283 _type(0x0) 284 { 285 EDDY_FUNC_DEBUGSCOPE 286 this->_type = new RealDesignVariableType(*this); 287 } 288 DesignVariableInfo(const DesignVariableInfo & copy,DesignTarget & target)289DesignVariableInfo::DesignVariableInfo( 290 const DesignVariableInfo& copy, 291 DesignTarget& target 292 ) : 293 InfoBase(copy, target), 294 _type(0x0) 295 { 296 EDDY_FUNC_DEBUGSCOPE 297 this->_type = copy.GetType().Clone(*this); 298 299 } // DesignVariableInfo::DesignVariableInfo 300 DesignVariableInfo(const DesignVariableInfo & copy)301DesignVariableInfo::DesignVariableInfo( 302 const DesignVariableInfo& copy 303 ) : 304 InfoBase(copy), 305 _type(0x0) 306 { 307 EDDY_FUNC_DEBUGSCOPE 308 this->_type = copy.GetType().Clone(*this); 309 } 310 ~DesignVariableInfo()311DesignVariableInfo::~DesignVariableInfo( 312 ) 313 { 314 EDDY_FUNC_DEBUGSCOPE 315 delete this->_type; 316 } 317 318 319 320 321 322 323 324 /* 325 ================================================================================ 326 End Namespace 327 ================================================================================ 328 */ 329 } // namespace Utilities 330 } // namespace JEGA 331