Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 47 additions & 14 deletions src/main/java/org/jreliability/bdd/BDDReliabilityFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,37 @@

package org.jreliability.bdd;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections15.Transformer;
import org.jreliability.booleanfunction.Term;
import org.jreliability.booleanfunction.common.ANDTerm;
import org.jreliability.booleanfunction.common.LiteralTerm;
import org.jreliability.booleanfunction.common.NOTTerm;
import org.jreliability.common.StructureFunction;
import org.jreliability.function.ReliabilityFunction;
import org.jreliability.function.SequentialFunction;
import org.jreliability.function.UnreliabilityFunction;

/**
* The {@link BDDReliabilityFunction} represents the {@link ReliabilityFunction}
* that is inherently included in a {@link BDD}.
*
* @author glass
*
* @param <T>
* the type of variable
* @param <T> the type of variable
*/
public class BDDReliabilityFunction<T> extends SequentialFunction implements ReliabilityFunction {
public class BDDReliabilityFunction<T> extends SequentialFunction implements ReliabilityFunction, StructureFunction<T> {

/**
* The BDD representing the {@link UnreliabilityFunction}.
* The BDD representing the {@link ReliabilityFunction}.
*/
protected final BDD<T> bdd;

/**
* The used {@link Transformer} to get the {@link ReliabilityFunction} of
* each element of the {@link BDD}.
* The used {@link Transformer} to get the {@link ReliabilityFunction} of each
* element of the {@link BDD}.
*/
protected final Transformer<T, ReliabilityFunction> functionTransformer;

Expand All @@ -51,12 +58,10 @@ public class BDDReliabilityFunction<T> extends SequentialFunction implements Rel
* Constructs a {@link BDDReliabilityFunction} with a given {@link BDD} and
* {@link Transformer}.
*
* @param bdd
* the bdd representing the reliabilityFunction
* @param bdd the bdd representing the reliabilityFunction
*
* @param functionTransformer
* the functionTransformer to transform bdd elements to
* reliabilityFunction
* @param functionTransformer the functionTransformer to transform bdd elements
* to reliabilityFunction
*/
public BDDReliabilityFunction(BDD<T> bdd, Transformer<T, ReliabilityFunction> functionTransformer) {
super();
Expand All @@ -77,8 +82,7 @@ public double getY(final double x) {
/**
* Default {@link Transformer}.
*
* @param a
* parameter a
* @param a parameter a
* @return the double value of a
*/
@Override
Expand Down Expand Up @@ -108,4 +112,33 @@ public Transformer<T, ReliabilityFunction> getTransformer() {
return functionTransformer;
}

/*
* (non-Javadoc)
*
* @see org.jreliability.common.StructureFunction#isProvidingService(Map<T, Boolean>)
*/
@Override
public boolean isProvidingService(Map<T, Boolean> variables) {
// Convert variables and their phase to a term
List<Term> terms = new ArrayList<Term>();
for (Map.Entry<T, Boolean> entry : variables.entrySet()) {
LiteralTerm<T> literalTerm = new LiteralTerm<T>(entry.getKey());
if (entry.getValue()) {
terms.add(literalTerm);
} else {
terms.add(new NOTTerm(literalTerm));
}
}
ANDTerm variablesTerm = new ANDTerm(terms);
// Get BDD from term
BDDTTRF<T> bddTTRF = new BDDTTRF<T>(bdd.getProvider());
BDD<T> variablesBDD = bddTTRF.convertToBDD(variablesTerm);

// Combine variablesBDD and bdd via AND: If result is zero, no service is provided anymore
BDD<T> tmpBDD = bdd.copy();
tmpBDD.andWith(variablesBDD);
boolean hasFailed = tmpBDD.isZero();
return !hasFailed;
}

}
42 changes: 42 additions & 0 deletions src/main/java/org/jreliability/common/StructureFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* 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.common;

import java.util.Map;

/**
* The {@link StructureFunction} {@code phi(T)} is a characteristic or indicator
* function that determines whether the system provides correct service
* ({@code phi(X) = true}) or has failed ({@code phi(X) = false}) given a set of
* properly working and/or failed variables of type T.
*
* @author glass
*
* @param <T> the type of the variables
*
*/
public interface StructureFunction<T> {

/**
* Corresponds to the structure function {@code phi} and returns whether the
* system works given a map of either working or failed variables
*
* @param variables the map of working or failed variables
* @return true if the system still provides correct service and false in case
* it failed
*/
public boolean isProvidingService(Map<T, Boolean> variables);

}
Loading