Skip to content

Commit a6d5f69

Browse files
committed
Output settings: Allow renumbering of output files
Now you can set start_numbering_from to a value greater than or equal to zero. The output files will be renumbered starting from this value.
1 parent 78f1c92 commit a6d5f69

File tree

11 files changed

+35
-15
lines changed

11 files changed

+35
-15
lines changed

examples/ActivityDriven/conf.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ n_output_agents = 1 # Write the opinions of agents after every iteration
88
print_progress = true # Print the iteration time ; if not set, then does not print
99
output_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
1010
start_output = 2 # Start writing out opinions and/or network files from this iteration. If not set, this is 1.
11+
start_numbering_from = 0 # The initial step number, before the simulation runs, is this value. The first step would be (1+start_numbering_from). By default, 0
1112

1213
[model]
1314
max_iterations = 500 # If not set, max iterations is infinite

examples/ActivityDrivenBot/conf.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ rng_seed = 120 # Leaving this empty will pick a random seed
66
n_output_network = 1 # Write the network every 20 iterations
77
n_output_agents = 1 # Write the opinions of agents after every iteration
88
print_progress = true # Print the iteration time; if not set, then always print
9-
output_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
10-
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1.
9+
output_initial = true # Print the initial opinions and network file, before the simulation starts. If not set, this is true by default.
10+
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1 + start_numbering_from.
11+
start_numbering_from = 0 # The initial step number, before the simulation runs, is this value. The first step would be (1+start_numbering_from). By default, 0
1112

1213
[model]
1314
max_iterations = 1000 # If not set, max iterations is infinite

examples/ActivityDrivenInertial/conf.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ model = "ActivityDrivenInertial"
66
n_output_network = 20 # Write the network every 20 iterations
77
n_output_agents = 1 # Write the opinions of agents after every iteration
88
print_progress = true # Print the iteration time ; if not set, then does not print
9+
output_initial = true # Print the initial opinions and network file, before the simulation starts. If not set, this is true by default.
10+
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1.
11+
start_numbering_from = 0 # The initial step number, before the simulation runs, is this value. The first step would be (1+start_numbering_from). By default, 0
912

1013
[model]
1114
max_iterations = 500 # If not set, max iterations is infinite

examples/ActivityDrivenMeanField/conf.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ n_output_network = 20 # Write the network every 20 iterations
77
n_output_agents = 1 # Write the opinions of agents after every iteration
88
print_progress = true # Print the iteration time ; if not set, then does not print
99
output_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
10-
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1.
10+
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1 + start_numbering_from.
11+
start_numbering_from = 0 # The initial step number, before the simulation runs, is this value. The first step would be (1+start_numbering_from). By default, 0
1112

1213
[model]
1314
max_iterations = 2000 # If not set, max iterations is infinite

examples/ActivityDrivenReluctance/conf.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ model = "ActivityDriven"
66
n_output_network = 20 # Write the network every 20 iterations
77
n_output_agents = 1 # Write the opinions of agents after every iteration
88
print_progress = true # Print the iteration time ; if not set, then does not print
9+
output_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
10+
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1.
11+
start_numbering_from = 0 # The initial step number, before the simulation runs, is this value. The first step would be (1+start_numbering_from). By default, 0
912

1013
[model]
1114
max_iterations = 500 # If not set, max iterations is infinite

examples/DeGroot/conf.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ n_output_network = 20 # Write the network every 20 iterations
77
n_output_agents = 1 # Write the opinions of agents after every iteration
88
print_progress = false # Print the iteration time ; if not set, then does not prints
99
output_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
10-
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1.
10+
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1 + start_numbering_from.
11+
start_numbering_from = 0 # The initial step number, before the simulation runs, is this value. The first step would be (1+start_numbering_from). By default, 0
1112

1213
[model]
1314
max_iterations = 20 # If not set, max iterations is infinite

examples/Deffuant/conf.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ model = "Deffuant"
77
n_output_agents = 1 # Write the opinions of agents after every iteration
88
print_progress = true # Print the iteration time ; if not set, then does not prints
99
output_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
10-
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1.
10+
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1 + start_numbering_from.
11+
start_numbering_from = 0 # The initial step number, before the simulation runs, is this value. The first step would be (1+start_numbering_from). By default, 0
1112

