Skip to content

Commit

Permalink
Support running scenarios (#51)
Browse files Browse the repository at this point in the history
Closes #42.
  • Loading branch information
kyllingstad committed Mar 12, 2020
1 parent 2606756 commit 66d479f
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <boost/filesystem.hpp>
#include <cse/cse_config_parser.hpp>
#include <cse/manipulator/scenario_manager.hpp>
#include <cse/model.hpp>
#include <cse/observer/file_observer.hpp>
#include <cse/observer/observer.hpp>
#include <cse/orchestration.hpp>
Expand Down Expand Up @@ -36,7 +38,15 @@ void run_subcommand::setup_options(
"'none' disables file output altogether.")
("output-dir",
boost::program_options::value<std::string>()->default_value("."),
"The path to a directory for storing simulation results.");
"The path to a directory for storing simulation results.")
("scenario",
boost::program_options::value<std::string>(),
"The path to a scenario file to run. "
"By default, no scenario is run.")
("scenario-start",
boost::program_options::value<double>()->default_value(0.0),
"The logical time at which the scenario will start. "
"Only used if --scenario is specified.");
positionalOptions.add_options()
("system_structure_path",
boost::program_options::value<std::string>()->required(),
Expand Down Expand Up @@ -94,6 +104,17 @@ std::unique_ptr<cse::observer> make_file_observer(
}


void load_scenario(
cse::execution& execution,
const boost::filesystem::path& scenarioPath,
cse::time_point startTime)
{
auto s = std::make_shared<cse::scenario_manager>();
execution.add_manipulator(s);
s->load_scenario(scenarioPath, startTime);
}


class progress_monitor : public cse::observer
{
public:
Expand Down Expand Up @@ -155,6 +176,13 @@ int run_subcommand::run(const boost::program_options::variables_map& args) const
systemStructurePath);
if (outputObserver) execution.add_observer(std::move(outputObserver));

if (args.count("scenario")) {
load_scenario(
execution,
args["scenario"].as<std::string>(),
cse::to_time_point(args["scenario-start"].as<double>()));
}

execution.add_observer(
std::make_shared<progress_monitor>(
runOptions.begin_time,
Expand Down

0 comments on commit 66d479f

Please sign in to comment.