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 #ifndef EOVELOCITYINIT_H
00026 #define EOVELOCITYINIT_H
00027
00028
00029 #include <algorithm>
00030
00031 #include <eoOp.h>
00032 #include <eoSTLFunctor.h>
00033 #include <utils/eoRndGenerators.h>
00034
00036 template < class POT > class eoVelocityInit:public eoInit < POT >
00037 {
00038 public:
00039 virtual std::string className (void) const
00040 {
00041 return "eoVelocityInit";
00042 }
00043 };
00044
00045
00049 template < class POT > class eoVelocityInitGenerator:public eoF < POT >
00050 {
00051 public:
00052
00054 eoVelocityInitGenerator (eoVelocityInit < POT > &_init):init (_init){}
00055
00056 virtual POT operator () ()
00057 {
00058 POT p;
00059 init (p);
00060 return (p);
00061 }
00062
00063 private:
00064 eoVelocityInit < POT > &init;
00065 };
00066
00070 template < class POT > class eoVelocityInitFixedLength:public eoVelocityInit <
00071 POT >
00072 {
00073 public:
00074
00075 typedef typename POT::ParticleVelocityType VelocityType;
00076
00077 eoVelocityInitFixedLength (unsigned _combien,
00078 eoRndGenerator < VelocityType >
00079 &_generator):combien (_combien),
00080 generator (_generator)
00081 {
00082 }
00083
00084 virtual void operator () (POT & chrom)
00085 {
00086 chrom.resize (combien);
00087 std::generate (chrom.velocities.begin (), chrom.velocities.end (),
00088 generator);
00089 }
00090
00091 private:
00092 unsigned combien;
00094 eoSTLF < VelocityType > generator;
00095 };
00096
00100 template < class POT > class eoVelocityInitVariableLength:public eoVelocityInit <
00101 POT >
00102 {
00103 public:
00104 typedef typename POT::ParticleVelocityType VelocityType;
00105
00107 eoVelocityInitVariableLength (unsigned _minSize, unsigned _maxSize,
00108 eoVelocityInit < VelocityType >
00109 &_init):offset (_minSize),
00110 extent (_maxSize - _minSize), init (_init)
00111 {
00112 if (_minSize >= _maxSize)
00113 throw std::
00114 logic_error
00115 ("eoVelocityInitVariableLength: minSize larger or equal to maxSize");
00116 }
00117
00118
00119 virtual void operator () (POT & _chrom)
00120 {
00121 _chrom.resizeVelocities (offset + rng.random (extent));
00122 typename std::vector < VelocityType >::iterator it;
00123 for (it = _chrom.velocities.begin (); it < _chrom.velocities.end (); it++)
00124 init (*it);
00125 }
00126
00127
00128 eoInit < VelocityType > &atomInit ()
00129 {
00130 return init;
00131 }
00132
00133 private:
00134 unsigned offset;
00135 unsigned extent;
00136 eoVelocityInit < VelocityType > &init;
00137 };
00138
00139 #endif