Skip to content

Commit

Permalink
Implements importance measures and template test systems. (#21)
Browse files Browse the repository at this point in the history
* Implements importance measures and template test systems.

+ Adds Criticality Calculator, which calculates the failure and repair criticalities
+ Adds ABGT, BAGT, BarlowProschan, Birnbaun, Andrews Beeson Birnbaum, RAW, RRW and Vaurio importance measures
+ Adds customizable test systems for TMR, BridgeSystem and SeriesParallelSystem
+ Adds example systems for a time consistent, non coherent system a time inconsistent, non coherent system
* Modifies DensityFunction to work on all functions, not just ReliabilityFunctions

* Adds missing unit tests.

+ Adds unit tests to cover all BAGT variants
* Moves BarlowProschanFunction to its own nested class to improve testability
+ Adds unit test to cover BarlowProschanFunction
- Removes unused class.

* Adds missing files from previous commit.

* Increases coverage for unit tests on test systems.
  • Loading branch information
HOehmen committed Feb 10, 2021
1 parent 39e53f4 commit 4cef034
Show file tree
Hide file tree
Showing 36 changed files with 3,905 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/main/java/org/jreliability/function/DensityFunction.java
Expand Up @@ -17,28 +17,28 @@

/**
* The {@link DensityFunction} determines the density {@code f(x)} of a
* {@link ReliabilityFunction} {@code R(x)}.
* {@link Function} {@code F(x)}.
*
* @author glass
*
*/
public class DensityFunction {

/**
* The {@link ReliabilityFunction} for which the {@link DensityFunction} is
* The {@link Function} for which the {@link DensityFunction} is
* to determine.
*/
protected final ReliabilityFunction reliabilityFunction;
protected final Function function;

/**
* Constructs a {@link DensityFunction} with a given
* {@link ReliabilityFunction}.
* {@link Function}.
*
* @param reliabilityFunction
* the reliabilityFunction
* @param function
* the function
*/
public DensityFunction(ReliabilityFunction reliabilityFunction) {
this.reliabilityFunction = reliabilityFunction;
public DensityFunction(Function function) {
this.function = function;
}

/**
Expand All @@ -50,9 +50,9 @@ public DensityFunction(ReliabilityFunction reliabilityFunction) {
*/
public double getY(double x) {
double deltaT = 0.00000001;
double y = reliabilityFunction.getY(x);
double yPrime = reliabilityFunction.getY(x + deltaT);
double density = (y - yPrime) / deltaT;
double y = function.getY(x);
double yPrime = function.getY(x + deltaT);
double density = Math.abs(y - yPrime) / deltaT;
return density;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jreliability/function/Function.java
Expand Up @@ -39,7 +39,7 @@ public interface Function {
*
* @param xs
* the list of values
* @return the list of y values for each xØÏ
* @return the list of y values for each x
*/
public List<Double> getY(List<Double> xs);

Expand Down
98 changes: 98 additions & 0 deletions src/main/java/org/jreliability/importancemeasures/ABGT.java
@@ -0,0 +1,98 @@
/*******************************************************************************
* JReliability is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* JReliability 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JReliability. If not, see http://www.gnu.org/licenses/.
*******************************************************************************/

package org.jreliability.importancemeasures;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.collections15.Transformer;
import org.jreliability.bdd.BDD;
import org.jreliability.bdd.BDDTTRF;
import org.jreliability.function.ReliabilityFunction;


/**
* The {@link ABGT} class calculates the ABGT importance for coherent and non-coherent systems
* proposed by [ABGT17].
*
* [ABGT17] ( https://doi.org/10.1016/j.ress.2016.12.013 )
*
* @author oehmen
*
* @param <T>
* The type of the variables of the {@link BDD} of the system
*/
public class ABGT<T> implements TimeDependentImportanceMeasure<T> {
protected final BDD<T> bdd;
protected final Transformer<T, ReliabilityFunction> transformer;
protected final BDDTTRF<T> bddTTRF;
protected final CriticalityCalculator<T> critCalc;

/**
* Returns a {@link ABGT} calculator for a specific system with its {@link BDD}
* and {@link ReliabilityFunction} {@link Transformer}.
*
* @param bdd
* The {@link BDD} representing the system structure function
*
* @param transformer
* The {@link Transformer} used to get the {@link ReliabilityFunction} of
* variables present in the {@link BDD}
*/
public ABGT(BDD<T> bdd, Transformer<T, ReliabilityFunction> transformer) {
this.bdd = bdd;
this.transformer = transformer;
bddTTRF = new BDDTTRF<>(bdd.getProvider());

critCalc = new CriticalityCalculator<>(bdd, transformer);
}

/**
* Calculates the ABGT importances for all components at the specified time.
*
* Uses equation 15 and 23 of [ABGT17] to calculate the importance from the failure
* and repair {@link CriticalityBDDs} of the components.
*
* @param time
* Time t at which the ABGT importance of all components is calculated.
* Must be greater than 0, otherwise an IllegalArgumentException is thrown.
*
* @return results
* Map of components and their respective ABGT importance
* at time t.
*/
public Map<T, Double> calculate(double time) {
Map<T, Double> results = new HashMap<>();

if (time <= 0) {
throw new IllegalArgumentException("Importance measure not defined for time <= 0.");
}

for (T var: bdd.getVariables()) {
CriticalityBDDs<T> critBdds = critCalc.getCriticalityBDDs(var);

/* Equation 15 of [ABGT17] */
BDD<T> abgtBdd = critBdds.getFailureCriticalityBDD().or(critBdds.getRepairCriticalityBdd());

/* Equation 23 of [ABGT17] */
double abgt_im = bddTTRF.convert(abgtBdd, transformer).getY(time);

results.put(var, abgt_im);
}

return results;
}
}
126 changes: 126 additions & 0 deletions src/main/java/org/jreliability/importancemeasures/BAGT.java
@@ -0,0 +1,126 @@
/*******************************************************************************
* JReliability is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* JReliability 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JReliability. If not, see http://www.gnu.org/licenses/.
*******************************************************************************/

package org.jreliability.importancemeasures;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.collections15.Transformer;
import org.jreliability.bdd.BDD;
import org.jreliability.bdd.BDDProvider;
import org.jreliability.bdd.BDDTTRF;
import org.jreliability.evaluator.MomentEvaluator;
import org.jreliability.function.ReliabilityFunction;


/**
* The {@link BAGT} class calculates the time-independent importance of components
* proposed by [BAGT16].
*
* [BAGT16] ( https://doi.org/10.1016/j.ejor.2016.03.054 )
*
* @author oehmen
*
* @param <T>
* The type of the variables of the {@link BDD} of the system
*/
public class BAGT<T> implements ImportanceMeasure {
protected final BDD<T> bdd;
protected final Transformer<T, ReliabilityFunction> transformer;
protected final BDDProvider<T> provider;
protected final BDDTTRF<T> bddTTRF;
protected final MomentEvaluator moment;

protected final double mttf;

public enum Variant {
MINUS,
PLUS,
MINUS_NORMALIZED,
PLUS_NORMALIZED
}

/**
* Returns a {@link BAGT} calculator for a specific system with its {@link BDD}
* and {@link ReliabilityFunction} {@link Transformer}.
*
* @param bdd
* The {@link BDD} representing the system structure function
*
* @param transformer
* The {@link Transformer} used to get the {@link ReliabilityFunction} of
* variables present in the {@link BDD}
*/
public BAGT(BDD<T> bdd, Transformer<T, ReliabilityFunction> transformer) {
this.bdd = bdd;
this.transformer = transformer;
provider = bdd.getProvider();
bddTTRF = new BDDTTRF<>(provider);
moment = new MomentEvaluator(1);

/* bddTTRF deallocates the bdd parameter -> copy is needed */
mttf = moment.evaluate(bddTTRF.convert(bdd.copy(), transformer));
}

/**
* Calculates one of the BAGT importance measure variants.
*
* Note: This function might have infinite run times for some variants
* using non coherent systems. This is due to the {@link MomentEvaluator}
* having an infinite run time for the restricted reliability functions
* in those cases.
*
* @param variant
* The variant of BAGT to be calculated.
*
* @return results
* Map of components and their respective BAGT importance.
*
*/
public Map<T, Double> calculate(Variant variant) {
Map<T, Double> results = new HashMap<>();
BDD<T> restrictedBdd;
double bagt_im;

for (T var: bdd.getVariables()) {
if (variant == Variant.MINUS || variant == Variant.MINUS_NORMALIZED) {
restrictedBdd = bdd.restrict(provider.get(var).not()); /* Fix var to 0 ie. Component never works */
}
else {
restrictedBdd = bdd.restrict(provider.get(var)); /* Fix var to 1 ie. Component always works */
}

ReliabilityFunction restrictedReliability = bddTTRF.convert(restrictedBdd, transformer);

/* This will cause infinite run time for some cases (eg. BAGT+ of TCNC component 1 ) */
double restrictedMttf = moment.evaluate(restrictedReliability);

if (variant == Variant.MINUS_NORMALIZED || variant == Variant.PLUS_NORMALIZED) {
/* Equation 19 of [BAGT16] */
bagt_im = Math.abs(mttf - restrictedMttf) / mttf;
}
else {
/* Equation 18 of [BAGT16] */
bagt_im = Math.abs(mttf - restrictedMttf);
}

results.put(var, bagt_im);
}

return results;

}
}

0 comments on commit 4cef034

Please sign in to comment.