Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test code refs #126 #291

Draft
wants to merge 10 commits into
base: devel
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update quanticationUtils.h Ref #126
1. make macro #define a method
2. remove all commented sections
3. remove banned keywords
  • Loading branch information
Hugo Nie authored Mar 30, 2020
commit 0c8e507420b1ae95ea469bb76de341b1aad7a13f
89 changes: 70 additions & 19 deletions include/utils/QuantificationUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
#include "FaultTreeUtils.h"
#include "MastodonUtils.h"

/********************* Quantification Definition *********************/

class FTAUtils::Quantification
{
public:
enum _dist_t
{
PE,
EXP,
GAMMA,
PE, // = 0
EXP, // = 1
GAMMA, // = 2
WEIBULL,
EXTREME,
NORM,
Expand All @@ -26,8 +27,8 @@ class FTAUtils::Quantification

enum _analysis_t
{
FRAGILITY,
RISK
FRAGILITY, // = 0
RISK // = 1
};

Quantification(std::map<std::string, vector_double> & params_double,
Expand Down Expand Up @@ -63,6 +64,7 @@ class FTAUtils::Quantification
std::vector<double> vec;
vec.clear();

// Remove all INF from vector
for (int index = 0; index < vec_in.size(); index++)
{
if (!std::isinf(vec_in[index]))
Expand All @@ -73,6 +75,7 @@ class FTAUtils::Quantification

int size = vec.size();

// ASSERT
if (!(size > 0))
{
fprintf(stderr,
Expand All @@ -86,6 +89,8 @@ class FTAUtils::Quantification

_pe = vec[0];

// TODO: Remove 0th element from further calculations
// vec.erase( vec.begin() );

sort(vec.begin(), vec.end());
_mean = accumulate(vec.begin(), vec.end(), 0.0) / size;
Expand Down Expand Up @@ -114,7 +119,8 @@ class FTAUtils::Quantification
}
};


// TODO: 3 of the following are not supported as they need 1 arg rather than 2
// for their distribution. Remove these 3 if not needed else add support
std::map<std::string, _dist_t> _str2dist = {
{"GAMMA", GAMMA},
{"WEIBULL", WEIBULL},
Expand All @@ -129,7 +135,11 @@ class FTAUtils::Quantification
vector_double _cut_set_prob;
std::map<std::string, std::vector<double>> _b_nodes;


/**
* Generates probability vector for a specified distribution
* Nomenclature of a and b changes with distribution.
* eg., a => mean, b => std for NORM
*/
std::vector<double> getProbVector(_dist_t dist,
double a,
double b,
Expand All @@ -139,15 +149,20 @@ class FTAUtils::Quantification
_analysis_t analysis,
bool uc);


/**
* Parses and floods probabilties of basic elements
*/
vector_string beProb(FTAUtils::Parser parser,
int n_sample,
int seed,
_analysis_t analysis,
std::vector<double> intmes,
bool uncert);


/**
* Computes probability for a given cut set on a per set basis based on
* pre-flooded basic elem probs
*/
vector_double computeCutSetProb(std::set<std::set<std::string>> cut_sets,
int n,
bool bypass = false,
Expand All @@ -161,40 +176,76 @@ class FTAUtils::Quantification
std::string bypass_key = "",
double bypass_value = 0);


/**
* Computes accumulated probability for the entire cut set
* 3 Digests are computed:
* 0. Min Max
* 1. Upper Bound
* 2. Top Rare
*
* NOTE
* 1. Its better to compute these 2 together as they have common loops
* which can save time
* 2. Sets the vector cutSetProb
*/
std::vector<double> *
cutSetProbWDigest(std::set<std::set<std::string>> cut_sets, int n, bool only_min_max = false);


/**
* Wrapper function for gate probability arith
* AND => a * b
* OR => (1 - a) * (1 - b)
*/
double getGateProb(double a, double b, bool is_and);


/**
* Computes cut-set Fussel-Vesely Important measures
*/
vector_double minCutIM(std::vector<double> upperBound);


/**
* For each basic element:
* 1. Calculate #occurrence in minimal cut set (beCount)
* 2. Store row index of all occurrence (beIndex)
*/
std::map<std::string, vector_double> beIM(std::set<std::set<std::string>> cut_sets,
int n,
std::vector<double> upper_bound,
std::vector<int> & count_v);


/**
* Translator function for string -> double
*/
vector_double linesToDouble(vector_string lines);


/**
* Function for getting BIN mean values of intensity measure
*/
std::vector<double> getBinMeans(double im_lower, double im_upper, int n_bins);


/**
* Function for interpolating the hazard curve based on range of intensity
* measures
*/
std::vector<double> hazInterp(vector_double hazard, std::vector<double> im_bins);


/**
* Function for top event fragility
*/
std::vector<double> fragility(std::set<std::set<std::string>> cut_sets,
int n,
std::vector<double> im_bins,
double & mu,
double & sigma);


/**
* Function for calculating risk by convoluting hazard and fragility
* Assign risk to basic event probabilites
*
* WARNING
* This consumes _b_nodes and then overwrites it
*/
void computeRisk(int n, std::vector<double> hazard);
};

#endif
#endif // _QUANTIFICATION_H