-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from KienTTran/main
Update core scheduler
- Loading branch information
Showing
15 changed files
with
616 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,47 @@ | ||
# Core Config | ||
|
||
The Configuration module is responsible for loading, validating, and managing the configuration settings for the simulation. It reads configuration data from a YAML file and provides access to various configuration parameters through getter methods. | ||
|
||
## Files | ||
|
||
- `Config.h` and `Config.cpp`: Defines the `Config` class, which handles loading and validating the configuration file. | ||
- `ConfigData.h`: Defines the `ConfigData` struct, which holds all the configuration parameters. | ||
- `ConfigData.cpp`: Implements the methods for the `ConfigData` struct. | ||
|
||
## Classes | ||
|
||
### Config | ||
|
||
The `Config` class is responsible for: | ||
|
||
- Loading configuration data from a YAML file. | ||
- Validating the configuration data. | ||
- Providing access to the configuration parameters. | ||
|
||
#### Methods | ||
|
||
- `bool load(const std::string &filename)`: Loads the configuration from the specified YAML file. | ||
- `void reload()`: Reloads the configuration file. | ||
- `void validate_all_cross_field_validations()`: Validates all cross-field validations. | ||
- Various getter methods to access specific configuration parameters. | ||
|
||
### ConfigData | ||
|
||
The `ConfigData` struct holds all the configuration parameters. It includes the following fields: | ||
|
||
- `ModelSettings model_settings`: Configuration for the model settings. | ||
- `TransmissionSettings transmission_settings`: Configuration for transmission settings. | ||
- `PopulationDemographic population_demographic`: Configuration for population demographics. | ||
- `SimulationTimeframe simulation_timeframe`: Configuration for the simulation timeframe. | ||
- `SpatialSettings spatial_settings`: Configuration for spatial settings. | ||
- `SeasonalitySettings seasonality_settings`: Configuration for seasonality settings. | ||
- `MovementSettings movement_settings`: Configuration for movement settings. | ||
- `ParasiteParameters parasite_parameters`: Configuration for parasite parameters. | ||
- `ImmuneSystemParameters immune_system_parameters`: Configuration for immune system parameters. | ||
- `GenotypeParameters genotype_parameters`: Configuration for genotype parameters. | ||
- `DrugParameters drug_parameters`: Configuration for drug parameters. | ||
- `TherapyParameters therapy_parameters`: Configuration for therapy parameters. | ||
- `StrategyParameters strategy_parameters`: Configuration for strategy parameters. | ||
- `EpidemiologicalParameters epidemiological_parameters`: Configuration for epidemiological parameters. | ||
- `MosquitoParameters mosquito_parameters`: Configuration for mosquito parameters. | ||
- `PopulationEvents population_events`: Configuration for population events. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,37 @@ | ||
# Core Scheduler | ||
|
||
The Scheduler module is responsible for managing the simulation's time progression and scheduling events. It interacts with the `Model` class to execute daily, monthly, and yearly updates. | ||
|
||
## Files | ||
|
||
- `Scheduler.h` and `Scheduler.cpp`: Defines the `Scheduler` class, which handles the simulation's time management and event scheduling. | ||
|
||
## Classes | ||
|
||
### Scheduler | ||
|
||
The `Scheduler` class is responsible for: | ||
|
||
- Managing the simulation's current time and total available time. | ||
- Interacting with the `Model` class to perform updates. | ||
- Handling the simulation's calendar date. | ||
- Providing methods to start, run, and stop the simulation. | ||
|
||
#### Methods | ||
|
||
- `Scheduler(Model *model = nullptr)`: Constructor that initializes the scheduler with an optional `Model` instance. | ||
- `~Scheduler()`: Destructor that clears all events. | ||
- `void extend_total_time(int new_total_time)`: Extends the total available time for the simulation. | ||
- `void clear_all_events()`: Clears all scheduled events. | ||
- `void initialize(const date::year_month_day &starting_date, const int &total_time)`: Initializes the scheduler with a starting date and total time. | ||
- `void run()`: Runs the simulation. | ||
- `void begin_time_step() const`: Begins a time step in the simulation. | ||
- `void end_time_step() const`: Ends a time step in the simulation. | ||
- `bool can_stop() const`: Checks if the simulation can stop. | ||
- `int current_day_in_year() const`: Returns the current day in the year. | ||
- `int current_month_in_year() const`: Returns the current month in the year. | ||
- `bool is_today_last_day_of_month() const`: Checks if today is the last day of the month. | ||
- `bool is_today_first_day_of_month() const`: Checks if today is the first day of the month. | ||
- `bool is_today_first_day_of_year() const`: Checks if today is the first day of the year. | ||
- `bool is_today_last_day_of_year() const`: Checks if today is the last day of the year. | ||
- `void daily_update() const`: Performs daily updates in the simulation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#include "Scheduler.h" | ||
|
||
#include <Configuration/Config.h> | ||
|
||
Scheduler::Scheduler(Model* model) | ||
: current_time_(-1), total_available_time_(-1), model_(model), is_force_stop_(false) {} | ||
|
||
Scheduler::~Scheduler() { | ||
clear_all_events(); | ||
} | ||
|
||
void Scheduler::extend_total_time(int new_total_time) { | ||
if (total_available_time_ < new_total_time) { | ||
// for (auto i = total_available_time_; i <= new_total_time; i++) { | ||
// individual_events_list_.push_back(EventPtrVector()); | ||
// population_events_list_.push_back(EventPtrVector()); | ||
// } | ||
} | ||
total_available_time_ = new_total_time; | ||
} | ||
|
||
void Scheduler::clear_all_events() { | ||
// clear_all_events(individual_events_list_); | ||
// clear_all_events(population_events_list_); | ||
} | ||
|
||
void Scheduler::initialize(const date::year_month_day& starting_date, const int& total_time) { | ||
set_total_available_time(total_time + 720); // Prevent scheduling at the end of simulation | ||
set_current_time(0); | ||
calendar_date = date::sys_days(starting_date); | ||
} | ||
|
||
// Methods not declared in the header have been removed | ||
|
||
void Scheduler::run() { | ||
current_time_ = 0; | ||
for (current_time_ = 0; !can_stop(); current_time_++) { | ||
if (current_time_ % model_->get_config()->get_model_settings().get_days_between_stdout_output() == 0) { | ||
spdlog::info("Day: {}", current_time_); | ||
} | ||
begin_time_step(); | ||
daily_update(); | ||
end_time_step(); | ||
calendar_date += date::days{1}; | ||
} | ||
} | ||
|
||
void Scheduler::begin_time_step() const { | ||
if (model_ != nullptr) { | ||
model_->begin_time_step(); | ||
} | ||
} | ||
|
||
void Scheduler::daily_update() const { | ||
if (model_ != nullptr) { | ||
model_->daily_update(); | ||
|
||
if (is_today_first_day_of_month()) { | ||
model_->monthly_update(); | ||
} | ||
|
||
if (is_today_first_day_of_year()) { | ||
model_->yearly_update(); | ||
} | ||
|
||
// Executing population-related events | ||
// execute_events_list(population_events_list_[current_time_]); | ||
|
||
// Executing individual-related events | ||
// execute_events_list(individual_events_list_[current_time_]); | ||
} | ||
} | ||
|
||
void Scheduler::end_time_step() const { | ||
if (model_ != nullptr) { | ||
model_->end_time_step(); | ||
} | ||
} | ||
|
||
bool Scheduler::can_stop() const { | ||
return current_time_ > model_->get_config()->get_simulation_timeframe().get_total_time(); | ||
} | ||
|
||
int Scheduler::current_day_in_year() const { | ||
return utils::Time::instance().day_of_year(calendar_date); | ||
} | ||
|
||
int Scheduler::current_month_in_year() const { | ||
return utils::Time::instance().month_of_year(calendar_date); | ||
} | ||
|
||
bool Scheduler::is_today_last_day_of_year() const { | ||
date::year_month_day ymd{calendar_date}; | ||
return ymd.month() == date::month{12} && ymd.day() == date::day{31}; | ||
} | ||
|
||
bool Scheduler::is_today_first_day_of_month() const { | ||
date::year_month_day ymd{calendar_date}; | ||
return ymd.day() == date::day{1}; | ||
} | ||
|
||
bool Scheduler::is_today_first_day_of_year() const { | ||
date::year_month_day ymd{calendar_date}; | ||
return ymd.month() == date::month{1} && ymd.day() == date::day{1}; | ||
} | ||
|
||
bool Scheduler::is_today_last_day_of_month() const { | ||
const auto next_date = calendar_date + date::days{1}; | ||
date::year_month_day ymd{next_date}; | ||
return ymd.day() == date::day{1}; | ||
} |
Oops, something went wrong.