eoVectorParticle.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoVectorParticle.h
00005 // (c) OPAC 2007
00006 /*
00007     Contact: paradiseo-help@lists.gforge.inria.fr
00008  */
00009 //-----------------------------------------------------------------------------
00010 
00011 #ifndef _EOVECTORPARTICLE_H
00012 #define _EOVECTORPARTICLE_H
00013 
00014 #include <PO.h>
00015 
00022 template < class FitT, class PositionType, class VelocityType > class eoVectorParticle:public PO < FitT >,
00023             public std::vector <
00024             PositionType >
00025 {
00026 
00027 public:
00028 
00029     using PO < FitT >::invalidate;
00030     using
00031     std::vector <
00032     PositionType >::operator[];
00033     using
00034     std::vector <
00035     PositionType >::begin;
00036     using
00037     std::vector <
00038     PositionType >::end;
00039     using
00040     std::vector <
00041     PositionType >::size;
00042 
00043     typedef PositionType AtomType;
00044     typedef VelocityType ParticleVelocityType;
00045 
00046 
00053     eoVectorParticle (unsigned _size = 0,PositionType position = PositionType (), VelocityType velocity = VelocityType (), PositionType bestPositions = PositionType ()):PO < FitT > (),std::vector < PositionType > (_size, position), bestPositions (_size, bestPositions), velocities (_size,
00054                     velocity)
00055     {
00056     }
00057 
00058 
00059     // we can't have a Ctor from a std::vector, it would create ambiguity
00060     //  with the copy Ctor
00061     void
00062     position (const std::vector < PositionType > &_v)
00063     {
00064         if (_v.size () != size ())      // safety check
00065         {
00066             if (size ())                // NOT an initial empty std::vector
00067                 std::
00068                 cout <<
00069                 "Warning: Changing position size in eoVectorParticle assignation"
00070                 << std::endl;
00071             resize (_v.size ());
00072         }
00073 
00074         std::copy (_v.begin (), _v.end (), begin ());
00075         invalidate ();
00076     }
00077 
00081     void
00082     resize (unsigned _size)
00083     {
00084         std::vector < PositionType >::resize (_size);
00085         bestPositions.resize (_size);
00086         velocities.resize (_size);
00087     }
00088 
00089 
00093     void
00094     resizeBestPositions (unsigned _size)
00095     {
00096         bestPositions.resize (_size);
00097     }
00098 
00099 
00103     void
00104     resizeVelocities (unsigned _size)
00105     {
00106         velocities.resize (_size);
00107     }
00108 
00109 
00110     /* public attributes */
00111     std::vector < PositionType > bestPositions;
00112     std::vector < ParticleVelocityType > velocities;
00113 
00114 };
00115 
00116 #endif /*_EOVECTORPARTICLE_H*/

Generated on Fri Jun 22 10:17:02 2007 for EO-PSO by  doxygen 1.4.7