EvolvingObjects
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     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     Contact: thomas.legrand@lifl.fr
00022  */
00023 //-----------------------------------------------------------------------------
00024 
00025 #ifndef _EOVECTORPARTICLE_H
00026 #define _EOVECTORPARTICLE_H
00027 
00028 #include <PO.h>
00029 
00030 
00042 template < class FitT, class PositionType, class VelocityType > class eoVectorParticle:public PO < FitT >,
00043             public std::vector <
00044             PositionType >
00045 {
00046 
00047 public:
00048 
00049     using PO < FitT >::invalidate;
00050     using
00051     std::vector <
00052     PositionType >::operator[];
00053     using
00054     std::vector <
00055     PositionType >::begin;
00056     using
00057     std::vector <
00058     PositionType >::end;
00059     using
00060     std::vector <
00061     PositionType >::size;
00062 
00063     typedef PositionType AtomType;
00064     typedef VelocityType ParticleVelocityType;
00065 
00066 
00073     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,
00074                     _velocity)
00075     {
00076     }
00077 
00078 
00079     // we can't have a Ctor from a std::vector, it would create ambiguity
00080     //  with the copy Ctor
00081     void
00082     position (const std::vector < PositionType > &_v)
00083     {
00084         if (_v.size () != size ())      // safety check
00085         {
00086             if (size ())                // NOT an initial empty std::vector
00087                 eo::log << eo::warnings <<
00088                 "Warning: Changing position size in eoVectorParticle assignation"
00089                 << std::endl;
00090             resize (_v.size ());
00091         }
00092 
00093         std::copy (_v.begin (), _v.end (), begin ());
00094         invalidate ();
00095     }
00096 
00100     void
00101     resize (unsigned _size)
00102     {
00103         std::vector < PositionType >::resize (_size);
00104         bestPositions.resize (_size);
00105         velocities.resize (_size);
00106     }
00107 
00108 
00112     void
00113     resizeBestPositions (unsigned _size)
00114     {
00115         bestPositions.resize (_size);
00116     }
00117 
00118 
00122     void
00123     resizeVelocities (unsigned _size)
00124     {
00125         velocities.resize (_size);
00126     }
00127 
00129     bool operator<(const eoVectorParticle<FitT, PositionType, VelocityType >& _eo) const
00130         {
00131                 if (_eo.best() > this->best())
00132                         return true;
00133                 else
00134                         return false;
00135         }
00136 
00140     virtual void printOn(std::ostream& os) const
00141     {
00142         PO<FitT>::printOn(os);
00143         os << ' ';
00144         os << size() << ' ';
00145         std::copy(bestPositions.begin(), bestPositions.end(), std::ostream_iterator<AtomType>(os, " "));
00146      }
00147 
00148     /* public attributes */
00149     std::vector < PositionType > bestPositions;
00150     std::vector < ParticleVelocityType > velocities;
00151 
00152 };
00153 
00154 #endif /*_EOVECTORPARTICLE_H*/
00155 
 All Classes Namespaces Files Functions Variables Typedefs Friends