From 1f7c135934b6604c5409d4b6f34861105c0a64cb Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 9 Jul 2012 12:01:50 -0600 Subject: It works well enough to solve polynomial maxima. --- src/population.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) (limited to 'src/population.cpp') diff --git a/src/population.cpp b/src/population.cpp index 85b859e..fbd6d6c 100644 --- a/src/population.cpp +++ b/src/population.cpp @@ -1,10 +1,85 @@ #include "genetic/population.h" +#include "genetic/phenotype.h" -Genetic::Population::Population() +#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; } -- cgit v1.2.3