Skip to content

Commit

Permalink
Patch/#35 codacy issues (#38)
Browse files Browse the repository at this point in the history
* codacy issues fixed for org.opt4j.viewer.*

* codacy issues fixed for org.opt4j.tutorial.* except prettify.js

* codacy issues fixed for org.opt4j.satdecoding.*

* codacy issues fixed for org.opt4j.satdecoding.*

* codaxy issues fixed for org.opt4j.optimizers.* except fronts in
hypervolume

* codaxy issues fixed for org.opt4j.optimizers.*

* codacy issued fixed for org.opt4j.operators.*

* codacy issue fix

* codacy issues fixed in part for org.opt4j.core.*

* PMD CompareObjectsWithEquals requires more careful consideration;
reverted respective occurrences

* codacy issues fixed for org.opt4j.benchmarks.*

* Ignore ptolemy-plot sources, *.js, and *.py source files in codacy

* giving different syntax a try

* fixes according to pull-request review by felixreimann

* addressed review by felixreimann
  • Loading branch information
michaelhglass committed Apr 20, 2018
1 parent c5781dc commit 5a72265
Show file tree
Hide file tree
Showing 101 changed files with 639 additions and 523 deletions.
5 changes: 5 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
exclude_paths:
- 'opt4j-viewer/src/main/java/ptolemy/**/*'
- '**/*.py'
- '**/*.js'
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void config() {
creator = BinaryCreator.class;
decoder = BinaryToDoubleDecoder.class;
break;
case DOUBLE:
default: // DOUBLE
creator = DoubleCreator.class;
decoder = DoubleCopyDecoder.class;
break;
Expand Down Expand Up @@ -334,6 +334,7 @@ public void config() {
break;
default:
evaluator = DTLZ1.class;
break;
}

bindConstant(N.class).to(n);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
import org.opt4j.core.start.Constant;

/**
* The multiobjective 0/1 ILP knapsack problem as proposed in Zitzler and Thiele 1999. Either one of the nine benchmark
* problems from Zitzler and Thiele 1999 can be selected or the number of knapsacks and items can be set manually.
* The multiobjective 0/1 ILP knapsack problem as proposed in Zitzler and Thiele
* 1999. Either one of the nine benchmark problems from Zitzler and Thiele 1999
* can be selected or the number of knapsacks and items can be set manually.
*
* @see <a href=
* "http://www.tik.ee.ethz.ch/sop/download/supplementary/testProblemSuite/">http://www.tik.ee.ethz.ch/sop/download/supplementary/testProblemSuite/</a>
Expand Down Expand Up @@ -130,7 +131,7 @@ protected void config() {
}

switch (representation) {
case BITSTRING:
default: // BITSTRING
bindProblem(KnapsackBinaryCreatorDecoder.class, KnapsackBinaryCreatorDecoder.class,
KnapsackProfitEvaluator.class);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
*******************************************************************************/


package org.opt4j.benchmarks.queens;

import static org.opt4j.core.Objective.Sign.MIN;
Expand Down Expand Up @@ -82,6 +81,22 @@ public Objectives evaluate(QueensBoard queensBoard) {
*/
private int countErrors(QueensBoard queensBoard) {
int errorcount = 0;

errorcount += countErrorsRowsColumns(queensBoard);
errorcount += countErrorsDiagonals(queensBoard);

return errorcount;
}

/**
* Helper function to count the errors in rows and columns.
*
* @param queensBoard
* the board
* @return the error count in rows and columns
*/
protected int countErrorsRowsColumns(QueensBoard queensBoard) {
int errorcount = 0;
int size = problem.size();

for (int i = 0; i < size; i++) {
Expand All @@ -106,6 +121,20 @@ private int countErrors(QueensBoard queensBoard) {
errorcount += sum;
}

return errorcount;
}

/**
* Helper function to count the errors in diagonals.
*
* @param queensBoard
* the board
* @return the error count in diagonals
*/
protected int countErrorsDiagonals(QueensBoard queensBoard) {
int errorcount = 0;
int size = problem.size();

for (int k = -size + 1; k < size; k++) {
// diagonal 1
int sum = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ public class QueensModule extends ProblemModule {
@Order(3)
protected Dec decoder = Dec.SAT;

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

/**
* The {@link Decoder} strategy for the queens problem.
*
Expand Down Expand Up @@ -105,7 +98,7 @@ public void config() {
Class<? extends Decoder<?, ?>> decoderClass = null;

switch (decoder) {
case SAT:
default: // SAT
creatorClass = QueensSATDecoder.class;
decoderClass = QueensSATDecoder.class;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/


package org.opt4j.benchmarks.queens;

Expand Down Expand Up @@ -90,7 +89,20 @@ public QueensBoard convertModel(Model model) {
@Override
public Set<Constraint> createConstraints() {
Set<Constraint> constraints = new HashSet<Constraint>();

constraints.addAll(createConstraintsRowsColumns());
constraints.addAll(createConstraintsDiagonal());
return constraints;
}

/**
* Helper function for createConstraints() that creates the constraints regarding rows and columns.
*
* @return constraints regarding rows and columns
*/
protected Set<Constraint> createConstraintsRowsColumns() {
int size = problem.size();
Set<Constraint> constraints = new HashSet<Constraint>();

for (int i = 0; i < size; i++) {

Expand All @@ -112,6 +124,19 @@ public Set<Constraint> createConstraints() {
constraints.add(constraint);
}

return constraints;

}

/**
* Helper function for createConstraints() that creates the constraints regarding diagonals.
*
* @return constraints regarding diagonals
*/
protected Set<Constraint> createConstraintsDiagonal() {
int size = problem.size();
Set<Constraint> constraints = new HashSet<Constraint>();

for (int k = -size + 1; k < size; k++) {
// diagonal 1
Constraint constraint = new Constraint("<=", 1);
Expand All @@ -137,5 +162,6 @@ public Set<Constraint> createConstraints() {
}

return constraints;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected static List<Double> t1(final List<Double> y, final int k) {
}

for (int i = k; i < n; i++) {
t.add(WFGTransFunctions.s_linear(y.get(i), 0.35));
t.add(WFGTransFunctions.sLinear(y.get(i), 0.35));
}

return t;
Expand All @@ -85,7 +85,7 @@ protected static List<Double> t2(final List<Double> y, final int k) {
}

for (int i = k; i < n; i++) {
t.add(WFGTransFunctions.b_flat(y.get(i), 0.8, 0.75, 0.85));
t.add(WFGTransFunctions.bFlat(y.get(i), 0.8, 0.75, 0.85));
}

return t;
Expand All @@ -96,7 +96,7 @@ protected static List<Double> t3(final List<Double> y) {
List<Double> t = new ArrayList<Double>();

for (int i = 0; i < n; i++) {
t.add(WFGTransFunctions.b_poly(y.get(i), 0.02));
t.add(WFGTransFunctions.bPoly(y.get(i), 0.02));
}

return t;
Expand Down Expand Up @@ -125,13 +125,13 @@ protected static List<Double> t4(final List<Double> y, final int k, final int M)
final List<Double> y_sub = y.subList(head, tail);
final List<Double> w_sub = w.subList(head, tail);

t.add(WFGTransFunctions.r_sum(y_sub, w_sub));
t.add(WFGTransFunctions.rSum(y_sub, w_sub));
}

final List<Double> y_sub = y.subList(k, n);
final List<Double> w_sub = w.subList(k, n);

t.add(WFGTransFunctions.r_sum(y_sub, w_sub));
t.add(WFGTransFunctions.rSum(y_sub, w_sub));

return t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected static List<Double> t2(final List<Double> y, final int k) {
final int head = k + 2 * (i - k) - 2;
final int tail = k + 2 * (i - k);

t.add(WFGTransFunctions.r_nonsep(y.subList(head, tail), 2));
t.add(WFGTransFunctions.rNonsep(y.subList(head, tail), 2));
}

return t;
Expand Down Expand Up @@ -98,13 +98,13 @@ protected static List<Double> t3(final List<Double> y, final int k, final int M)
final List<Double> y_sub = y.subList(head, tail);
final List<Double> w_sub = w.subList(head, tail);

t.add(WFGTransFunctions.r_sum(y_sub, w_sub));
t.add(WFGTransFunctions.rSum(y_sub, w_sub));
}

final List<Double> y_sub = y.subList(k, n);
final List<Double> w_sub = w.subList(k, n);

t.add(WFGTransFunctions.r_sum(y_sub, w_sub));
t.add(WFGTransFunctions.rSum(y_sub, w_sub));

return t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static List<Double> t1(final List<Double> y) {
List<Double> t = new ArrayList<Double>();

for (int i = 0; i < n; i++) {
t.add(WFGTransFunctions.s_multi(y.get(i), 30, 10, 0.35));
t.add(WFGTransFunctions.sMulti(y.get(i), 30, 10, 0.35));
}

return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected static List<Double> t1(final List<Double> y) {
List<Double> t = new ArrayList<Double>();

for (int i = 0; i < n; i++) {
t.add(WFGTransFunctions.s_decept(y.get(i), 0.35, 0.001, 0.05));
t.add(WFGTransFunctions.sDecept(y.get(i), 0.35, 0.001, 0.05));
}

return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public static List<Double> t2(final List<Double> y, final int k, final int M) {

final List<Double> y_sub = y.subList(head, tail);

t.add(WFGTransFunctions.r_nonsep(y_sub, k / (M - 1)));
t.add(WFGTransFunctions.rNonsep(y_sub, k / (M - 1)));
}

final List<Double> y_sub = y.subList(k, n);

t.add(WFGTransFunctions.r_nonsep(y_sub, n - k));
t.add(WFGTransFunctions.rNonsep(y_sub, n - k));

return t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public static List<Double> t1(final List<Double> y, final int k) {
final List<Double> y_sub = y.subList(i + 1, n);
final List<Double> w_sub = w.subList(i + 1, n);

final double u = WFGTransFunctions.r_sum(y_sub, w_sub);
final double u = WFGTransFunctions.rSum(y_sub, w_sub);

t.add(WFGTransFunctions.b_param(y.get(i), u, 0.98 / 49.98, 0.02, 50));
t.add(WFGTransFunctions.bParam(y.get(i), u, 0.98 / 49.98, 0.02, 50));
}

for (int i = k; i < n; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ protected static List<Double> t1(final List<Double> y, final int k) {
final List<Double> y_sub = y.subList(0, i);
final List<Double> w_sub = w.subList(0, i);

final double u = WFGTransFunctions.r_sum(y_sub, w_sub);
final double u = WFGTransFunctions.rSum(y_sub, w_sub);

t.add(WFGTransFunctions.b_param(y.get(i), u, 0.98 / 49.98, 0.02, 50));
t.add(WFGTransFunctions.bParam(y.get(i), u, 0.98 / 49.98, 0.02, 50));
}

return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ protected static List<Double> t1(final List<Double> y) {
final List<Double> y_sub = y.subList(i + 1, n);
final List<Double> w_sub = w.subList(i + 1, n);

final double u = WFGTransFunctions.r_sum(y_sub, w_sub);
final double u = WFGTransFunctions.rSum(y_sub, w_sub);

t.add(WFGTransFunctions.b_param(y.get(i), u, 0.98 / 49.98, 0.02, 50));
t.add(WFGTransFunctions.bParam(y.get(i), u, 0.98 / 49.98, 0.02, 50));
}

t.add(y.get(n - 1));
Expand All @@ -85,11 +85,11 @@ protected static List<Double> t2(final List<Double> y, final int k) {
List<Double> t = new ArrayList<Double>();

for (int i = 0; i < k; i++) {
t.add(WFGTransFunctions.s_decept(y.get(i), 0.35, 0.001, 0.05));
t.add(WFGTransFunctions.sDecept(y.get(i), 0.35, 0.001, 0.05));
}

for (int i = k; i < n; i++) {
t.add(WFGTransFunctions.s_multi(y.get(i), 30, 95, 0.35));
t.add(WFGTransFunctions.sMulti(y.get(i), 30, 95, 0.35));
}

return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected static List<Double> calculateF(final List<Double> x, final List<Double
S.add(m * 2.0);
}

return caculateF(x, h, S);
return calculateF(x, h, S);
}

protected static List<Double> normalizeZ(final List<Double> z, final List<Double> z_max) {
Expand Down Expand Up @@ -146,7 +146,7 @@ protected static List<Double> calculateX(final List<Double> t_p, final List<Bool
return result;
}

protected static List<Double> caculateF(final List<Double> x, final List<Double> h, final List<Double> S) {
protected static List<Double> calculateF(final List<Double> x, final List<Double> h, final List<Double> S) {
assert (x.size() == h.size());
assert (h.size() == S.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected static List<Double> shape(final List<Double> t_p) {
S.add(1.0);
}

return caculateF(x, h, S);
return calculateF(x, h, S);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public static List<Double> t1(final List<Double> y) {
final List<Double> y_sub = y.subList(0, i);
final List<Double> w_sub = w.subList(0, i);

final double u = WFGTransFunctions.r_sum(y_sub, w_sub);
final double u = WFGTransFunctions.rSum(y_sub, w_sub);

t.add(WFGTransFunctions.b_param(y.get(i), u, 0.98 / 49.98, 0.02, 50));
t.add(WFGTransFunctions.bParam(y.get(i), u, 0.98 / 49.98, 0.02, 50));
}

return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void config() {
Class<? extends Evaluator<?>> evaluator = null;

switch (encoding) {
case BINARY:
default: //BINARY
creator = BinaryCreator.class;
decoder = BinaryToDoubleDecoder.class;
break;
Expand Down
Loading

0 comments on commit 5a72265

Please sign in to comment.