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 ;
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}
0 commit comments