Skip to content

packages/engine/scram-node/src/event_tree_analysis.h

Event tree analysis facilities.

Namespaces

Name
scram
scram::core

Classes

Name
classscram::core::EventTreeAnalysis <br>Event tree analysis functionality.
structscram::core::EventTreeAnalysis::Result <br>The analysis results binding to the unique analysis target.

Source code

cpp
/*
 * Copyright (C) 2014-2018 Olzhas Rakhimov
 * Copyright (C) 2023 OpenPRA ORG Inc.
 *
 * 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
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "analysis.h"
#include "event.h"
#include "event_tree.h"
#include "expression.h"
#include "expression/test_event.h"
#include "settings.h"

namespace scram::core {

class EventTreeAnalysis : public Analysis {
 public:
  struct Result {
    const mef::Sequence& sequence;  
    std::unique_ptr<mef::Gate> gate;  
    bool is_expression_only;  
    double p_sequence;  
  };

  EventTreeAnalysis(const mef::InitiatingEvent& initiating_event,
                    const Settings& settings, mef::Context* context);

  void Analyze() noexcept;

  const mef::InitiatingEvent& initiating_event() const {
    return initiating_event_;
  }

  const std::vector<Result>& sequences() const { return sequences_; }
  std::vector<Result>& sequences() { return sequences_; }

 private:
  struct PathCollector {
    PathCollector() = default;
    PathCollector(const PathCollector&);  
    std::vector<mef::Expression*> expressions;  
    std::vector<mef::FormulaPtr> formulas;  
    std::unordered_map<std::string, bool> set_instructions;  
  };

  struct SequenceCollector {
    const mef::InitiatingEvent& initiating_event;  
    mef::Context& context;  
    std::unordered_map<const mef::Sequence*, std::vector<PathCollector>>
        sequences;
  };

  void CollectSequences(const mef::Branch& initial_state,
                        SequenceCollector* result) noexcept;

  const mef::InitiatingEvent& initiating_event_;  
  std::vector<Result> sequences_;  
  std::vector<std::unique_ptr<mef::Expression>> expressions_;
  std::vector<std::unique_ptr<mef::Event>> events_;  
  mef::Context* context_;  
};

}  // namespace scram::core

Updated on 2025-11-11 at 16:51:08 +0000