Skip to content

Commit

Permalink
IO: Optionally disable initial state outputs
Browse files Browse the repository at this point in the history
Now the user can optionally disable outputting the initial opinions
and network. By default, the initial opinions and network are always
printed.
  • Loading branch information
amritagos committed Mar 17, 2024
1 parent 7b38f6c commit 2ceece9
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/ActivityDriven/conf.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ model = "ActivityDriven"
n_output_network = 20 # Write the network every 20 iterations
n_output_agents = 1 # Write the opinions of agents after every iteration
print_progress = true # Print the iteration time ; if not set, then always print
print_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
start_print_iteration = 1 # Start printing opinions and/or network files from this iteration. If not set, this is 1.

[model]
Expand Down
1 change: 1 addition & 0 deletions examples/ActivityDrivenBot/conf.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rng_seed = 120 # Leaving this empty will pick a random seed
n_output_network = 1 # Write the network every 20 iterations
n_output_agents = 1 # Write the opinions of agents after every iteration
print_progress = true # Print the iteration time; if not set, then always print
print_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
start_print_iteration = 1 # Start printing opinions and/or network files from this iteration. If not set, this is 1.

[model]
Expand Down
1 change: 1 addition & 0 deletions examples/ActivityDrivenMeanField/conf.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rng_seed = 12345678 # Leaving this empty will pick a random seed
n_output_network = 20 # Write the network every 20 iterations
n_output_agents = 1 # Write the opinions of agents after every iteration
print_progress = true # Print the iteration time ; if not set, then always print
print_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
start_print_iteration = 1 # Start printing opinions and/or network files from this iteration. If not set, this is 1.

[model]
Expand Down
1 change: 1 addition & 0 deletions examples/DeGroot/conf.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ model = "DeGroot"
n_output_network = 20 # Write the network every 20 iterations
n_output_agents = 1 # Write the opinions of agents after every iteration
print_progress = false # Print the iteration time ; if not set, then always prints
print_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
start_print_iteration = 1 # Start printing opinions and/or network files from this iteration. If not set, this is 1.

[model]
Expand Down
1 change: 1 addition & 0 deletions include/config_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct OutputSettings
std::optional<size_t> n_output_agents = std::nullopt;
std::optional<size_t> n_output_network = std::nullopt;
bool print_progress = true; // Print the iteration time, by default always prints
bool print_initial = true; // Output initial opinions and network, by default always outputs.
int start_print_iteration = 1; // Start printing opinion and/or network files from this iteration number
};

Expand Down
11 changes: 7 additions & 4 deletions include/simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,18 @@ class Simulation : public SimulationInterface
auto n_output_agents = this->output_settings.n_output_agents;
auto n_output_network = this->output_settings.n_output_network;
auto print_iter_start = this->output_settings.start_print_iteration;
auto print_initial = this->output_settings.print_initial;

fmt::print( "-----------------------------------------------------------------\n" );
fmt::print( "Starting simulation\n" );
fmt::print( "-----------------------------------------------------------------\n" );

Seldon::IO::network_to_file( network, ( output_dir_path / fs::path( "network_0.txt" ) ).string() );
auto filename = fmt::format( "opinions_{}.txt", 0 );
Seldon::IO::opinions_to_file( network, ( output_dir_path / fs::path( filename ) ).string() );

if( print_initial )
{
Seldon::IO::network_to_file( network, ( output_dir_path / fs::path( "network_0.txt" ) ).string() );
auto filename = fmt::format( "opinions_{}.txt", 0 );
Seldon::IO::opinions_to_file( network, ( output_dir_path / fs::path( filename ) ).string() );
}
this->model->initialize_iterations();

typedef std::chrono::milliseconds ms;
Expand Down
2 changes: 2 additions & 0 deletions src/config_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ SimulationOptions parse_config_file( std::string_view config_file_path )
options.output_settings.n_output_agents = tbl["io"]["n_output_agents"].value<size_t>();
options.output_settings.print_progress
= tbl["io"]["print_progress"].value_or<bool>( bool( options.output_settings.print_progress ) );
options.output_settings.print_initial
= tbl["io"]["print_initial"].value_or<bool>( bool( options.output_settings.print_initial ) );
// @TODO: default value should not be hard-coded here
options.output_settings.start_print_iteration = tbl["io"]["start_print_iteration"].value_or<int>( 1 );

Expand Down

0 comments on commit 2ceece9

Please sign in to comment.