#include "genetic/population.h" #include "genetic/phenotype.h" #include Genetic::Population::Population() : uNextId( 0 ), uTime( 0 ) { } Genetic::Population::~Population() { for( PhenotypeHash::iterator i = hPhenotype.begin(); i; i++ ) delete *i; } Genetic::PhenotypeId Genetic::Population::addPhenotype( Genetic::Phenotype *pNew ) { Bu::MutexLocker ml( mGeneral ); if( !pNew->isActive() ) pNew->setCreated( uTime, uNextId++ ); hPhenotype.insert( pNew->getId(), pNew ); return pNew->getId(); } bool Genetic::Population::hasProperty( Genetic::PhenotypeId id, const Bu::String &sKey ) const { Bu::MutexLocker ml( mGeneral ); return hPhenotype.get( id )->hasProperty( sKey ); } Bu::Variant Genetic::Population::getProperty( Genetic::PhenotypeId id, const Bu::String &sKey ) const { Bu::MutexLocker ml( mGeneral ); return hPhenotype.get( id )->getProperty( sKey ); } void Genetic::Population::setProperty( Genetic::PhenotypeId id, const Bu::String &sKey, Bu::Variant vValue ) { Bu::MutexLocker ml( mGeneral ); hPhenotype.get( id )->setProperty( sKey, vValue ); } void Genetic::Population::delPhenotype( PhenotypeId id ) { Bu::MutexLocker ml( mGeneral ); delete hPhenotype.get( id ); hPhenotype.erase( id ); } Genetic::Phenotype *Genetic::Population::takePhenotype( PhenotypeId id ) { Bu::MutexLocker ml( mGeneral ); Phenotype *pRet = hPhenotype.get( id ); hPhenotype.erase( id ); return pRet; } void Genetic::Population::clear() { Bu::MutexLocker ml( mGeneral ); for( PhenotypeHash::iterator i = hPhenotype.begin(); i; i++ ) delete *i; hPhenotype.clear(); } Genetic::PhenotypeId Genetic::Population::timestep() { Bu::MutexLocker ml( mGeneral ); return (++uTime); } Genetic::PhenotypeId Genetic::Population::time() const { Bu::MutexLocker ml( mGeneral ); return uTime; }