FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
seldon/src/main.cpp at main · seldon-code/seldon · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
seldon-code
/
seldon
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
7
Code
Issues
4
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
seldon
/
src
/
main.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
101 lines (88 loc) · 3.9 KB
Breadcrumbs
seldon
/
src
/
main.cpp
Copy path
File metadata and controls
101 lines (88 loc) · 3.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#
include
"
config_parser.hpp
"
#
include
"
models/DeGroot.hpp
"
#
include
"
models/DeffuantModel.hpp
"
#
include
"
models/InertialModel.hpp
"
#
include
"
simulation.hpp
"
#
include
<
fmt/format.h
>
#
include
<
fmt/ostream.h
>
#
include
<
argparse/argparse.hpp
>
#
include
<
filesystem
>
#
include
<
memory
>
#
include
<
models/ActivityDrivenModel.hpp
>
#
include
<
string
>
namespace
fs
=
std::filesystem;
int
main
(
int
argc,
char
* argv[] )
{
argparse::ArgumentParser
program
(
"
seldon
"
);
program.
add_argument
(
"
config_file
"
).
help
(
"
The config file to be used. Has to be in TOML format.
"
);
program.
add_argument
(
"
-o
"
,
"
--output
"
)
.
help
(
"
Specify the output directory. Defaults to `path/to/config_file/output`
"
);
program.
add_argument
(
"
-a
"
,
"
--agents
"
)
.
help
(
"
Specify initial agent opinions in a file. Overwrites TOML config.
"
);
program.
add_argument
(
"
-n
"
,
"
--network
"
).
help
(
"
Specify initial network in a file. Overwrites TOML config.
"
);
try
{
program.
parse_args
( argc, argv );
}
catch
(
const
std::runtime_error & err )
{
fmt::print
( stderr,
"
{}
\n
{}
"
, err.
what
(),
fmt::streamed
( program ) );
return
1
;
}
fs::path config_file_path = program.
get
<std::string>(
"
config_file
"
);
std::optional<std::string> agent_file = program.
present
<std::string>(
"
-a
"
);
std::optional<std::string> network_file = program.
present
<std::string>(
"
-n
"
);
std::optional<std::string> output_dir_path_cli = program.
present
<std::string>(
"
-o
"
);
fs::path output_dir_path = output_dir_path_cli.
value_or
(
fs::path
(
"
./output
"
) );
fmt::print
(
"
=================================================================
\n
"
);
fmt::print
(
"
Using input file: {}
\n
"
, config_file_path.
string
() );
fmt::print
(
"
Output directory path set to: {}
\n
"
, output_dir_path.
string
() );
fs::create_directories
( output_dir_path );
//
Create the output directory
auto
simulation_options =
Seldon::Config::parse_config_file
( config_file_path.
string
() );
Seldon::Config::validate_settings
( simulation_options );
Seldon::Config::print_settings
( simulation_options );
if
( network_file.
has_value
() )
{
fmt::print
(
"
Reading network from file {}
\n
"
, network_file.
value
() );
}
if
( agent_file.
has_value
() )
{
fmt::print
(
"
Reading agents from file {}
\n
"
, agent_file.
value
() );
}
std::unique_ptr<Seldon::SimulationInterface> simulation;
if
( simulation_options.
model
== Seldon::Config::Model::DeGroot )
{
simulation = std::make_unique<Seldon::Simulation<Seldon::DeGrootModel::AgentT>>(
simulation_options, network_file, agent_file );
}
else
if
( simulation_options.
model
== Seldon::Config::Model::ActivityDrivenModel )
{
simulation = std::make_unique<Seldon::Simulation<Seldon::ActivityDrivenModel::AgentT>>(
simulation_options, network_file, agent_file );
}
else
if
( simulation_options.
model
== Seldon::Config::Model::ActivityDrivenInertial )
{
simulation = std::make_unique<Seldon::Simulation<Seldon::InertialModel::AgentT>>(
simulation_options, network_file, agent_file );
}
else
if
( simulation_options.
model
== Seldon::Config::Model::DeffuantModel )
{
auto
model_settings = std::get<Seldon::Config::DeffuantSettings>( simulation_options.
model_settings
);
if
( model_settings.
use_binary_vector
)
{
simulation = std::make_unique<Seldon::Simulation<Seldon::DeffuantModelVector::AgentT>>(
simulation_options, network_file, agent_file );
}
else
{
simulation = std::make_unique<Seldon::Simulation<Seldon::DeffuantModel::AgentT>>(
simulation_options, network_file, agent_file );
}
}
else
{
throw
std::runtime_error
(
"
Model has not been created
"
);
}
simulation->
run
( output_dir_path );
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL