-
Notifications
You must be signed in to change notification settings - Fork 0
/
Colony.h
554 lines (485 loc) · 19.1 KB
/
Colony.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
#if !defined(AFX_COLONY_H__8C6C41B4_7899_11D2_8D9A_0020AF233A70__INCLUDED_)
#define AFX_COLONY_H__8C6C41B4_7899_11D2_8D9A_0020AF233A70__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// Colony.h : header file
//
#include "Adult.h"
#include "Bee.h"
#include "Brood.h"
#include "ColonyResource.h"
#include "DateRangeValues.h"
#include "EPAData.h"
#include "Egg.h"
#include "Larva.h"
#include "Mite.h"
#include "MiteTreatmentItem.h"
#include "MiteTreatments.h"
#include "NutrientContaminationTable.h"
#include "Queen.h"
#include "Spores.h"
#include "WeatherEvents.h"
#include <memory>
#include <queue>
class CColony; // Forward declaration
/////////////////////////////////////////////////////////////////////////////
// List classes for all bee life stages
/////////////////////////////////////////////////////////////////////////////
//
// CBeelist - this is the base class for all bee list classes. Contains the functions and attributes common to all
//
class CBeelist : public CObList
{
protected:
int m_ListLength;
CColony* m_pColony;
static const int m_DefaultPropTransition = 1;
double m_PropTransition; // The proportion of bees from this list that go to the caboose
// A number between 0.0 .. 1.0
CDateRangeValues* m_pDRVList;
public:
CBeelist() {}
virtual ~CBeelist();
void SetLength(int len) { m_ListLength = len; }
int GetLength() { return m_ListLength; }
int GetQuantity();
virtual int GetQuantityAt(int index);
virtual int GetQuantityAt(int from, int to);
virtual void SetQuantityAt(int index, int Quan);
virtual void SetQuantityAt(int from, int to, int Quan);
virtual void SetQuantityAtProportional(int from, int to, double Proportion);
void KillAll();
void SetColony(CColony* pCol) { m_pColony = pCol; }
CColony* GetColony() { return m_pColony; }
virtual void Serialize(CArchive& ar) = 0;
CString Status();
void FactorQuantity(double factor);
// void SetQuantityAt(int Quan);
void SetPropTransition(double Prop) { m_PropTransition = Prop; }
double GetPropTransition() { return m_PropTransition; }
static int DroneCount;
static int ForagerCount;
static int WorkerCount;
};
/////////////////////////////////////////////////////////////////////////////
//
// CAdultlist - Drones and Workers
//
class CAdultlist : public CBeelist
{
protected:
std::unique_ptr<CAdultlist> PendingAdults;
CAdult* Caboose;
public:
CAdultlist();
virtual ~CAdultlist();
//! Add method simply add theBrood to the Adults without making the adults age
virtual void Add(CBrood* theBrood, CColony* theColony, CEvent* theEvent, bool bWorkder = true);
virtual void Update(CBrood* theBrood, CColony* theColony, CEvent* theEvent, bool bWorkder = true);
virtual void UpdateLength(int len, bool bWorker = true);
virtual int MoveToEnd(int QuantityToMove, int MinAge);
int GetQuantity();
CAdult* GetCaboose() { return Caboose; }
virtual int GetCabooseQuantity() const;
virtual int GetCabooseBoxCardsCount() const { return Caboose != NULL ? 1 : 0; }
virtual void ClearCaboose();
CAdultlist* GetPendingAdults() { return PendingAdults.get(); }
void Serialize(CArchive& ar);
void KillAll();
};
//! Adults age based on foraging weather.
//! - if it is too windy, adults will not age
//! - if it is too rainy, adults will not age
//! - if weather is not compatible with foragers flying time, adults will not age
class CForageBasedAgingAdultList : public CAdultlist
{
public:
typedef std::deque<CAdult*> CabooseQueue;
CForageBasedAgingAdultList() {}
// Revisit Get/Set quantities since boxcards do not correspond to ages anymore
virtual int GetQuantityAt(int index);
virtual int GetQuantityAt(int from, int to);
virtual void SetQuantityAt(int index, int Quan);
virtual void SetQuantityAt(int from, int to, int Quan);
virtual void SetQuantityAtProportional(int from, int to, double Proportion);
//! Add method simply add theBrood txo the Adults without making the adults age
virtual void Add(CBrood* theBrood, CColony* theColony, CEvent* theEvent, bool bWorkder = true);
virtual void Update(CBrood* theBrood, CColony* theColony, CEvent* theEvent, bool bWorkder = true);
virtual void UpdateLength(int len, bool bWorker = true);
virtual int MoveToEnd(int QuantityToMove, int MinAge);
CabooseQueue& GetCabooseQueue() { return m_Caboose; }
virtual int GetCabooseQuantity() const;
virtual int GetCabooseBoxCardsCount() const;
virtual void ClearCaboose();
protected:
void UpdateCaboose(bool bWorker, CColony* colony = nullptr);
protected:
CabooseQueue m_Caboose;
};
/////////////////////////////////////////////////////////////////////////////
//
// CForagerlist - this is a type of CAdultList implementing Forager behaviors
//
class CForagerlist : public CAdultlist
{
private:
CAdultlist PendingForagers;
CAdult m_UnemployedForagers;
double m_PropActualForagers;
public:
CForagerlist();
virtual ~CForagerlist();
void Update(CAdult* theAdult, CEvent* theEvent);
void ClearPendingForagers();
void KillAll();
int GetQuantity(); // Total Forarger Quantity including UnemployedForagers
int GetActiveQuantity(); // Total Forager Quantity minus UnemployedForagers
int GetUnemployedQuantity();
void SetUnemployedForagerQuantity(int Quan) { m_UnemployedForagers.SetNumber(Quan); }
void SetLength(int len);
void SetPropActualForagers(double proportion) { m_PropActualForagers = proportion; }
double GetPropActualForagers() { return m_PropActualForagers; }
};
/////////////////////////////////////////////////////////////////////////////
//
// CForagerlistA - An update from CForagerlist (created in version 3.2.8.0) to implement a new data structure logic for
// Foragers()-> The design intent is to maintain the same interface as CForagerlist but implement to the new data
// structure which is a longer CAdultlist.
//
class CForagerlistA : public CAdultlist
{
private:
CAdultlist PendingForagers;
double m_PropActualForagers;
public:
CForagerlistA();
virtual ~CForagerlistA();
virtual void Update(CAdult* theAdult, CColony* theColony, CEvent* theEvent);
virtual void SetLength(int len);
void ClearPendingForagers();
void KillAll();
int GetQuantity(); // Total Forarger Quantity including UnemployedForagers
int GetActiveQuantity(); // Total Forager Quantity minus UnemployedForagers
int GetPendingQuantity(); // Total Pending Foragers
int GetUnemployedQuantity();
// void SetUnemployedForagerQuantity(int Quan) { m_UnemployedForagers.SetNumber(Quan); }
void SetPropActualForagers(double proportion) { m_PropActualForagers = proportion; }
double GetPropActualForagers() { return m_PropActualForagers; }
};
//! Foragers age based on foraging weather.
//! - if it is too windy, adults will not age
//! - if it is too rainy, adults will not age
//! - if weather is not compatible with foragers flying time, adults will not age
class CForageBasedAgingForagersList : public CForagerlistA
{
public:
CForageBasedAgingForagersList() : CForagerlistA() {}
//! Add method simply add theBrood txo the Adults without making the adults age
virtual void Update(CForageBasedAgingAdultList::CabooseQueue& theAdult, CColony* theColony, CEvent* theEvent);
virtual void SetLength(int len);
protected:
void KillOldForagers();
};
/////////////////////////////////////////////////////////////////////////////
//
// CBroodlist - capped brood
//
class CBroodlist : public CBeelist
{
protected:
CBrood* Caboose;
public:
double GetMitesPerCell();
void Update(CLarva* theLarva);
void Serialize(CArchive& ar);
int GetMiteCount();
void KillAll();
void DistributeMites(CMite theMites);
float GetPropInfest();
CBrood* GetCaboose() { return Caboose; }
void ClearCaboose() { Caboose = NULL; }
};
/////////////////////////////////////////////////////////////////////////////
//
// CLarvalist
//
class CLarvalist : public CBeelist
{
protected:
CLarva* Caboose;
public:
void Update(CEgg* theEggs);
void Serialize(CArchive& ar);
CLarva* GetCaboose() { return Caboose; }
void KillAll();
void ClearCaboose() { Caboose = NULL; }
};
/////////////////////////////////////////////////////////////////////////////
//
// CEgglist
//
class CEgglist : public CBeelist
{
protected:
CEgg* Caboose;
public:
void Update(CEgg* theEggs);
void Serialize(CArchive& ar);
void KillAll();
CEgg* GetCaboose() { return Caboose; }
void ClearCaboose() { Caboose = NULL; }
};
/////////////////////////////////////////////////////////////////////////////
// CColony
struct ColonyInitCond
{
float m_droneAdultInfestField;
float m_droneBroodInfestField;
float m_droneMiteOffspringField;
float m_droneMiteSurvivorshipField;
float m_workerAdultInfestField;
float m_workerBroodInfestField;
float m_workerMiteOffspring;
float m_workerMiteSurvivorship;
int m_droneAdultsField;
int m_droneBroodField;
int m_droneEggsField;
int m_droneLarvaeField;
int m_workerAdultsField;
int m_workerBroodField;
int m_workerEggsField;
int m_workerLarvaeField;
int m_totalEggsField;
double m_DDField;
double m_LField;
double m_NField;
double m_PField;
double m_ddField;
double m_lField;
double m_nField;
// From Simulation Initial Conditions
double m_QueenStrength;
double m_QueenSperm;
double m_MaxEggs;
int m_ForagerLifespan;
CString m_SimStart;
CString m_SimEnd;
CDateRangeValues m_EggTransitionDRV;
CDateRangeValues m_LarvaeTransitionDRV;
CDateRangeValues m_BroodTransitionDRV;
CDateRangeValues m_AdultTransitionDRV;
CDateRangeValues m_ForagerLifespanDRV;
CDateRangeValues m_AdultLifespanDRV;
};
struct SupplementalFeedingResource
{
double m_StartingAmount; // In Grams
double m_CurrentAmount; // In Grams
COleDateTime m_BeginDate;
COleDateTime m_EndDate;
};
// Durations of each life stage
#define EGGLIFE 3
#define DLARVLIFE 7
#define WLARVLIFE 5
#define DBROODLIFE 14
#define WBROODLIFE 13
#define DADLLIFE 21
#define WADLLIFE 21
// Discrete Events
#define DE_NONE 1
#define DE_SWARM 2
#define DE_CHALKBROOD 3
#define DE_RESOURCEDEP 4
#define DE_SUPERCEDURE 5
#define DE_PESTICIDE 6
class CColony : public CCmdTarget
{
DECLARE_DYNCREATE(CColony)
CColony(); // protected constructor used by dynamic creation
// Attributes
protected:
BOOL GetDiscreteEvents(CString key, CUIntArray*& theArray);
CString name;
bool HasBeenInitialized;
int m_VTStart;
int m_SPStart;
UINT m_VTDuration;
UINT m_VTMortality;
bool m_VTEnable;
bool m_SPEnable;
bool m_VTTreatmentActive;
bool m_SPTreatmentActive;
double m_InitMitePctResistant;
int m_MitesDyingToday;
bool m_PollenFeedingDay; // Specifies this is a day when man-made feed is available.
bool m_NectarFeedingDay; // Specifies this is a day when man-made feed is available.
// Data structure for discrete events
CMapStringToOb m_EventMap;
public:
ColonyInitCond m_InitCond;
double LongRedux[8]; // Longevity Reduction as a function of mite infestation
int m_CurrentForagerLifespan;
CArray<double, double> m_RQQueenStrengthArray;
CStringList m_ColonyEventList;
// Bee Attributes
CQueen queen;
// CForagerlist foragers;
CAdultlist Dadl;
std::unique_ptr<CAdultlist> m_Wadl;
std::unique_ptr<CForagerlistA> m_Foragers;
CBroodlist CapWkr;
CBroodlist CapDrn;
CLarvalist Wlarv;
CLarvalist Dlarv;
CEgglist Weggs;
CEgglist Deggs;
// Mite Attributes
CMite WMites; // # of mites under capped worker cells
CMite DMites; // # of mites under capped drone cells
CMite NewMitesW; // # of mated female mites emerging from worker cells in 1st step
CMite NewMitesD; // # of mated female mites emerging from drone cells in 1st step
CMite RunMiteW; // # of mites on adult workers
CMite RunMiteD; // # of mites on adult drones
CMite PrevEmergMite; // # of mites that emerged from previous day
CMite RunMite; // Total # of mites outside of cells
double PropRMVirgins; // Proportion of Free Mites that have not yet infested
float PropInfstW; // Proportion of infested workers
float PropInfstD; // Proportion of infested drones
CSpores m_Spores; // The spore population for in the colony.
CMiteTreatments m_MiteTreatmentInfo; // This is public since CVarroaPopDoc will serialize it based on file version
CColonyResource m_Resources; // The stored Pollen and Nectar in the colony
SupplementalFeedingResource m_SuppPollen; // Supplemental Feeding. SAmount in grams
SupplementalFeedingResource m_SuppNectar; // Supplemental Feeding. Amount in grams
double m_ColonyNecInitAmount; // Starting amount of Nectar(g) at the beginning of the simulation
double m_ColonyNecMaxAmount;
double m_ColonyPolInitAmount; // Starting amount of Pollen(g) at the beginning of the simulation
double m_ColonyPolMaxAmount;
bool m_SuppPollenEnabled;
bool m_SuppNectarEnabled;
bool m_SuppPollenAnnual;
bool m_SuppNectarAnnual;
bool m_NoResourceKillsColony; // Determines if lack of nectar or pollen will cause colony to die. If true, colony
// dies. User parameter.
CEPAData m_EPAData; // EPA-related data structure
// Additional statistics
// When the option GlobalOptions::Get().ShouldOutputInOutCounts() is activated
// the following count will be appended to the normal output
struct InOutEvent
{
void Reset() { memset(this, 0, sizeof(InOutEvent)); }
int m_NewWEggs = -1; //!< new worker eggs
int m_NewDEggs = -1; //!< new drone eggs
int m_WEggsToLarv = -1; //!< worker eggs moving to larvae
int m_DEggsToLarv = -1; //!< drone eggs moving to larvae
int m_WLarvToBrood = -1; //!< worker larvae moving to brood
int m_DLarvToBrood = -1; //!< drone larvae moving to brood
int m_WBroodToAdult = -1; //!< worker drone moving to adult
int m_DBroodToAdult = -1; //!< drone drone moving to adult
int m_DeadDAdults = -1; //!< drone adult dying
int m_ForagersKilledByPesticide = -1; //!< forager killed by pesticide
int m_WAdultToForagers = -1; //!< worker adult moving to forager
int m_ForagersAtTheBeginningOfTheDay = -1; //!< forager at the beginning of the day
int m_WinterMortalityForagersLoss = -1; //!< forager dying to due winter mortality
int m_DeadForagers = -1; //!< forager dying
};
InOutEvent m_InOutEvent;
// Operations
public:
//! get the adults list and creates it if needed
std::unique_ptr<CAdultlist>& Wadl();
//! get the foragers list and creates it if needed
std::unique_ptr<CForagerlistA>& Foragers();
int m_MitesDyingThisPeriod;
int GetMitesDyingThisPeriod();
void SetStartSamplePeriod();
int GetTotalMiteCount();
int GetMitesDyingToday();
int GetNurseBees();
void RemoveDiscreteEvent(CString datestg, UINT EventID);
void AddDiscreteEvent(CString datestg, UINT EventID);
void DoPendingEvents(CEvent* pWeatherEvent, int CurSimDay);
// double GetMitesPerDBrood();
// double GetMitesPerWBrood();
virtual ~CColony();
void Clear();
CString GetName() { return name; }
void SetName(CString stg) { name = stg; }
CColony operator=(CColony col); // Assignment operator
CColony(CColony& col); // Copy Constructor
void InitializeColony();
void InitializeBees();
void InitializeMites();
void SetInitialized(bool val) { HasBeenInitialized = val; }
bool IsInitialized() { return HasBeenInitialized; }
void UpdateBees(CEvent* pEvent, int DayNum);
void UpdateMites(CEvent* pEvent, int DayNum);
int GetForagerLifespan() { return m_InitCond.m_ForagerLifespan; }
void AddMites(CMite NewMites);
void SetMitePctResistance(double pct) { m_InitMitePctResistant = pct; }
int GetColonySize();
void RemoveDroneComb(double pct);
int GetEggsToday();
double GetDDToday();
double GetLToday();
double GetNToday();
double GetPToday();
double GetddToday();
double GetlToday();
double GetnToday();
void ReQueenIfNeeded(
int DayNum, CEvent* theEvent, UINT EggLayingDelay, double WkrDrnRatio, BOOL EnableReQueen, int Scheduled,
double QueenStrength, int Once, COleDateTime ReQueenDate);
void SetMiticideTreatment(int StartDayNum, UINT Duration, UINT Mortality, BOOL Enable);
void SetMiticideTreatment(CMiteTreatments& theTreatments, BOOL Enable);
void SetSporeTreatment(int StartDayNum, BOOL Enable);
// double GetSporeMortality(int TreatmentDayNum);
bool IsPollenFeedingDay(CEvent* pEvent);
bool IsNectarFeedingDay(CEvent* pEvent);
void KillColony();
COleDateTime* GetDayNumDate(int theDayNum);
void AddEventNotification(CString DateStg, CString Msg);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CColony)
public:
virtual void Serialize(CArchive& ar, int FileFormatVersion = 0);
//}}AFX_VIRTUAL
// Generated message map functions
//{{AFX_MSG(CColony)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// Colony Resource Management
double GetPollenNeeds(CEvent* pEvent);
double GetNectarNeeds(CEvent* pEvent);
void InitializeColonyResources(void);
double GetIncomingNectarQuant(void);
double GetIncomingNectarPesticideConcentration(int DayNum);
double GetIncomingPollenQuant(void);
double GetIncomingPollenPesticideConcentration(int DayNum);
// EPA Pesticide Dose and Mortality
void ConsumeFood(CEvent* pEvent, int DayNum);
void DetermineFoliarDose(int DayNum);
void ApplyPesticideMortality();
int ApplyPesticideToBees(
CBeelist* pList, int from, int to, double CurrentDose, double MaxDose, double LD50, double Slope);
int QuantityPesticideToKill(CBeelist* pList, double CurrentDose, double MaxDose, double LD50, double Slope);
public:
CNutrientContaminationTable m_NutrientCT;
bool m_NutrientContEnabled;
int m_DeadWorkerLarvaePesticide;
int m_DeadDroneLarvaePesticide;
int m_DeadWorkerAdultsPesticide;
int m_DeadDroneAdultsPesticide;
int m_DeadForagersPesticide;
protected:
void AddPollenToResources(SResourceItem theResource);
public:
void AddNectarToResources(SResourceItem theResource);
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_COLONY_H__8C6C41B4_7899_11D2_8D9A_0020AF233A70__INCLUDED_)