00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef EOVELOCITYINIT_H
00012 #define EOVELOCITYINIT_H
00013
00014
00015 #include <algorithm>
00016
00017 #include <eoOp.h>
00018 #include <eoSTLFunctor.h>
00019 #include <utils/eoRndGenerators.h>
00020
00022 template < class POT > class eoVelocityInit:public eoInit < POT >
00023 {
00024 public:
00025 virtual std::string className (void) const
00026 {
00027 return "eoVelocityInit";
00028 }
00029 };
00030
00031
00035 template < class POT > class eoVelocityInitGenerator:public eoF < POT >
00036 {
00037 public:
00038
00040 eoVelocityInitGenerator (eoVelocityInit < POT > &_init):init (_init)
00041 {
00042 }
00043
00044 virtual POT operator () ()
00045 {
00046 POT p;
00047 init (p);
00048 return (p);
00049 }
00050 private:
00051 eoVelocityInit < POT > &init;
00052 };
00053
00057 template < class POT > class eoVelocityInitFixedLength:public eoVelocityInit <
00058 POT >
00059 {
00060 public:
00061
00062 typedef typename POT::ParticleVelocityType VelocityType;
00063
00064 eoVelocityInitFixedLength (unsigned _combien,
00065 eoRndGenerator < VelocityType >
00066 &_generator):combien (_combien),
00067 generator (_generator)
00068 {
00069 }
00070
00071 virtual void operator () (POT & chrom)
00072 {
00073 chrom.resize (combien);
00074 std::generate (chrom.velocities.begin (), chrom.velocities.end (),
00075 generator);
00076 }
00077
00078 private:
00079 unsigned combien;
00081 eoSTLF < VelocityType > generator;
00082 };
00083
00087 template < class POT > class eoVelocityInitVariableLength:public eoVelocityInit <
00088 POT >
00089 {
00090 public:
00091 typedef typename POT::ParticleVelocityType VelocityType;
00092
00094 eoVelocityInitVariableLength (unsigned _minSize, unsigned _maxSize,
00095 eoVelocityInit < VelocityType >
00096 &_init):offset (_minSize),
00097 extent (_maxSize - _minSize), init (_init)
00098 {
00099 if (_minSize >= _maxSize)
00100 throw std::
00101 logic_error
00102 ("eoVelocityInitVariableLength: minSize larger or equal to maxSize");
00103 }
00104
00105
00106 virtual void operator () (POT & _chrom)
00107 {
00108 _chrom.resizeVelocities (offset + rng.random (extent));
00109 typename std::vector < VelocityType >::iterator it;
00110 for (it = _chrom.velocities.begin (); it < _chrom.velocities.end (); it++)
00111 init (*it);
00112 }
00113
00114
00115 eoInit < VelocityType > &atomInit ()
00116 {
00117 return init;
00118 }
00119
00120 private:
00121 unsigned offset;
00122 unsigned extent;
00123 eoVelocityInit < VelocityType > &init;
00124 };
00125
00126 #endif