diff options
author | Mike Buland <mike@xagasoft.com> | 2012-07-09 12:01:50 -0600 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2012-07-09 12:01:50 -0600 |
commit | 1f7c135934b6604c5409d4b6f34861105c0a64cb (patch) | |
tree | cc421e2e8620b72e202f0eddf2cd5f1478d3bc06 /src/population.cpp | |
parent | 40ee7ad5aeadeb9823e1cd6e1218a1999c608a65 (diff) | |
download | libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.tar.gz libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.tar.bz2 libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.tar.xz libgenetic-1f7c135934b6604c5409d4b6f34861105c0a64cb.zip |
It works well enough to solve polynomial maxima.
Diffstat (limited to 'src/population.cpp')
-rw-r--r-- | src/population.cpp | 77 |
1 files changed, 76 insertions, 1 deletions
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 @@ | |||
1 | #include "genetic/population.h" | 1 | #include "genetic/population.h" |
2 | #include "genetic/phenotype.h" | ||
2 | 3 | ||
3 | Genetic::Population::Population() | 4 | #include <bu/mutexlocker.h> |
5 | |||
6 | Genetic::Population::Population() : | ||
7 | uNextId( 0 ), | ||
8 | uTime( 0 ) | ||
4 | { | 9 | { |
5 | } | 10 | } |
6 | 11 | ||
7 | Genetic::Population::~Population() | 12 | Genetic::Population::~Population() |
8 | { | 13 | { |
14 | for( PhenotypeHash::iterator i = hPhenotype.begin(); i; i++ ) | ||
15 | delete *i; | ||
16 | } | ||
17 | |||
18 | Genetic::PhenotypeId Genetic::Population::addPhenotype( | ||
19 | Genetic::Phenotype *pNew ) | ||
20 | { | ||
21 | Bu::MutexLocker ml( mGeneral ); | ||
22 | if( !pNew->isActive() ) | ||
23 | pNew->setCreated( uTime, uNextId++ ); | ||
24 | |||
25 | hPhenotype.insert( pNew->getId(), pNew ); | ||
26 | return pNew->getId(); | ||
27 | } | ||
28 | |||
29 | bool Genetic::Population::hasProperty( Genetic::PhenotypeId id, | ||
30 | const Bu::String &sKey ) const | ||
31 | { | ||
32 | Bu::MutexLocker ml( mGeneral ); | ||
33 | return hPhenotype.get( id )->hasProperty( sKey ); | ||
34 | } | ||
35 | |||
36 | Bu::Variant Genetic::Population::getProperty( | ||
37 | Genetic::PhenotypeId id, const Bu::String &sKey ) const | ||
38 | { | ||
39 | Bu::MutexLocker ml( mGeneral ); | ||
40 | return hPhenotype.get( id )->getProperty( sKey ); | ||
41 | } | ||
42 | |||
43 | void Genetic::Population::setProperty( Genetic::PhenotypeId id, | ||
44 | const Bu::String &sKey, Bu::Variant vValue ) | ||
45 | { | ||
46 | Bu::MutexLocker ml( mGeneral ); | ||
47 | |||
48 | hPhenotype.get( id )->setProperty( sKey, vValue ); | ||
49 | } | ||
50 | |||
51 | void Genetic::Population::delPhenotype( PhenotypeId id ) | ||
52 | { | ||
53 | Bu::MutexLocker ml( mGeneral ); | ||
54 | delete hPhenotype.get( id ); | ||
55 | hPhenotype.erase( id ); | ||
56 | } | ||
57 | |||
58 | Genetic::Phenotype *Genetic::Population::takePhenotype( PhenotypeId id ) | ||
59 | { | ||
60 | Bu::MutexLocker ml( mGeneral ); | ||
61 | Phenotype *pRet = hPhenotype.get( id ); | ||
62 | hPhenotype.erase( id ); | ||
63 | return pRet; | ||
64 | } | ||
65 | |||
66 | void Genetic::Population::clear() | ||
67 | { | ||
68 | Bu::MutexLocker ml( mGeneral ); | ||
69 | for( PhenotypeHash::iterator i = hPhenotype.begin(); i; i++ ) | ||
70 | delete *i; | ||
71 | hPhenotype.clear(); | ||
72 | } | ||
73 | |||
74 | Genetic::PhenotypeId Genetic::Population::timestep() | ||
75 | { | ||
76 | Bu::MutexLocker ml( mGeneral ); | ||
77 | return (++uTime); | ||
78 | } | ||
79 | |||
80 | Genetic::PhenotypeId Genetic::Population::time() const | ||
81 | { | ||
82 | Bu::MutexLocker ml( mGeneral ); | ||
83 | return uTime; | ||
9 | } | 84 | } |
10 | 85 | ||