29 #include <boost/property_tree/ptree.hpp> 30 #include <tclap/CmdLine.h> 39 using namespace TCLAP;
43 int main(
int argc,
char** argv)
45 int exitStatus = EXIT_SUCCESS;
51 CmdLine cmd(
"stride",
' ',
"1.0");
53 string sa =
"Stochastic Analysis (stan) will run <COUNT> simulations, each with a " 54 "different seed for the random engine. Only applies in case of -e sim. ";
55 ValueArg<unsigned int> stanArg(
"",
"stan", sa,
false, 0,
"COUNT", cmd);
57 string si =
"File are read from the appropriate (config, data) directories of the " 58 "stride install directory. If false, files are read and written to the " 59 "local directory. \nDefaults to true.";
60 SwitchArg installedArg(
"i",
"installed", si, cmd,
true);
62 string so =
"Override configuration file parameters with values provided here.";
63 MultiArg<string> overrideArg(
"o",
"override", so,
false,
"<NAME>=<VALUE>", cmd);
65 string sc =
"Specifies the run configuration parameters. The format may be " 66 "either -c file=<file> or -c name=<name>. The first is mostly " 67 "used and may be shortened to -c <file>. The second refers to " 68 "built-in configurations specified by their name." 69 "\nDefaults to -c file=run_default.xml";
70 ValueArg<string> configArg(
"c",
"config", sc,
false,
"run_default.xml",
"CONFIGURATION", cmd);
72 vector<string> execs{
"clean",
"dump",
"sim",
"genpop"};
73 ValuesConstraint<string> vc(execs);
74 string se =
"Execute the corresponding function:" 75 " \n\t clean: cleans configuration and writes it to a new file." 76 " \n\t dump: takes built-in configuration writes it to a file." 77 " \n\t sim: runs the simulator and is the default." 78 " \n\t genpop: generates geo-based population to file (no sim)" 79 "\nDefaults to --exec sim.";
80 ValueArg<string> execArg(
"e",
"exec", se,
false,
"sim", &vc, cmd);
82 cmd.parse(argc, static_cast<const char* const*>(argv));
87 auto config = configArg.getValue();
90 if (regex_search(config, regex(
"^name="))) {
91 config = regex_replace(config, regex(
string(
"^name=")),
string(
""));
92 configPt = RunConfigManager::Create(config);
94 config = regex_replace(config, regex(
string(
"^file=")),
string(
""));
95 const filesys::path configPath =
96 (installedArg.getValue()) ? FileSys::GetConfigDir() /= config : filesys::path(config);
97 configPt = FileSys::ReadPtreeFile(configPath);
100 for (
const auto& p_assignment : overrideArg.getValue()) {
102 configPt.put(
"run." + v[0], v[1]);
108 if (execArg.getValue() ==
"sim" || execArg.getValue() ==
"genpop") {
109 if (configPt.get<
string>(
"run.output_prefix",
"").empty()) {
110 configPt.put(
"run.output_prefix",
TimeStamp().ToTag().append(
"/"));
112 if (stanArg.isSet()) {
113 configPt.put(
"run.stan_count", stanArg.getValue());
117 if (execArg.getValue() ==
"sim") {
118 if (!stanArg.isSet()) {
131 else if (execArg.getValue() ==
"clean" || execArg.getValue() ==
"dump") {
132 RunConfigManager::CleanConfigFile(configPt);
134 }
catch (exception& e) {
135 exitStatus = EXIT_FAILURE;
136 cerr <<
"\nEXCEPION THROWN: " << e.what() << endl;
138 exitStatus = EXIT_FAILURE;
139 cerr <<
"\nEXCEPION THROWN: Unknown exception." << endl;
void Control()
Actual run of the simulator.
Controls a geo-population generation run initiated with the command line interface (cli)...
Header for the command line controller.
void Control()
Control the execution of the simulation.
Utilities for the project.
int main(int argc, char **argv)
Main program of the stride simulator.
Runs a simulation multiple times, with different random engine seeds.
Provides wall-clock time stamp using the time call.
std::vector< std::string > Tokenize(const std::string &str, const std::string &delimiters)
Tokenize a string (in order of occurence) with the given delimiters.
Header for the command line controller.
Header for the St(ochastic)an(alysis)Controller.
Produce run config ptree.
Miscellaneous string utilities.
Interface for install directory queries.
Namespace for the simulator and related classes.
Controls a simulation run initiated with the command line interface (cli).
void Control()
Actual run of the simulator.