Skip to content

Commit 5cfaf37

Browse files
committed
initial solution to integrate structure function
1 parent c9dc9f5 commit 5cfaf37

3 files changed

Lines changed: 119 additions & 12 deletions

File tree

src/main/java/org/jreliability/bdd/BDDReliabilityFunction.java

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515

1616
package org.jreliability.bdd;
1717

18+
import java.util.ArrayList;
19+
import java.util.List;
20+
import java.util.Map;
21+
1822
import org.apache.commons.collections15.Transformer;
23+
import org.jreliability.booleanfunction.Term;
24+
import org.jreliability.booleanfunction.common.ANDTerm;
25+
import org.jreliability.booleanfunction.common.LiteralTerm;
26+
import org.jreliability.booleanfunction.common.NOTTerm;
27+
import org.jreliability.common.StructureFunction;
1928
import org.jreliability.function.ReliabilityFunction;
2029
import org.jreliability.function.SequentialFunction;
2130
import org.jreliability.function.UnreliabilityFunction;
@@ -26,19 +35,18 @@
2635
*
2736
* @author glass
2837
*
29-
* @param <T>
30-
* the type of variable
38+
* @param <T> the type of variable
3139
*/
32-
public class BDDReliabilityFunction<T> extends SequentialFunction implements ReliabilityFunction {
40+
public class BDDReliabilityFunction<T> extends SequentialFunction implements ReliabilityFunction, StructureFunction<T> {
3341

3442
/**
3543
* The BDD representing the {@link UnreliabilityFunction}.
3644
*/
3745
protected final BDD<T> bdd;
3846

3947
/**
40-
* The used {@link Transformer} to get the {@link ReliabilityFunction} of
41-
* each element of the {@link BDD}.
48+
* The used {@link Transformer} to get the {@link ReliabilityFunction} of each
49+
* element of the {@link BDD}.
4250
*/
4351
protected final Transformer<T, ReliabilityFunction> functionTransformer;
4452

@@ -51,12 +59,10 @@ public class BDDReliabilityFunction<T> extends SequentialFunction implements Rel
5159
* Constructs a {@link BDDReliabilityFunction} with a given {@link BDD} and
5260
* {@link Transformer}.
5361
*
54-
* @param bdd
55-
* the bdd representing the reliabilityFunction
62+
* @param bdd the bdd representing the reliabilityFunction
5663
*
57-
* @param functionTransformer
58-
* the functionTransformer to transform bdd elements to
59-
* reliabilityFunction
64+
* @param functionTransformer the functionTransformer to transform bdd elements
65+
* to reliabilityFunction
6066
*/
6167
public BDDReliabilityFunction(BDD<T> bdd, Transformer<T, ReliabilityFunction> functionTransformer) {
6268
super();
@@ -77,8 +83,7 @@ public double getY(final double x) {
7783
/**
7884
* Default {@link Transformer}.
7985
*
80-
* @param a
81-
* parameter a
86+
* @param a parameter a
8287
* @return the double value of a
8388
*/
8489
@Override
@@ -108,4 +113,33 @@ public Transformer<T, ReliabilityFunction> getTransformer() {
108113
return functionTransformer;
109114
}
110115

116+
/*
117+
* (non-Javadoc)
118+
*
119+
* @see org.jreliability.common.StructureFunction#isProvidingService(Map<T, Boolean>)
120+
*/
121+
@Override
122+
public boolean isProvidingService(Map<T, Boolean> variables) {
123+
// Convert variables and their phase to a term
124+
List<Term> terms = new ArrayList<Term>();
125+
for (Map.Entry<T, Boolean> entry : variables.entrySet()) {
126+
LiteralTerm<T> literalTerm = new LiteralTerm<T>(entry.getKey());
127+
if (entry.getValue()) {
128+
terms.add(literalTerm);
129+
} else {
130+
terms.add(new NOTTerm(literalTerm));
131+
}
132+
}
133+
ANDTerm variablesTerm = new ANDTerm(terms);
134+
// Get BDD from term
135+
BDDTTRF<T> bddTTRF = new BDDTTRF<T>(bdd.getProvider());
136+
BDD<T> variablesBDD = bddTTRF.convertToBDD(variablesTerm);
137+
138+
// Combine variablesBDD and bdd via AND: If result is zero, no service is provided anymore
139+
BDD<T> tmpBDD = bdd.copy();
140+
tmpBDD.andWith(variablesBDD);
141+
boolean hasFailed = tmpBDD.isZero();
142+
return !hasFailed;
143+
}
144+
111145
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
*
3+
*/
4+
package org.jreliability.common;
5+
6+
import java.util.Map;
7+
8+
/**
9+
* The {@link StructureFunction} {@code phi(T)} is a characteristic or indicater
10+
* function that determines whether the system provides correct service
11+
* ({@code phi(X) = true}) or has failed ({@code phi(X) = false}) given a set of
12+
* properly working and/or failed variables of type T.
13+
*
14+
* @author glass
15+
*
16+
* @param <T> the type of the variables
17+
*
18+
*/
19+
public interface StructureFunction<T> {
20+
21+
/**
22+
* Corresponds to the structure function {@code phi} and returns whether the
23+
* system works given a map of either working or failed variables
24+
*
25+
* @param variables the map of working or failed variables
26+
* @return true if the system still provides correct service and false in case
27+
* it failed
28+
*/
29+
public boolean isProvidingService(Map<T, Boolean> variables);
30+
31+
}

src/test/java/org/jreliability/bdd/BDDReliabilityFunctionTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515

1616
package org.jreliability.bdd;
1717

18+
import java.util.HashMap;
19+
import java.util.Map;
20+
1821
import org.apache.commons.collections15.Transformer;
1922
import org.jreliability.bdd.javabdd.JBDDProviderFactory;
2023
import org.jreliability.booleanfunction.Term;
2124
import org.jreliability.booleanfunction.common.ANDTerm;
2225
import org.jreliability.booleanfunction.common.LiteralTerm;
26+
import org.jreliability.booleanfunction.common.ORTerm;
2327
import org.jreliability.function.ReliabilityFunction;
2428
import org.jreliability.function.common.ExponentialReliabilityFunction;
2529
import org.junit.jupiter.api.Assertions;
@@ -105,4 +109,42 @@ public void testGetTransformer() {
105109
Assertions.assertEquals(transformer, function.getTransformer());
106110
}
107111

112+
@Test
113+
public void testIsProvidingService() {
114+
// Sensor 1 & 2 in parallel, sensor 3 in series
115+
String var1 = "sensor1";
116+
String var2 = "sensor2";
117+
String var3 = "sensor3";
118+
Term s1 = new LiteralTerm<>(var1);
119+
Term s2 = new LiteralTerm<>(var2);
120+
Term s3 = new LiteralTerm<>(var3);
121+
ORTerm or = new ORTerm();
122+
or.add(s1, s2);
123+
ANDTerm and = new ANDTerm();
124+
and.add(or, s3);
125+
126+
BDDTTRF<String> ttrf = new BDDTTRF<String>(provider);
127+
BDD<String> bdd = ttrf.convertToBDD(and);
128+
129+
BDDReliabilityFunction<String> function = new BDDReliabilityFunction<String>(bdd, new TestTransformer());
130+
131+
Map<String, Boolean> failedComponents = new HashMap<String, Boolean>();
132+
133+
// First sensor failure should return proper working system
134+
failedComponents.put(var1, false);
135+
Assertions.assertTrue(function.isProvidingService(failedComponents));
136+
137+
// Second sensor failure should return failed system
138+
failedComponents.put(var2, false);
139+
Assertions.assertFalse(function.isProvidingService(failedComponents));
140+
141+
// Second sensor back to life, system properly working
142+
failedComponents.put(var2, true);
143+
Assertions.assertTrue(function.isProvidingService(failedComponents));
144+
145+
// Sensor 3 failure cannot be mitigated, system fails
146+
failedComponents.put(var3, false);
147+
Assertions.assertFalse(function.isProvidingService(failedComponents));
148+
}
149+
108150
}

0 commit comments

Comments
 (0)