Skip to content

Commit

Permalink
codacy issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhglass committed Apr 8, 2018
1 parent 1605b19 commit 4f0bdce
Show file tree
Hide file tree
Showing 38 changed files with 303 additions and 342 deletions.
54 changes: 32 additions & 22 deletions src/main/java/org/jreliability/bdd/BDDConstraint.java
Expand Up @@ -15,11 +15,13 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
* The {@link BDDConstraint} is used to model {@link greater-equal} constraints with a left-hand-side ({@link lhs})
* consisting of {@link Literals} and the right-hand-side ({@link rhs}) being an {@link Integer}.
* The {@link BDDConstraint} is used to model {@link greater-equal} constraints
* with a left-hand-side ({@link lhs}) consisting of {@link Literals} and the
* right-hand-side ({@link rhs}) being an {@link Integer}.
*
* @author glass, lukasiewycz
*
Expand All @@ -33,8 +35,8 @@ class BDDConstraint<T> {
*/
protected int rhs;
/**
* The left-hand-side of the constraint as a {@link List} of {@link
* Literals}.
* The left-hand-side of the constraint as a {@link List} of
* {@link Literals}.
*/
protected List<Literal<T>> lhs = new ArrayList<>();
/**
Expand All @@ -43,7 +45,8 @@ class BDDConstraint<T> {
protected Set<BDD<T>> variables = new HashSet<>();

/**
* Constructs a {@link BDDConstraint} with a given right-hand-side {@link rhs} and left-hand-side {@link lhs}.
* Constructs a {@link BDDConstraint} with a given right-hand-side
* {@link rhs} and left-hand-side {@link lhs}.
*
* @param rhs
* the right-hand-side
Expand All @@ -56,8 +59,9 @@ public BDDConstraint(int rhs, List<Literal<T>> lhs) {
}

/**
* Initializes the {@link BDDConstraint} with the normalizing operations proposed by {@link Een & Soerrensson 2006}
* plus zero coefficient elimination.
* Initializes the {@link BDDConstraint} with the normalizing operations
* proposed by {@link Een & Soerrensson 2006} plus zero coefficient
* elimination.
*
* @param literals
* the literals
Expand All @@ -73,8 +77,8 @@ protected void initialize(List<Literal<T>> literals) {
}

/**
* Ensures a positive {@link coefficient} of the {@link Literal} by a negotiation of the variable and an update of
* the {@link rhs}.
* Ensures a positive {@link coefficient} of the {@link Literal} by a
* negotiation of the variable and an update of the {@link rhs}.
*
* @param literal
* the literal
Expand All @@ -92,8 +96,8 @@ protected void checkCoefficient(Literal<T> literal) {
}

/**
* Checks the {@link Literal} if it includes a variable that is already present in the {@link BDDConstraint} and
* adds it correctly.
* Checks the {@link Literal} if it includes a variable that is already
* present in the {@link BDDConstraint} and adds it correctly.
*
* @param literal
*/
Expand All @@ -119,7 +123,8 @@ protected void checkAndAddVariable(Literal<T> literal) {
}

/**
* Trims all {@link coefficients} that are greater than the {@link rhs} to {@link rhs}.
* Trims all {@link coefficients} that are greater than the {@link rhs} to
* {@link rhs}.
*/
protected void trim() {
for (Literal<T> literal : lhs) {
Expand Down Expand Up @@ -147,8 +152,9 @@ protected void eliminateZeroCoefficients() {
}

/**
* Determines the greatest-common-divisor ({@link gcd}) of all {@link
* coefficients} of the {@link lhs} and the {@link rhs} and updates the values.
* Determines the greatest-common-divisor ({@link gcd}) of all
* {@link coefficients} of the {@link lhs} and the {@link rhs} and updates
* the values.
*/
protected void gcd() {
if (!lhs.isEmpty()) {
Expand All @@ -170,7 +176,8 @@ protected void gcd() {
}

/**
* Returns the {@link gcd} of two {@link Integers} by a simple recursive procedure.
* Returns the {@link gcd} of two {@link Integers} by a simple recursive
* procedure.
*
* @param a
* integer a
Expand All @@ -195,8 +202,8 @@ public int getRhs() {
}

/**
* Returns the left-hand-side ({@link lhs}) of the constraint as a {@link
* List} of {@link Literals}.
* Returns the left-hand-side ({@link lhs}) of the constraint as a
* {@link List} of {@link Literals}.
*
* @return the lhs of the constraint
*/
Expand All @@ -205,7 +212,8 @@ public List<Literal<T>> getLhs() {
}

/**
* The {@link Literal} represents a variable using a {@link BDD} and its {@link coefficient}.
* The {@link Literal} represents a variable using a {@link BDD} and its
* {@link coefficient}.
*
* @author glass
*
Expand All @@ -217,15 +225,16 @@ static class Literal<T> {
/**
* The coefficient.
*/
Integer coefficient = 0;
protected Integer coefficient = 0;

/**
* The variable.
*/
BDD<T> variable = null;
protected BDD<T> variable = null;

/**
* Constructs a {@link Literal} with a given coefficient and variable as a {@link BDD}.
* Constructs a {@link Literal} with a given coefficient and variable as
* a {@link BDD}.
*
* @param coefficient
* the coefficient
Expand Down Expand Up @@ -287,7 +296,8 @@ public String toString() {
}

/**
* The {@link Pair} represents a tuple of two {@link Objects} {@link A} and {@link B}.
* The {@link Pair} represents a tuple of two {@link Objects} {@link A} and
* {@link B}.
*
* @author glass
*
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/org/jreliability/bdd/BDDTTRF.java
Expand Up @@ -32,8 +32,9 @@
import org.jreliability.function.ReliabilityFunction;

/**
* The {@link BDDTTRF} transforms a Boolean function represented as a {@link Term} into a {@link ReliabilityFunction}
* or, if needed, into a {@link BDD}.
* The {@link BDDTTRF} transforms a Boolean function represented as a
* {@link Term} into a {@link ReliabilityFunction} or, if needed, into a
* {@link BDD}.
*
* @author glass
*
Expand All @@ -60,8 +61,8 @@ public BDDTTRF(BDDProvider<T> provider) {
/*
* (non-Javadoc)
*
* @see org.jreliability.booleanfunction.TTRF#convert(org.jreliability. booleanfunction.Term,
* org.apache.commons.collections15.Transformer)
* @see org.jreliability.booleanfunction.TTRF#convert(org.jreliability.
* booleanfunction.Term, org.apache.commons.collections15.Transformer)
*/
@Override
public ReliabilityFunction convert(Term term, Transformer<T, ReliabilityFunction> functionTransformer) {
Expand All @@ -71,8 +72,9 @@ public ReliabilityFunction convert(Term term, Transformer<T, ReliabilityFunction
/*
* (non-Javadoc)
*
* @see org.jreliability.booleanfunction.TTRF#convert(org.jreliability. booleanfunction.Term,
* org.apache.commons.collections15.Transformer, org.apache.commons.collections15.Predicate)
* @see org.jreliability.booleanfunction.TTRF#convert(org.jreliability.
* booleanfunction.Term, org.apache.commons.collections15.Transformer,
* org.apache.commons.collections15.Predicate)
*/
@Override
public ReliabilityFunction convert(Term term, Transformer<T, ReliabilityFunction> functionTransformer,
Expand All @@ -82,13 +84,15 @@ public ReliabilityFunction convert(Term term, Transformer<T, ReliabilityFunction
}

/**
* Converts a given {@link BDD} and a {@link Transformer} to a {@link ReliabilityFunction}.
* Converts a given {@link BDD} and a {@link Transformer} to a
* {@link ReliabilityFunction}.
*
* @param bdd
* the bdd
* @param functionTransformer
* the function functionTransformer
* @return a reliability function from the given bdd and function functionTransformer
* @return a reliability function from the given bdd and function
* functionTransformer
*/
public ReliabilityFunction convert(BDD<T> bdd, Transformer<T, ReliabilityFunction> functionTransformer) {
BDDReliabilityFunction<T> function = new BDDReliabilityFunction<>(bdd, functionTransformer);
Expand All @@ -108,7 +112,8 @@ public BDD<T> convertToBDD(Term term) {
}

/**
* Returns a {@link BDD} representing the given {@link Term} while respecting the exists-variables.
* Returns a {@link BDD} representing the given {@link Term} while
* respecting the exists-variables.
*
* @param term
* the term
Expand All @@ -118,7 +123,7 @@ public BDD<T> convertToBDD(Term term) {
*/
public BDD<T> convertToBDD(Term term, Predicate<T> existsPredicate) {
BDD<T> bdd = transform(term);
if (!(existsPredicate == null)) {
if (existsPredicate != null) {
Set<T> variables = Terms.getVariables(term);
for (T variable : variables) {
if (existsPredicate.evaluate(variable)) {
Expand Down
57 changes: 29 additions & 28 deletions src/main/java/org/jreliability/bdd/BDDTopEvent.java
Expand Up @@ -21,10 +21,11 @@
import org.apache.commons.collections15.Transformer;

/**
* The {@link BDDTopEvent} allows the fast calculation of the top event for a given {@link BDD}.
* The {@link BDDTopEvent} allows the fast calculation of the top event for a
* given {@link BDD}.
* <p>
* Here, the {@link BDD} is copied to an internal structure such that the {@link BDD#free()} method does not interfere
* with this class.
* Here, the {@link BDD} is copied to an internal structure such that the
* {@link BDD#free()} method does not interfere with this class.
*
* @author lukasiewycz
*
Expand All @@ -33,6 +34,31 @@
*/
public class BDDTopEvent<T> {

/**
* Map of the original variables to the internal structure of the variables.
*/
protected Map<T, Var> variables = new HashMap<>();

/**
* A list of all variables nodes (ordered from bottom to the root).
*/
protected List<VarNode> nodes = new ArrayList<>();

/**
* The instance of the zero node.
*/
protected Node zero = new NodeZero();

/**
* The instance of the one node.
*/
protected Node one = new NodeOne();

/**
* The root of the bdd.
*/
protected Node root;

/**
*
* The {@link Var} is an internal variable class.
Expand Down Expand Up @@ -242,31 +268,6 @@ public double getValue() {
}
}

/**
* Map of the original variables to the internal structure of the variables.
*/
Map<T, Var> variables = new HashMap<>();

/**
* A list of all variables nodes (ordered from bottom to the root).
*/
List<VarNode> nodes = new ArrayList<>();

/**
* The instance of the zero node.
*/
Node zero = new NodeZero();

/**
* The instance of the one node.
*/
Node one = new NodeOne();

/**
* The root of the bdd.
*/
Node root;

/**
* Constructs the {@link BDDTopEvent} calculator for a given {@link BDD}.
*
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/jreliability/bdd/BDDs.java
Expand Up @@ -352,14 +352,14 @@ protected static <T> BDD<T> buildConstraintBDD(List<Literal<T>> literals, int rh

Pair<Integer, Integer> key = new Pair<>(index, sum);
if (!memo.containsKey(key)) {
index--;
int coefficient = literals.get(index).getCoefficient();
materialLeft -= coefficient;
int newIndex = index - 1;
int coefficient = literals.get(newIndex).getCoefficient();
int newMaterialLeft = materialLeft - coefficient;
int hiSum = sum + coefficient;
int loSum = sum;
BDD<T> hiBDD = buildConstraintBDD(literals, rhs, index, hiSum, materialLeft, memo, provider);
BDD<T> loBDD = buildConstraintBDD(literals, rhs, index, loSum, materialLeft, memo, provider);
BDD<T> ifBDD = literals.get(index).getVariable();
BDD<T> hiBDD = buildConstraintBDD(literals, rhs, newIndex, hiSum, newMaterialLeft, memo, provider);
BDD<T> loBDD = buildConstraintBDD(literals, rhs, newIndex, loSum, newMaterialLeft, memo, provider);
BDD<T> ifBDD = literals.get(newIndex).getVariable();
BDD<T> resultBDD = ifBDD.ite(hiBDD, loBDD);
memo.put(key, resultBDD);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jreliability/bdd/javabdd/JBDD.java
Expand Up @@ -32,9 +32,9 @@
*/
public class JBDD<T> implements BDD<T> {

JBDDProvider<T> provider;
protected JBDDProvider<T> provider;

net.sf.javabdd.BDD bdd;
protected net.sf.javabdd.BDD bdd;

/**
* The {@link AllSatIterator} is used as the {@link Iterator}.
Expand All @@ -44,7 +44,7 @@ public class JBDD<T> implements BDD<T> {
*/
private class AllSatIterator implements Iterator<BDD<T>> {

Iterator<T> iterator;
protected Iterator<T> iterator;

/**
* Constructs a {@link Iterator} with a given JavaBDD JDD iterator.
Expand Down
Expand Up @@ -97,6 +97,7 @@ public JBDDProvider(Type type, int vars, int variableGrowthFactor, int initialNu
default:
factory = JFactory.init(initialNumberofNodes, initialNumberofNodes);
factory.autoReorder(BDDFactory.REORDER_SIFT);
break;
}

factory.setVarNum(vars);
Expand Down
Expand Up @@ -22,14 +22,6 @@
*/
public class FALSETerm implements Term {

/**
* Constructs a {@link FALSETerm}.
*
*/
public FALSETerm() {
super();
}

/*
* (non-Javadoc)
*
Expand Down
Expand Up @@ -22,14 +22,6 @@
*/
public class TRUETerm implements Term {

/**
* Constructs a {@link TRUETerm}.
*
*/
public TRUETerm() {
super();
}

/*
* (non-Javadoc)
*
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/jreliability/common/Samples.java
Expand Up @@ -24,11 +24,4 @@ public class Samples extends TreeMap<Double, Double> {

private static final long serialVersionUID = 1L;

/**
* Constructs a {@link Samples}.
*/
public Samples() {
super();
}

}

0 comments on commit 4f0bdce

Please sign in to comment.