Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/random seed driving profiles #139

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is inspired from [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and the versioning aim to respect [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [unreleased] - 2024-05-17

### Added

- driving_profile_seed parameter in the config file to set the seed for the driving profile generation step #139

### Changed

- Results are the same for the same seed specified in the config file #139

## [1.0.0] - 2022-07-15

### Added
Expand Down
1 change: 1 addition & 0 deletions scenarios/default/configs/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ energy_min = energy_min.csv
scaling = 1
num_threads = 4
seed = 3
driving_profile_seed = 10
private_only_run = false
1 change: 1 addition & 0 deletions scenarios/default_RS7/configs/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ energy_min = energy_min.csv
scaling = 1
num_threads = 4
seed = 3
driving_profile_seed = 10
private_only_run = false
5 changes: 4 additions & 1 deletion simbev/mid_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def get_empty_timeseries(start_date, end_date, step_size):
return pd.DataFrame([0] * len(date_range), index=date_range)


def get_profile_time_series(start_date, end_date, step_size, df):
def get_profile_time_series(start_date, end_date, step_size, df, seed):
"""
Returns a time series starting from the start date up until the end date filled with
week data chosen at random from the input DataFrame for each week.
Expand All @@ -238,6 +238,8 @@ def get_profile_time_series(start_date, end_date, step_size, df):
Step size of the simulation in minutes.
df : pd.DataFrame
The input DataFrame containing week data, where each entry with the same ID belongs to the same week.
seed : int
Seed for the random number generator.

Returns
-------
Expand All @@ -258,6 +260,7 @@ def get_profile_time_series(start_date, end_date, step_size, df):
week_start = start_date
time_step = 0
steps_per_day = 1440 / step_size
np.random.seed(seed)
while week_start <= end_date:
# Select a random ID from the input DataFrame

Expand Down
7 changes: 7 additions & 0 deletions simbev/simbev_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def __init__(self, data_dict, config_dict, name):
file_path_parts[-1]
] = pd.read_parquet(file_path)
self.scaling = config_dict["scaling"]
self.driving_profile_seed = config_dict["driving_profile_seed"]
# additional parameters
self.regions: List[Region] = []
self.created_region_types = {}
Expand Down Expand Up @@ -524,6 +525,8 @@ def run(self, region):
public_count = 0
for car_type_name, car_count in region.car_dict.items():
for car_number in range(car_count):
# Update driving profile seed
self.driving_profile_seed += 1
# Create new car
if "max_charging_capacity_slow" in self.tech_data.columns:
car_type = self.car_types[car_type_name]
Expand Down Expand Up @@ -607,6 +610,7 @@ def run(self, region):
self.input_data[region.region_type.rs3_type][
car_type_name.split("_")[-1]
],
self.driving_profile_seed,
)

if self.num_threads == 1:
Expand Down Expand Up @@ -1089,6 +1093,9 @@ def from_config(cls, config_path):
"basic", "consumption_factor_highway", fallback=1.0
),
"rng_seed": cfg["sim_params"].getint("seed", None),
"driving_profile_seed": cfg["sim_params"].getint(
"driving_profile_seed", None
),
"eta_cp": cfg.getfloat("basic", "eta_cp", fallback=1),
"start_date": start_date,
"end_date": end_date,
Expand Down