Nemo  2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
statservices.h
Go to the documentation of this file.
1
30#ifndef STATSERVICES_H
31#define STATSERVICES_H
32
33#include <list>
34#include <string>
35#include <fstream>
36#include <map>
37#include <vector>
38#include <assert.h>
39#include <cstring> //for memcpy
40#include "service.h"
41#include "statrecorder.h"
42
43using namespace std;
44
45class Metapop;
46
47class StatHandlerBase;
48
50class StatServices : public Service {
51
52private:
53
55
57 list< StatHandlerBase* > _statHandlers;
58
60 list< StatRecBase *> _statRecorders;
61
63 unsigned int _numRecorders;
64
66 vector< vector< double*> > _statValues;
67
70
72 string _statArg;
73
75 unsigned int _occurrence;
76
78 list< unsigned int > _occurrences;
79
83 list< unsigned int >::const_iterator _current_occurrence;
84
85 //output format:
86 unsigned int _width, _precision;
87
88 unsigned char _separator;
89
91
92public:
93
94 typedef list< StatHandlerBase* >::const_iterator stat_it;
95
96 typedef list< StatRecBase* >::const_iterator rec_it;
97
100 { }
101
103
104 virtual bool init ( );
105
107
108 void set_pop_ptr (Metapop* pop) {_popPtr=pop;}
109
110 void set (string& str, unsigned int occ)
111 {_statArg = str; _occurrence = occ;}
112
113 void setStatOptions (string& str) {_statArg = str;}
114
115 string& getStatArg ( ) {return _statArg;}
116
117 //OCURRENCE
118 unsigned int getOccurrence ( ) {return _occurrence;}
119
120 void setOcccurrence (unsigned int value) {_occurrence = value;}
124 void setOccurrences (map<unsigned int, unsigned int> timeTable);
126 unsigned int getNumOccurrences( ) {return _occurrences.size();}
127
131 unsigned int getNumOccurrences(unsigned int replicate)
132 {
133 return _statValues[replicate-1].size();
134 }
136 unsigned int getCurrentOccurrence () {return *_current_occurrence;}
139
140 //PRINT
141 void printStatHeaders (ofstream& FH);
145
149 void printStatValue (ofstream& FH, unsigned int repl_idx);
150
151 void printStatAverage (ofstream& FH);
152
154
155 void setFieldWidth (unsigned int val) {_width = val;}
156
157 void setFieldPrecision (unsigned int val) {_precision = val;}
158
159 void setFieldSeparator (unsigned char c) {_separator = c;}
160
162
163 //STAT RECORDS
164 list<StatRecBase*> getAllStats ( );
165
166 unsigned int getNumStats ( ) {return _statRecorders.size();}
167
168 stat_it getFirst () {return _statHandlers.begin();}
169
170 stat_it getLast () {return _statHandlers.end();}
171
172 vector<double*>* getReplicateStatRecords (unsigned int replicate)
173 {
174 return &_statValues[ replicate-1 ];
175 }
176
177 double* getGenerationStatValues (unsigned int replicate, unsigned int occurence) const
178 {
179 assert(occurence < _occurrences.size());
180 return _statValues[ replicate-1 ][ occurence ];
181 }
182
183 void copyGenerationStatValues (unsigned int replicate, unsigned int occurence, double* values, unsigned int size)
184 {
185 assert( _statValues[ replicate-1 ].size() < _occurrences.size() );
186
187 assert( size == _numRecorders+2);
188
189 double* new_record = new double[size];
190
191 memcpy(new_record, values, size*sizeof(double));
192
193 _statValues[ replicate-1 ].push_back(new_record);
194 }
198 void recordStats (unsigned int gen);
199
200 virtual void notify ();
205 virtual void load ( SimComponent* sc );
210 virtual void attach ( Handler* H);
214 virtual void reset ( );
215
217 void reset_stat_table();
218};
219#endif //STATSERVICES_H
220
Service handler (an observer).
Definition: handler.h:36
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:80
Interface for the simulation services (files and stats).
Definition: service.h:43
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:45
Base class of the StatHandler class, implements the Handler interface.
Definition: stathandler.h:48
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
virtual void load(SimComponent *sc)
tell the SimComponent to load its stat handlers
Definition: statservices.cc:170
void setFieldPrecision(unsigned int val)
Definition: statservices.h:157
void setDefaultOutputFormat()
Definition: statservices.h:161
void setOcccurrence(unsigned int value)
Definition: statservices.h:120
Metapop * _popPtr
Definition: statservices.h:54
void cancelPrintAverages()
Definition: statservices.h:143
unsigned int getNumOccurrences()
Returns the maximum number of generation records per replicate.
Definition: statservices.h:126
void resetCurrentOccurrence()
Resets the occurrence iterator to the beginning of the list of generation occurrences.
Definition: statservices.h:138
unsigned char _separator
Definition: statservices.h:88
list< unsignedint >::const_iterator _current_occurrence
Iterator pointing to the current generation to record.
Definition: statservices.h:83
virtual bool init()
Definition: statservices.cc:47
void set(string &str, unsigned int occ)
Definition: statservices.h:110
unsigned int getNumOccurrences(unsigned int replicate)
Returns the number of generation records present in the stat table for a replicate.
Definition: statservices.h:131
unsigned int _occurrence
Deprecated.
Definition: statservices.h:75
list< unsigned int > _occurrences
List of all generations to record.
Definition: statservices.h:78
unsigned int _width
Definition: statservices.h:86
vector< double * > * getReplicateStatRecords(unsigned int replicate)
Definition: statservices.h:172
vector< vector< double * > > _statValues
Table containing all recorded stats, replicate x generation x (num recorders + 2) .
Definition: statservices.h:66
StatServices()
Definition: statservices.h:98
string _statArg
The string argument of the 'stat' input option.
Definition: statservices.h:72
void copyGenerationStatValues(unsigned int replicate, unsigned int occurence, double *values, unsigned int size)
Definition: statservices.h:183
void reset_stat_table()
Deletes the stat tables.
Definition: statservices.cc:231
void doPrintAverages()
Definition: statservices.h:142
void set_pop_ptr(Metapop *pop)
Definition: statservices.h:108
double * getGenerationStatValues(unsigned int replicate, unsigned int occurence) const
Definition: statservices.h:177
unsigned int getCurrentOccurrence()
Returns the last generation recorded for current replicate.
Definition: statservices.h:136
void setStatOptions(string &str)
Definition: statservices.h:113
unsigned int _precision
Definition: statservices.h:86
unsigned int _numRecorders
Number of stats to record.
Definition: statservices.h:63
void setFieldSeparator(unsigned char c)
Definition: statservices.h:159
list< StatRecBase * > _statRecorders
List of stat recorders.
Definition: statservices.h:60
Metapop * get_pop_ptr()
Definition: statservices.h:106
void recordStats(unsigned int gen)
record stat values in stat table by calling all stat recorders.
Definition: statservices.cc:246
virtual void notify()
Definition: statservices.cc:188
virtual void reset()
clear the list of StatHandler
Definition: statservices.cc:208
virtual void attach(Handler *H)
attach the StatHandler to the current list (_statHandlers) of the StatServices
Definition: statservices.cc:177
void setFieldWidth(unsigned int val)
Definition: statservices.h:155
stat_it getFirst()
Definition: statservices.h:168
void setOccurrences(map< unsigned int, unsigned int > timeTable)
Sets the list of generation for which statistics must be recorded during a run.
Definition: statservices.cc:121
void printStatHeaders(ofstream &FH)
Definition: statservices.cc:271
unsigned int getOccurrence()
Definition: statservices.h:118
string & getStatArg()
Definition: statservices.h:115
bool getPrintAveragesOpt()
Definition: statservices.h:144
virtual ~StatServices()
Definition: statservices.h:102
list< StatHandlerBase * > _statHandlers
List of stat handlers declared by currently active simulation components.
Definition: statservices.h:57
void setCompactOutputFormat()
Definition: statservices.h:153
list< StatRecBase * >::const_iterator rec_it
Definition: statservices.h:96
void printStatAverage(ofstream &FH)
Definition: statservices.cc:328
unsigned int getNumStats()
Definition: statservices.h:166
list< StatHandlerBase * >::const_iterator stat_it
Definition: statservices.h:94
void printStatValue(ofstream &FH, unsigned int repl_idx)
Prints the stat values to the '.txt' output file.
Definition: statservices.cc:280
bool _printAverages
Definition: statservices.h:90
stat_it getLast()
Definition: statservices.h:170
list< StatRecBase * > getAllStats()
Definition: statservices.cc:389
double * _currentStatValues
Pointer to the last recorded stats.
Definition: statservices.h:69

Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR