1515
1616package org .jreliability .bdd ;
1717
18+ import java .util .ArrayList ;
19+ import java .util .List ;
20+ import java .util .Map ;
21+
1822import 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 ;
1928import org .jreliability .function .ReliabilityFunction ;
2029import org .jreliability .function .SequentialFunction ;
2130import org .jreliability .function .UnreliabilityFunction ;
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}
0 commit comments