diff --git a/include/config_parser.hpp b/include/config_parser.hpp index 86f63bb..48f14e5 100644 --- a/include/config_parser.hpp +++ b/include/config_parser.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -102,7 +103,7 @@ struct SimulationOptions = std::variant; Model model; std::string model_string; - int rng_seed = std::random_device()(); + int64_t rng_seed = std::random_device()(); OutputSettings output_settings; ModelVariantT model_settings; InitialNetworkSettings network_settings; diff --git a/include/network.hpp b/include/network.hpp index 8056b62..4f268ce 100644 --- a/include/network.hpp +++ b/include/network.hpp @@ -58,6 +58,16 @@ class Network { } + Network( + const std::vector> & neighbour_list, const std::vector> & weight_list, + EdgeDirection direction ) + : agents( std::vector( neighbour_list.size() ) ), + neighbour_list( neighbour_list ), + weight_list( weight_list ), + _direction( direction ) + { + } + Network( std::vector> && neighbour_list, std::vector> && weight_list, EdgeDirection direction ) diff --git a/src/config_parser.cpp b/src/config_parser.cpp index 57e384f..a674cc5 100644 --- a/src/config_parser.cpp +++ b/src/config_parser.cpp @@ -113,7 +113,7 @@ SimulationOptions parse_config_file( std::string_view config_file_path ) toml::table tbl; tbl = toml::parse_file( config_file_path ); - options.rng_seed = tbl["simulation"]["rng_seed"].value_or( int( options.rng_seed ) ); + options.rng_seed = tbl["simulation"]["rng_seed"].value_or( int64_t( options.rng_seed ) ); // Parse output settings options.output_settings.n_output_network = tbl["io"]["n_output_network"].value(); diff --git a/test/test_io.cpp b/test/test_io.cpp index f49ab58..1934047 100644 --- a/test/test_io.cpp +++ b/test/test_io.cpp @@ -3,6 +3,7 @@ #include "models/ActivityDrivenModel.hpp" #include "network.hpp" #include "network_generation.hpp" +#include "network_io.hpp" #include #include @@ -38,6 +39,38 @@ TEST_CASE( "Test reading in the network from a file", "[io_network]" ) } } +TEST_CASE( "Test writing the network to a file", "[io_network]" ) +{ + using namespace Seldon; + using namespace Catch::Matchers; + using AgentT = ActivityDrivenModel::AgentT; + using Network = Network; + + std::vector> neighbours = { { 3, 1 }, {}, { 1 } }; + std::vector> weights = { { -0.1, -0.5 }, {}, { -0.2 } }; + + // Construct a network + auto network = Network( neighbours, weights, Network::EdgeDirection::Incoming ); + + // Save the network to a file + auto proj_root_path = fs::current_path(); + auto network_file = proj_root_path / fs::path( "test/network_out.txt" ); + network_to_file( network, network_file ); + + // Read the network back in + auto network_from_file = Seldon::NetworkGeneration::generate_from_file( network_file ); + + for( size_t i = 0; i < network.n_agents(); i++ ) + { + fmt::print( "{}", i ); + REQUIRE_THAT( + network.get_neighbours( i ), + Catch::Matchers::UnorderedRangeEquals( network_from_file.get_neighbours( i ) ) ); + REQUIRE_THAT( + network.get_weights( i ), Catch::Matchers::UnorderedRangeEquals( network_from_file.get_weights( i ) ) ); + } +} + TEST_CASE( "Test reading in the agents from a file", "[io_agents]" ) { using namespace Seldon;