Skip to content

Commit

Permalink
Merge pull request #103 from bigladder/feature/print-random-seed
Browse files Browse the repository at this point in the history
Add feature to show random seed after run.
  • Loading branch information
michael-okeefe authored Nov 14, 2024
2 parents b4a0b14 + 667437e commit 255c1e1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/erin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ CLI::App* add_run(CLI::App& app)
static bool verbose = false;
subcommand->add_flag("-v,--verbose", verbose, "Verbose output");

static bool show_seed = false;
subcommand->add_flag("-k,--show_seed", show_seed, "Show random seed used for simulation");

static bool no_aggregate_groups = false;
subcommand->add_flag("-n,--no-group", no_aggregate_groups, "Suppress group aggregation");

Expand Down Expand Up @@ -164,7 +167,8 @@ CLI::App* add_run(CLI::App& app)
time_step_h,
aggregate_groups,
save_reliability_curves,
verbose);
verbose,
show_seed);
return EXIT_SUCCESS;
};

Expand Down
1 change: 1 addition & 0 deletions docs/examples/ft-illinois/exft-illinois.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rate_unit = "kW"
quantity_unit = "kJ"
time_unit = "hours"
max_time = 8760
random_seed = 17

# Distributions
[dist.immediately]
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/ft-illinois_packed/exft-illinois_packed.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rate_unit = "kW"
quantity_unit = "kJ"
time_unit = "hours"
max_time = 8760
random_seed = 17

# Distributions
[dist.immediately]
Expand Down Expand Up @@ -2183,4 +2184,4 @@ occurrence_distribution = "immediately"
duration = 408
max_occurrences = 1
calculate_reliability = false
intensity.wind_speed_mph = 80.0
intensity.wind_speed_mph = 80.0
3 changes: 2 additions & 1 deletion include/erin/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ void run(Simulation& s,
double time_step_h = -1.0,
bool aggregate_groups = true,
bool save_reliability_curves = false,
bool verbose = false);
bool verbose = false,
bool show_seed = false);

bool is_failure_name_unique(Simulation& s, std::string const& name);

Expand Down
37 changes: 36 additions & 1 deletion src/erin-simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2763,7 +2763,8 @@ void run(Simulation& s,
double time_step_h /*-1.0*/,
bool aggregateGroups,
bool saveReliabilityCurves,
bool verbose)
bool verbose,
bool show_seed)
{
// TODO: wrap into input options struct and pass in
bool const checkNetwork = false;
Expand Down Expand Up @@ -2793,25 +2794,59 @@ void run(Simulation& s,
{
fixedRandom.fixed_value = s.info.fixed_value;
s.the_model.random_function = fixedRandom;
if (show_seed)
{
std::cout << std::endl << "RANDOM_TYPE: fixed" << std::endl;
std::cout << "RANDOM_SEED: " << s.info.fixed_value << "\n";
}
}
break;
case (RandomType::fixed_series):
{
fixedSeries.index = 0;
fixedSeries.series = s.info.series;
s.the_model.random_function = fixedSeries;
if (show_seed)
{
std::cout << std::endl << "RANDOM_TYPE: fixed_series" << std::endl;
std::cout << "RANDOM_SEED: ";
bool is_first = true;
for (auto fixed_series_value : s.info.series)
{
if (is_first)
{
is_first = false;
}
else
{
std::cout << ", ";
}
std::cout << fixed_series_value;
}
std::cout << std::endl;
}
}
break;
case (RandomType::random_from_seed):
{
fullRandom = create_random_with_seed(s.info.seed);
s.the_model.random_function = fullRandom;
if (show_seed)
{
std::cout << std::endl << "RANDOM_TYPE: random_from_seed" << std::endl;
std::cout << "RANDOM_SEED: " << s.info.seed << std::endl;
}
}
break;
case (RandomType::random_from_clock):
{
fullRandom = create_random();
s.the_model.random_function = fullRandom;
if (show_seed)
{
std::cout << std::endl << "RANDOM_TYPE: random_from_clock" << std::endl;
std::cout << "RANDOM_SEED: " << fullRandom.seed << std::endl;
}
}
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/erin-validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ InputValidationMap setup_global_validation_info()
.input_type = InputType::integer,
.is_required = false,
.inform_if_missing = false,
.default_value = "17",
.default_value = "",
.enum_values = valid_time_units,
.aliases = {},
.sections =
Expand Down

0 comments on commit 255c1e1

Please sign in to comment.