Skip to content

Commit

Permalink
Adjust mission-time on alignment phases
Browse files Browse the repository at this point in the history
The mission time is adjusted according to the phase time-fractions.
This approach assumes memoryless system with tests on phase transitions.
In other words, the order of phases doesn't matter.
In fact, this is a quick-&-dirty way to analyze phases
without getting into complexity of Markov chains.

Issue #153
Closes #153
  • Loading branch information
rakhimov committed Aug 12, 2017
1 parent 636dab4 commit bf41b14
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/analysis.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2016 Olzhas Rakhimov
* Copyright (C) 2015-2017 Olzhas Rakhimov
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -23,8 +23,8 @@
namespace scram {
namespace core {

Analysis::Analysis(const Settings& settings)
: kSettings_(settings),
Analysis::Analysis(Settings settings)
: settings_(std::move(settings)),
analysis_time_(0) {}

Analysis::~Analysis() = default; ///< Pure virtual destructor.
Expand Down
11 changes: 7 additions & 4 deletions src/analysis.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2016 Olzhas Rakhimov
* Copyright (C) 2015-2017 Olzhas Rakhimov
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,12 +36,12 @@ namespace core {
class Analysis : private boost::noncopyable {
public:
/// @param[in] settings Analysis settings for all calculations.
explicit Analysis(const Settings& settings);
explicit Analysis(Settings settings);

virtual ~Analysis() = 0; ///< Abstract class.

/// @returns Analysis settings.
const Settings& settings() const { return kSettings_; }
const Settings& settings() const { return settings_; }

/// @returns Warnings generated upon analysis.
const std::string& warnings() const { return warnings_; }
Expand All @@ -50,6 +50,9 @@ class Analysis : private boost::noncopyable {
double analysis_time() const { return analysis_time_; }

protected:
/// @returns Modifiable analysis settings.
Settings& settings() { return settings_; }

/// Appends a warning message to the analysis warnings.
/// Warnings are separated by spaces.
///
Expand All @@ -68,7 +71,7 @@ class Analysis : private boost::noncopyable {
}

private:
const Settings kSettings_; ///< All settings for analysis.
Settings settings_; ///< All settings for analysis.
double analysis_time_; ///< Time taken by the analysis.
std::string warnings_; ///< Generated warnings in analysis.
};
Expand Down
15 changes: 13 additions & 2 deletions src/risk_analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,29 @@ void RiskAnalysis::Analyze() noexcept {
}
}

void RiskAnalysis::RunAnalysis(boost::optional<Context> context) {
void RiskAnalysis::RunAnalysis(boost::optional<Context> context) noexcept {
/// Restores the model after application of the context.
struct Restorator {
~Restorator() {
mission_time.first->value(mission_time.second);
settings.mission_time(mission_time.second);

for (const std::pair<mef::HouseEvent*, bool>& entry : house_events)
entry.first->state(entry.second);
}

Settings& settings;
std::pair<mef::MissionTime*, double> mission_time;
std::vector<std::pair<mef::HouseEvent*, bool>> house_events;
} restorator;
} restorator{Analysis::settings(),
{&model_->mission_time(), model_->mission_time().value()}};

if (context) {
double mission_time =
context->phase.time_fraction() * model_->mission_time().value();
model_->mission_time().value(mission_time);
Analysis::settings().mission_time(mission_time);

for (const mef::SetHouseEvent* instruction :
context->phase.instructions()) {
auto it = model_->house_events().find(instruction->name());
Expand Down
2 changes: 1 addition & 1 deletion src/risk_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class RiskAnalysis : public Analysis {
/// @pre The model is in pristine.
///
/// @post The model is restored to the original state.
void RunAnalysis(boost::optional<Context> context = {});
void RunAnalysis(boost::optional<Context> context = {}) noexcept;

/// Runs all possible analysis on a given target.
/// Analysis types are deduced from the settings.
Expand Down

0 comments on commit bf41b14

Please sign in to comment.