• Main Page
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
  • File Members

ChromosomeT_int.cpp

Go to the documentation of this file.
00001 
00042 #include <SharkDefs.h>
00043 #include <EALib/ChromosomeT.h>
00044 
00045 
00046 //===========================================================================
00047 
00048 void ChromosomeT< int >::mutateDiffGeom(double s)
00049 {
00050     double p = 1 - (s / size()) / (sqrt(1 + Shark::sqr(s / size())) + 1);
00051 
00052     for (unsigned i = size(); i--;)
00053         (*this)[ i ] += Rng::diffGeom(p);
00054 }
00055 
00056 //===========================================================================
00057 
00058 void ChromosomeT< int >::mutateDiffGeom(const std::vector< double >& s,
00059                                         bool cycle)
00060 {
00061     RANGE_CHECK(s.size() <= size())
00062 
00063     for (unsigned i = cycle ? size() : s.size(); i--;) {
00064         double t = s[ i % s.size()] / size();
00065         (*this)[ i ] += Rng::diffGeom(1 - t / (sqrt(1 + t * t) + 1));
00066     }
00067 }
00068 
00069 //===========================================================================
00070 
00071 void ChromosomeT< int >::mutateDiffGeom(const ChromosomeT< double >& s,
00072                                         bool cycle)
00073 {
00074     mutateDiffGeom(static_cast< const std::vector< double >& >(s), cycle);
00075 }
00076 
00077 //===========================================================================
00078 
00079 void ChromosomeT< int >::mutateDiffGeom(const Chromosome& s, bool cycle)
00080 {
00081     mutateDiffGeom(dynamic_cast< const std::vector< double >& >(s), cycle);
00082 }
00083 
00084 //===========================================================================
00085 
00086 /*
00087 #ifndef __NO_GENERIC_IOSTREAM
00088 
00089 void ChromosomeT< int >::writeTo( std::ostream& os ) const
00090 {
00091     os << "ChromosomeT<" << typeid( int ).name( ) << ">(" << size() << ")" << std::endl;
00092     for( unsigned i = 0; i < size( ); i++ ) {
00093         if( i ) os << '\t';
00094     os << ( *this )[ i ];
00095     }
00096     os << std::endl;
00097 }
00098 
00099 void ChromosomeT< int >::readFrom( std::istream& is )
00100 {
00101     string s;
00102   //is.getline( s );
00103     is >> s;
00104     is.get( );   // skip end of line
00105 
00106     if( is.good( ) &&
00107     s.substr( 0, 12 ) == "ChromosomeT<" &&
00108     s.find( '>' ) != string::npos &&
00109     s.substr( 12, s.find( '>' ) - 12 ) == typeid( int ).name( ) ) {
00110 
00111         resize( atoi( s.substr( s.find( '>' ) + 2 ).c_str( ) ) );
00112     for( unsigned i = 0; i < size( ); i++ )
00113         is >> ( *this )[ i ];
00114     } else
00115         is.setf( ios::failbit );
00116 }
00117 
00118 #endif // !__NO_GENERIC_IOSTREAM
00119 */
00120 
00121 //===========================================================================
00122 
  • Shark Main Page
  • Array
  • Rng
  • LinAlg
  • FileUtil
  • EALib
  • MOO-EALib
  • ReClaM
  • Fuzzy
  • Mixture
  • Tutorials
  • FAQ