1213
[model]
1314
max_iterations = 1000 # If not set, max iterations is infinite

examples/DeffuantVector/conf.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ model = "Deffuant"
77
n_output_agents = 1 # Write the opinions of agents after every iteration
88
print_progress = true # Print the iteration time ; if not set, then does not print
99
output_initial = true # Print the initial opinions and network file from step 0. If not set, this is true by default.
10-
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1.
10+
start_output = 1 # Start writing out opinions and/or network files from this iteration. If not set, this is 1 + start_numbering_from.
11+
start_numbering_from = 0 # The initial step number, before the simulation runs, is this value. The first step would be (1+start_numbering_from). By default, 0
1112

1213
[model]
1314
max_iterations = 1000 # If not set, max iterations is infinite

include/config_parser.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ struct OutputSettings
3636
std::optional<size_t> n_output_network = std::nullopt;
3737
bool print_progress = false; // Print the iteration time, by default does not print
3838
bool output_initial = true; // Output initial opinions and network, by default always outputs.
39-
size_t start_output = 1; // Start printing opinion and/or network files from this iteration number
39+
size_t start_output = 1; // Start printing opinion and/or network files from this iteration number
40+
size_t start_numbering_from = 0; // The initial step number, before the simulation runs, is this value. The first
41+
// step would be (1+start_numbering_from). By default, 0
4042
};
4143

4244
struct DeGrootSettings

include/simulation.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,22 @@ class Simulation : public SimulationInterface
107107

108108
void run( const fs::path & output_dir_path ) override
109109
{
110-
auto n_output_agents = this->output_settings.n_output_agents;
111-
auto n_output_network = this->output_settings.n_output_network;
112-
auto start_output = this->output_settings.start_output;
113-
auto output_initial = this->output_settings.output_initial;
110+
auto n_output_agents = this->output_settings.n_output_agents;
111+
auto n_output_network = this->output_settings.n_output_network;
112+
auto start_output = this->output_settings.start_output;
113+
auto initial_step_number = this->output_settings.start_numbering_from;
114+
auto output_initial = this->output_settings.output_initial;
114115

115116
fmt::print( "-----------------------------------------------------------------\n" );
116117
fmt::print( "Starting simulation\n" );
117118
fmt::print( "-----------------------------------------------------------------\n" );
118119

119120
if( output_initial )
120121
{
121-
Seldon::network_to_file( network, ( output_dir_path / fs::path( "network_0.txt" ) ).string() );
122-
auto filename = fmt::format( "opinions_{}.txt", 0 );
122+
Seldon::network_to_file(
123+
network,
124+
( output_dir_path / fs::path( fmt::format( "network_{}.txt", initial_step_number ) ) ).string() );
125+
auto filename = fmt::format( "opinions_{}.txt", initial_step_number );
123126
Seldon::agents_to_file( network, ( output_dir_path / fs::path( filename ) ).string() );
124127
}
125128
this->model->initialize_iterations();
@@ -147,15 +150,15 @@ class Simulation : public SimulationInterface
147150
if( n_output_agents.has_value() && ( this->model->n_iterations() >= start_output )
148151
&& ( this->model->n_iterations() % n_output_agents.value() == 0 ) )
149152
{
150-
auto filename = fmt::format( "opinions_{}.txt", this->model->n_iterations() );
153+
auto filename = fmt::format( "opinions_{}.txt", this->model->n_iterations() + initial_step_number );
151154
Seldon::agents_to_file( network, ( output_dir_path / fs::path( filename ) ).string() );
152155
}
153156

154157
// Write out the network?
155158
if( n_output_network.has_value() && ( this->model->n_iterations() >= start_output )
156159
&& ( this->model->n_iterations() % n_output_network.value() == 0 ) )
157160
{
158-
auto filename = fmt::format( "network_{}.txt", this->model->n_iterations() );
161+
auto filename = fmt::format( "network_{}.txt", this->model->n_iterations() + initial_step_number );
159162
Seldon::network_to_file( network, ( output_dir_path / fs::path( filename ) ).string() );
160163
}
161164
}

0 commit comments

Comments
 (0)