diff options
Diffstat (limited to '')
-rw-r--r-- | src/explicitsimulation.h | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/explicitsimulation.h b/src/explicitsimulation.h index ebddd62..c2aeed9 100644 --- a/src/explicitsimulation.h +++ b/src/explicitsimulation.h | |||
@@ -4,6 +4,10 @@ | |||
4 | #include "genetic/population.h" | 4 | #include "genetic/population.h" |
5 | #include "genetic/config.h" | 5 | #include "genetic/config.h" |
6 | 6 | ||
7 | #include <bu/thread.h> | ||
8 | #include <bu/mutex.h> | ||
9 | #include <bu/synchroqueue.h> | ||
10 | |||
7 | namespace Genetic | 11 | namespace Genetic |
8 | { | 12 | { |
9 | class Operator; | 13 | class Operator; |
@@ -13,7 +17,8 @@ namespace Genetic | |||
13 | { | 17 | { |
14 | public: | 18 | public: |
15 | ExplicitSimulation( Operator *pOper, FitnessFunction *pFunc, | 19 | ExplicitSimulation( Operator *pOper, FitnessFunction *pFunc, |
16 | int iPopSize, float fKeep, float fRandom, bool bKeepBest=true ); | 20 | int iThreads, int iPopSize, float fKeep, float fRandom, |
21 | bool bKeepBest=true ); | ||
17 | virtual ~ExplicitSimulation(); | 22 | virtual ~ExplicitSimulation(); |
18 | 23 | ||
19 | void timestep(); | 24 | void timestep(); |
@@ -25,11 +30,11 @@ namespace Genetic | |||
25 | 30 | ||
26 | protected: | 31 | protected: |
27 | void updateFitness(); | 32 | void updateFitness(); |
33 | void setFitness( Genetic::PhenotypeId, double dFitness ); | ||
28 | 34 | ||
29 | protected: | 35 | protected: |
30 | Population xPop; | 36 | Population xPop; |
31 | Operator *pOper; | 37 | Operator *pOper; |
32 | FitnessFunction *pFunc; | ||
33 | 38 | ||
34 | private: | 39 | private: |
35 | int iPopSize; | 40 | int iPopSize; |
@@ -42,6 +47,32 @@ namespace Genetic | |||
42 | double dMaxFitness; | 47 | double dMaxFitness; |
43 | double dTotalFitness; | 48 | double dTotalFitness; |
44 | PhenotypeId uMaxFitness; | 49 | PhenotypeId uMaxFitness; |
50 | |||
51 | Bu::Mutex mFitness; | ||
52 | typedef Bu::SynchroQueue<Phenotype *> WorkQueue; | ||
53 | WorkQueue qWork; | ||
54 | |||
55 | class Processor : public Bu::Thread | ||
56 | { | ||
57 | public: | ||
58 | Processor( ExplicitSimulation &rSim, FitnessFunction *pFunc, | ||
59 | WorkQueue &rqWork, int iId ); | ||
60 | virtual ~Processor(); | ||
61 | |||
62 | void setRunning( bool b ) { bRunning = b; } | ||
63 | |||
64 | protected: | ||
65 | virtual void run(); | ||
66 | |||
67 | ExplicitSimulation &rSim; | ||
68 | FitnessFunction *pFunc; | ||
69 | WorkQueue &rqWork; | ||
70 | int iId; | ||
71 | bool bRunning; | ||
72 | }; | ||
73 | |||
74 | typedef Bu::List<Processor *> ProcessorList; | ||
75 | ProcessorList lProcessor; | ||
45 | }; | 76 | }; |
46 | }; | 77 | }; |
47 | 78 | ||