Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/ecosystem.h
[mareframe] / trunk / gadget / ecosystem.h Repository:
ViewVC logotype

Annotation of /trunk/gadget/ecosystem.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (view) (download)

1 : agomez 1 #ifndef ecosystem_h
2 :     #define ecosystem_h
3 :    
4 :     #include "areatime.h"
5 :     #include "keeper.h"
6 :     #include "errorhandler.h"
7 :     #include "tagptrvector.h"
8 :     #include "baseclassptrvector.h"
9 :     #include "stockptrvector.h"
10 :     #include "fleetptrvector.h"
11 :     #include "otherfoodptrvector.h"
12 :     #include "printerptrvector.h"
13 :     #include "likelihoodptrvector.h"
14 :     #include "optinfoptrvector.h"
15 :     #include "stock.h"
16 :     #include "fleet.h"
17 :     #include "otherfood.h"
18 :     #include "printer.h"
19 :     #include "maininfo.h"
20 :     #include "printinfo.h"
21 :     #include "optinfo.h"
22 :     #include "gadget.h"
23 :    
24 :     /**
25 :     * \class Ecosystem
26 :     * \brief This is the class used to control the model simulation
27 :     *
28 :     * This is the main class for the model simulation. This class contains pointers to all the objects that are to be used in the model simulation - the stocks and fleets, the model variables, any printer classes used to output the modelled population and any likelihood classes used to compare the modelled population to data. This class controls the model simulation, from the reading of the input files, simulating the modelled population on each timestep and printing the results, and finally calculating an overall likelihood score. This class is also used during an optimising run to update the variables to new values from the optimisation algorithm and calculating a new likelihood score based on these new values.
29 :     */
30 :     class Ecosystem {
31 :     public:
32 :     /**
33 :     * \brief This is the default Ecosystem constructor
34 :     */
35 :     Ecosystem() {};
36 :     /**
37 :     * \brief This is the Ecosystem constructor specifying details about the model
38 :     * \param main is the MainInfo specifying the command line options for the model run
39 :     */
40 :     Ecosystem(const MainInfo& main);
41 :     /**
42 :     * \brief This is the default Ecosystem destructor
43 :     */
44 :     ~Ecosystem();
45 :     /**
46 :     * \brief This function will read the model data from the main input file
47 :     * \param infile is the CommentStream to read the likelihood data from
48 :     * \param main is the MainInfo specifying the command line options for the model run
49 :     */
50 :     void readMain(CommentStream& infile, const MainInfo& main);
51 :     /**
52 :     * \brief This function will read the likelihood data from the input file
53 :     * \param infile is the CommentStream to read the likelihood data from
54 :     */
55 :     void readLikelihood(CommentStream& infile);
56 :     /**
57 :     * \brief This function will read the printer data from the input file
58 :     * \param infile is the CommentStream to read the printer data from
59 :     */
60 :     void readPrinters(CommentStream& infile);
61 :     /**
62 :     * \brief This function will read the fleet data from the input file
63 :     * \param infile is the CommentStream to read the fleet data from
64 :     */
65 :     void readFleet(CommentStream& infile);
66 :     /**
67 :     * \brief This function will read the tagging data from the input file
68 :     * \param infile is the CommentStream to read the tagging data from
69 :     */
70 :     void readTagging(CommentStream& infile);
71 :     /**
72 :     * \brief This function will read the otherfood data from the input file
73 :     * \param infile is the CommentStream to read the otherfood data from
74 :     */
75 :     void readOtherFood(CommentStream& infile);
76 :     /**
77 :     * \brief This function will read the stock data from the input file
78 :     * \param infile is the CommentStream to read the stock data from
79 :     */
80 :     void readStock(CommentStream& infile);
81 :     /**
82 :     * \brief This function will read in the optimisation parameters from the input file
83 :     * \param infile is the CommentStream to read the optimisation parameters from
84 :     */
85 : ulcessvp 11 void readOptimisation(CommentStream& infile, unsigned* seed);
86 : agomez 1 /**
87 :     * \brief This function will write the current model status to file
88 :     * \param filename is the name of the file to write the model information to
89 :     */
90 :     void writeStatus(const char* filename) const;
91 :     /**
92 :     * \brief This function will write header information about the model parameters to file
93 :     * \param filename is the name of the file to write the model information to
94 :     */
95 :     void writeInitialInformation(const char* const filename);
96 :     /**
97 :     * \brief This function will write current information about the model parameters to file
98 :     */
99 :     void writeValues();
100 :     /**
101 :     * \brief This function will write final information about the model parameters to file in a column format (which can then be used as the starting point for a subsequent model run)
102 :     * \param filename is the name of the file to write the model information to
103 :     * \param prec is the precision to use in the output file
104 :     */
105 :     void writeParams(const char* const filename, int prec) const;
106 :     /**
107 :     * \brief This function will display information about the best values of the parameters found so far during an optimisation run
108 :     */
109 :     void writeBestValues() { keeper->writeBestValues(); };
110 :     /**
111 :     * \brief This function will display information about the optimised values of the parameters
112 :     */
113 :     void writeOptValues();
114 : ulcessvp 11 //FIXME doc
115 :     //#ifdef GADGET_OPENMP
116 :     // void writeOptValuesOMP();
117 :     //#endif
118 : agomez 1 /**
119 :     * \brief This is the function that will optimise the likelihood score
120 :     */
121 :     void Optimise();
122 : ulcessvp 11 //FIXME doc
123 :     void OptimiseOMP();
124 : agomez 1 /**
125 :     * \brief This function will initialise the Ecosystem parameters
126 :     */
127 :     void Initialise();
128 :     /**
129 :     * \brief This function will update the Ecosystem parameters with new values from StochasticData
130 :     * \param Stochastic is the StochasticData containing the new values of the parameters
131 :     */
132 :     void Update(const StochasticData* const Stochastic) const { keeper->Update(Stochastic); };
133 : ulcessvp 11 //FIXME doc
134 :     void Update(const DoubleVector v)const { keeper->Update(v);}
135 : agomez 1 /**
136 :     * \brief This function will reset the Ecosystem information
137 :     */
138 :     void Reset();
139 :     /**
140 :     * \brief This function will store the current value of the variables from the optimisation process
141 :     * \param likvalue is the current likelihood value
142 :     * \param point is the DoubleVector of the current parameter values
143 :     */
144 :     void storeVariables(double likvalue, const DoubleVector& point) { keeper->storeVariables(likvalue, point); };
145 :     /**
146 :     * \brief This function will reset the variables that have been scaled, to be optimised using the Simulated Annealing optimisation algorithm
147 :     */
148 :     void resetVariables() { keeper->resetVariables(); };
149 :     /**
150 :     * \brief This function will scale the variables to be optimised, for the Hooke & Jeeves and BFGS optimisation algorithms
151 :     */
152 :     void scaleVariables() { keeper->scaleVariables(); };
153 :     /**
154 :     * \brief This function will return a copy of the initial value of the variables to be optimised
155 :     * \param val is the DoubleVector that will contain a copy of the initial values
156 :     */
157 :     void getOptInitialValues(DoubleVector& val) const { keeper->getOptInitialValues(val); };
158 :     /**
159 :     * \brief This function will return a copy of the scaled value of the variables to be optimised
160 :     * \param val is the DoubleVector that will contain a copy of the scaled values
161 :     */
162 :     void getOptScaledValues(DoubleVector& val) const { keeper->getOptScaledValues(val); };
163 :     /**
164 :     * \brief This function will return a copy of the lower bounds of the variables to be optimised
165 :     * \param lbs is the DoubleVector that will contain a copy of the lower bounds
166 :     */
167 :     void getOptLowerBounds(DoubleVector& lbs) const { keeper->getOptLowerBounds(lbs); };
168 :     /**
169 :     * \brief This function will return a copy of the upper bounds of the variables to be optimised
170 :     * \param ubs is the DoubleVector that will contain a copy of the upper bounds
171 :     */
172 :     void getOptUpperBounds(DoubleVector& ubs) const { keeper->getOptUpperBounds(ubs); };
173 :     /**
174 :     * \brief This function will check that the values of the parameters are within the specified bounds
175 :     */
176 :     void checkBounds() const { keeper->checkBounds(likevec); };
177 :     /**
178 :     * \brief This function will return the number of variables
179 :     * \return number of variables
180 :     */
181 :     int numVariables() const { return keeper->numVariables(); };
182 :     /**
183 :     * \brief This function will return the number of variables to be optimised
184 :     * \return number of variables to be optimised
185 :     */
186 :     int numOptVariables() const { return keeper->numOptVariables(); };
187 :     /**
188 :     * \brief This function will simulate the population in the model
189 :     * \param print is the flag to denote whether the model output should be printed or not
190 :     * \note This function covers a single running of the model, calculating the population structure and also calculating the likelihood score obtained from comparing the modelled population to the data specified in the likelihood components
191 :     */
192 :     void Simulate(int print);
193 :     /**
194 :     * \brief This function will calculate the predation, and update the population, on an area
195 :     * \param area is the area to calculate the predation on (default value 0)
196 :     * \note This function covers the predation of the preys by the predators, and consequent population changes, for a sub-step within a timestep of the model
197 :     */
198 :     void updatePredationOneArea(int area = 0);
199 :     /**
200 :     * \brief This function will update the population numbers on an area
201 :     * \param area is the area to update the population on (default value 0)
202 :     * \note This function covers the growth, various movements between stocks due to maturity and straying, spawning, and adding new recruits into the model
203 :     */
204 :     void updatePopulationOneArea(int area = 0);
205 :     /**
206 :     * \brief This function will update the ages of the population on an area
207 :     * \param area is the area to update the population on (default value 0)
208 :     * \note This function covers the increase in age and the simple 'doesmove' option for movement between stocks
209 :     */
210 :     void updateAgesOneArea(int area = 0);
211 :     /**
212 :     * \brief This function will update the model parameters, run the model and calculate a likelihood score
213 :     * \param x is the DoubleVector containing the updated values for the parameters
214 :     * \return likelihood score
215 :     * \note This function gets updated values for the model parameters from the optimisation algorithm and performs a model run based on these new values, calculating a new likelihood score that is then returned to the optimisation algorithm
216 :     */
217 :     double SimulateAndUpdate(const DoubleVector& x);
218 :     /**
219 :     * \brief This function will return the likelihood score from the current simulation
220 :     * \return likelihood score
221 :     */
222 :     double getLikelihood() const { return likelihood; };
223 :     /**
224 :     * \brief This function will return the total number of iterations completed
225 :     * \return number of iterations
226 :     */
227 :     int getFuncEval() const { return funceval; };
228 :     /**
229 :     * \brief This function will return the current time in the simulation
230 :     * \return current time
231 :     */
232 :     int getCurrentTime() const { return TimeInfo->getTime(); };
233 :     /**
234 :     * \brief This function will return the current year in the simulation
235 :     * \return current year
236 :     */
237 :     int getCurrentYear() const { return TimeInfo->getYear(); };
238 :     /**
239 :     * \brief This function will return the current step in the simulation
240 :     * \return current step
241 :     */
242 :     int getCurrentStep() const { return TimeInfo->getStep(); };
243 :     /**
244 :     * \brief This function will return the total number of timestep in the simulation
245 :     * \return number of timesteps
246 :     */
247 :     int numTotalSteps() const { return TimeInfo->numTotalSteps(); };
248 :     /**
249 :     * \brief This function will return the likelihood components used in the simulation
250 :     * \return LikelihoodPtrVector containing all the likelihood components used in the simulation
251 :     */
252 :     LikelihoodPtrVector& getModelLikelihoodVector() { return likevec; };
253 :     /**
254 :     * \brief This function will return the printer components used in the simulation
255 :     * \return PrinterPtrVector containing all the printer components used in the simulation
256 :     */
257 :     PrinterPtrVector& getModelPrinterVector() { return printvec; };
258 :     /**
259 :     * \brief This function will return the fleets used in the simulation
260 :     * \return FleetPtrVector containing all the fleets used in the simulation
261 :     */
262 :     FleetPtrVector& getModelFleetVector() { return fleetvec; };
263 :     /**
264 :     * \brief This function will return the stocks used in the simulation
265 :     * \return StockPtrVector containing all the stocks used in the simulation
266 :     */
267 :     StockPtrVector& getModelStockVector() { return stockvec; };
268 :     /**
269 :     * \brief This is the flag used to denote whether the user has interrupted the current model run
270 :     */
271 : ulcessvp 11 //FIXME doc
272 :     DoubleVector getValues() {return keeper->getValues();}
273 : agomez 1 volatile int interrupted;
274 :     protected:
275 :     /**
276 :     * \brief This is the value of the likelihood score for the current simulation
277 :     */
278 :     double likelihood;
279 :     /**
280 :     * \brief This is the current iteration
281 :     */
282 :     int funceval;
283 :     /**
284 :     * \brief This is the BaseClassPtrVector of the stocks, fleets and otherfood classes for the current model
285 :     */
286 :     BaseClassPtrVector basevec;
287 :     /**
288 :     * \brief This is the LikelihoodPtrVector of the likelihood components for the current model
289 :     */
290 :     LikelihoodPtrVector likevec;
291 :     /**
292 :     * \brief This is the PrinterPtrVector of the printer classes for the current model
293 :     */
294 :     PrinterPtrVector printvec;
295 :     /**
296 :     * \brief This is the OptInfoPtrVector of the optimisation algorithms for the current model
297 :     */
298 :     OptInfoPtrVector optvec;
299 :     /**
300 :     * \brief This is the TimeClass for the current model
301 :     */
302 :     TimeClass* TimeInfo;
303 :     /**
304 :     * \brief This is the AreaClass for the current model
305 :     */
306 :     AreaClass* Area;
307 :     /**
308 :     * \brief This is the Keeper for the current model
309 :     */
310 :     Keeper* keeper;
311 :     /**
312 :     * \brief This is the StockPtrVector of the stocks for the current model
313 :     */
314 :     StockPtrVector stockvec;
315 :     /**
316 :     * \brief This is the TagPtrVector of the tagging experiments for the current model
317 :     */
318 :     TagPtrVector tagvec;
319 :     /**
320 :     * \brief This is the OtherFoodPtrVector of the otherfood for the current model
321 :     */
322 :     OtherFoodPtrVector otherfoodvec;
323 :     /**
324 :     * \brief This is the FleetPtrVector of the fleets for the current model
325 :     */
326 :     FleetPtrVector fleetvec;
327 :     /**
328 :     * \brief This is the PrintInfo specifying the parameter output from the current model
329 :     */
330 :     PrintInfo printinfo;
331 :     /**
332 :     * \brief This is the counter for the printing interval for the -o output from the simualtion
333 :     */
334 :     int printcount;
335 :     /**
336 :     * \brief This is the DoubleVector used to store the initial values of the parameters
337 :     * \note This vector is only used to temporarily store values during an optimising run
338 :     */
339 :     DoubleVector initialval;
340 :     /**
341 :     * \brief This is the DoubleVector used to store the current values of the parameters
342 :     * \note This vector is only used to temporarily store values during an optimising run
343 :     */
344 :     DoubleVector currentval;
345 :     /**
346 :     * \brief This is the IntVector used to store information about whether the parameters are to be optimised
347 :     * \note This vector is only used to temporarily store values during an optimising run
348 :     */
349 :     IntVector optflag;
350 :     };
351 :    
352 :     #endif

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge