Reformat code and optimize imports.

Language Level changed to 1.7
This commit is contained in:
2013-10-12 13:49:50 +02:00
parent 6473b35859
commit 595d0084a9
214 changed files with 989 additions and 1461 deletions

View File

@@ -3,28 +3,27 @@ package simpleprobs;
/**
* A simple interface to easily include new optimization problems in Java into the
* EvA framework.
*
* @author mkron
*
* @author mkron
*/
public interface InterfaceSimpleProblem<T> {
/**
* Evaluate a double vector representing a possible problem solution as
* part of an individual in the EvA framework. This makes up the
* target function to be evaluated.
*
* @param x a double vector to be evaluated
* @return the fitness vector assigned to x as to the target function
*/
public double[] eval(T x);
/**
* Return the problem dimension.
*
* @return the problem dimension
*/
public int getProblemDimension();
/**
* Evaluate a double vector representing a possible problem solution as
* part of an individual in the EvA framework. This makes up the
* target function to be evaluated.
*
* @param x a double vector to be evaluated
* @return the fitness vector assigned to x as to the target function
*/
public double[] eval(T x);
/**
* Return the problem dimension.
*
* @return the problem dimension
*/
public int getProblemDimension();
}

View File

@@ -3,27 +3,27 @@ package simpleprobs;
import java.util.BitSet;
public class SimpleB1 extends SimpleProblemBinary {
public static String globalInfo() {
return "A simple B1 implementation, minimize bits in a binary vector.";
}
@Override
public double[] eval(BitSet b) {
double[] result = new double[1];
int fitness = 0;
public static String globalInfo() {
return "A simple B1 implementation, minimize bits in a binary vector.";
}
for (int i = 0; i < getProblemDimension(); i++) {
if (b.get(i)) {
fitness++;
}
@Override
public double[] eval(BitSet b) {
double[] result = new double[1];
int fitness = 0;
for (int i = 0; i < getProblemDimension(); i++) {
if (b.get(i)) {
fitness++;
}
result[0] = fitness;
return result;
}
}
result[0] = fitness;
return result;
}
@Override
public int getProblemDimension() {
return 20;
}
public int getProblemDimension() {
return 20;
}
}

View File

@@ -2,28 +2,28 @@ package simpleprobs;
public class SimpleF1 extends SimpleProblemDouble {
public static String globalInfo() {
return "A simple F1 implementation, find the minimum of a hyper parabola.";
}
public static String globalInfo() {
return "A simple F1 implementation, find the minimum of a hyper parabola.";
}
@Override
public double[] eval(double[] x) {
double res[] = new double[1];
// this defines the dimension of the fitness vector, which should be always the same
public double[] eval(double[] x) {
double res[] = new double[1];
// this defines the dimension of the fitness vector, which should be always the same
double sum = 0;
// calculate the fitness value
for (int i=0; i<getProblemDimension(); i++) {
sum += (x[i]*x[i]);
}
double sum = 0;
// calculate the fitness value
for (int i = 0; i < getProblemDimension(); i++) {
sum += (x[i] * x[i]);
}
// setting the return vector and return it
res[0] = Math.sqrt(sum);
return res;
}
// setting the return vector and return it
res[0] = Math.sqrt(sum);
return res;
}
@Override
public int getProblemDimension() {
return 20;
}
public int getProblemDimension() {
return 20;
}
}

View File

@@ -4,7 +4,7 @@ import java.io.Serializable;
import java.util.BitSet;
public abstract class SimpleProblemBinary implements InterfaceSimpleProblem<BitSet>, Serializable {
public static String globalInfo() {
return "A simple binary problem. Override globalInfo() to insert more information.";
}
public static String globalInfo() {
return "A simple binary problem. Override globalInfo() to insert more information.";
}
}

View File

@@ -3,7 +3,7 @@ package simpleprobs;
import java.io.Serializable;
public abstract class SimpleProblemDouble implements InterfaceSimpleProblem<double[]>, Serializable {
public static String globalInfo() {
return "A simple double valued problem. Override globalInfo() to insert more information.";
}
public static String globalInfo() {
return "A simple double valued problem. Override globalInfo() to insert more information.";
}
}