Skip to content

Commit 91bbb9c

Browse files
39 structurefunction (#40)
* initial solution to integrate structure function * Added the StructureFunction interface to stochastic logic * improve code re-use and coverage * improved minor coverage in LiteralTerm
1 parent c9dc9f5 commit 91bbb9c

7 files changed

Lines changed: 329 additions & 86 deletions

File tree

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

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,37 @@
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;
21-
import org.jreliability.function.UnreliabilityFunction;
2230

2331
/**
2432
* The {@link BDDReliabilityFunction} represents the {@link ReliabilityFunction}
2533
* that is inherently included in a {@link BDD}.
2634
*
2735
* @author glass
2836
*
29-
* @param <T>
30-
* the type of variable
37+
* @param <T> the type of variable
3138
*/
32-
public class BDDReliabilityFunction<T> extends SequentialFunction implements ReliabilityFunction {
39+
public class BDDReliabilityFunction<T> extends SequentialFunction implements ReliabilityFunction, StructureFunction<T> {
3340

3441
/**
35-
* The BDD representing the {@link UnreliabilityFunction}.
42+
* The BDD representing the {@link ReliabilityFunction}.
3643
*/
3744
protected final BDD<T> bdd;
3845

3946
/**
40-
* The used {@link Transformer} to get the {@link ReliabilityFunction} of
41-
* each element of the {@link BDD}.
47+
* The used {@link Transformer} to get the {@link ReliabilityFunction} of each
48+
* element of the {@link BDD}.
4249
*/
4350
protected final Transformer<T, ReliabilityFunction> functionTransformer;
4451

@@ -51,12 +58,10 @@ public class BDDReliabilityFunction<T> extends SequentialFunction implements Rel
5158
* Constructs a {@link BDDReliabilityFunction} with a given {@link BDD} and
5259
* {@link Transformer}.
5360
*
54-
* @param bdd
55-
* the bdd representing the reliabilityFunction
61+
* @param bdd the bdd representing the reliabilityFunction
5662
*
57-
* @param functionTransformer
58-
* the functionTransformer to transform bdd elements to
59-
* reliabilityFunction
63+
* @param functionTransformer the functionTransformer to transform bdd elements
64+
* to reliabilityFunction
6065
*/
6166
public BDDReliabilityFunction(BDD<T> bdd, Transformer<T, ReliabilityFunction> functionTransformer) {
6267
super();
@@ -77,8 +82,7 @@ public double getY(final double x) {
7782
/**
7883
* Default {@link Transformer}.
7984
*
80-
* @param a
81-
* parameter a
85+
* @param a parameter a
8286
* @return the double value of a
8387
*/
8488
@Override
@@ -108,4 +112,33 @@ public Transformer<T, ReliabilityFunction> getTransformer() {
108112
return functionTransformer;
109113
}
110114

115+
/*
116+
* (non-Javadoc)
117+
*
118+
* @see org.jreliability.common.StructureFunction#isProvidingService(Map<T, Boolean>)
119+
*/
120+
@Override
121+
public boolean isProvidingService(Map<T, Boolean> variables) {
122+
// Convert variables and their phase to a term
123+
List<Term> terms = new ArrayList<Term>();
124+
for (Map.Entry<T, Boolean> entry : variables.entrySet()) {
125+
LiteralTerm<T> literalTerm = new LiteralTerm<T>(entry.getKey());
126+
if (entry.getValue()) {
127+
terms.add(literalTerm);
128+
} else {
129+
terms.add(new NOTTerm(literalTerm));
130+
}
131+
}
132+
ANDTerm variablesTerm = new ANDTerm(terms);
133+
// Get BDD from term
134+
BDDTTRF<T> bddTTRF = new BDDTTRF<T>(bdd.getProvider());
135+
BDD<T> variablesBDD = bddTTRF.convertToBDD(variablesTerm);
136+
137+
// Combine variablesBDD and bdd via AND: If result is zero, no service is provided anymore
138+
BDD<T> tmpBDD = bdd.copy();
139+
tmpBDD.andWith(variablesBDD);
140+
boolean hasFailed = tmpBDD.isZero();
141+
return !hasFailed;
142+
}
143+
111144
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************************
2+
* JReliability is free software: you can redistribute it and/or modify it under
3+
* the terms of the GNU Lesser General Public License as published by the Free
4+
* Software Foundation, either version 3 of the License, or (at your option) any
5+
* later version.
6+
*
7+
* JReliability is distributed in the hope that it will be useful, but WITHOUT
8+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9+
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
10+
* details.
11+
*
12+
* You should have received a copy of the GNU Lesser General Public License
13+
* along with JReliability. If not, see http://www.gnu.org/licenses/.
14+
*******************************************************************************/
15+
package org.jreliability.common;
16+
17+
import java.util.Map;
18+
19+
/**
20+
* The {@link StructureFunction} {@code phi(T)} is a characteristic or indicator
21+
* function that determines whether the system provides correct service
22+
* ({@code phi(X) = true}) or has failed ({@code phi(X) = false}) given a set of
23+
* properly working and/or failed variables of type T.
24+
*
25+
* @author glass
26+
*
27+
* @param <T> the type of the variables
28+
*
29+
*/
30+
public interface StructureFunction<T> {
31+
32+
/**
33+
* Corresponds to the structure function {@code phi} and returns whether the
34+
* system works given a map of either working or failed variables
35+
*
36+
* @param variables the map of working or failed variables
37+
* @return true if the system still provides correct service and false in case
38+
* it failed
39+
*/
40+
public boolean isProvidingService(Map<T, Boolean> variables);
41+
42+
}

0 commit comments

Comments
 (0)