-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColdStorageSimulator.h
87 lines (66 loc) · 2.32 KB
/
ColdStorageSimulator.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
#pragma once
#include <afx.h>
#include <string>
class CEvent;
class CColony;
// There are 2 ways to activate cold storage:
// - based on an exterior criteria then call Activate / DeActivate to force cold storage
// - specify start and end date so that cold storage is activated during this period
class CColdStorageSimulator : public CObject
{
public:
static double GetDefaultColdStorageTemperature()
{
const double temperature = ((40.0 - 32.0) / 1.8);
return temperature;
}
private:
// Enables cold storage
bool m_Enabled = false;
// start and end date for automatic cold storage
COleDateTime m_StartDate;
COleDateTime m_EndDate;
// Cold storage is activated based on m_On state only
bool m_On = false;
// Temperature in cold storage
double m_Temperature = GetDefaultColdStorageTemperature();
// Optimization
std::string m_StartDateStr; // used for faster comparison between current and start date
std::string m_EndDateStr; // used for faster comparison between current and end date
// State attributes
bool m_IsActive = false;
bool m_IsStarting = false;
bool m_IsEnding = false;
public:
static CColdStorageSimulator& Get()
{
static CColdStorageSimulator sInstance;
return sInstance;
}
void SetEnabled(bool enabled) { m_Enabled = enabled; }
bool IsEnabled() const { return m_Enabled; }
void Activate() { m_On = true; }
void DeActivate() { m_On = false; }
bool IsOn() const { return m_On; }
// Returns true if the start and end date are not specified
bool IsAutomatic() const { return m_StartDateStr.empty() && m_EndDateStr.empty(); }
double GetTemp(CEvent& p_Event) const;
double GetMaxTemp(CEvent& p_Event) const;
double GetMinTemp(CEvent& p_Event) const;
double GetForageInc(CEvent& p_Event) const;
bool IsForageDay(CEvent& p_Event) const;
void SetStartDate(const COleDateTime& startDate);
void SetEndDate(const COleDateTime& endDate);
// Updates the state of the cold storage, call once a simulation day
void Update(CEvent& p_Event, CColony& queen);
// Reset default values
void Reset();
// Returns true if cold storage is currently activated
bool IsActive() const;
// Returns true if cold storage is currently activated
bool IsStarting() const;
// Returns true if cold storage is currently activated
bool IsEnding() const;
protected:
bool IsColdStoragePeriod(CEvent& p_Event) const;
};