Major commit, see changelog in JOpt-Notes.txt
This commit is contained in:
30
src/simpleprobs/InterfaceSimpleProblem.java
Normal file
30
src/simpleprobs/InterfaceSimpleProblem.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package simpleprobs;
|
||||
|
||||
/**
|
||||
* A simple interface to easily include new optimization problems in Java into the
|
||||
* JavaEvA framework.
|
||||
*
|
||||
* @author mkron
|
||||
*
|
||||
*/
|
||||
|
||||
public interface InterfaceSimpleProblem<T> {
|
||||
/**
|
||||
* Evaluate a double vector representing a possible problem solution as
|
||||
* part of an individual in the JavaEvA 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();
|
||||
|
||||
}
|
||||
|
23
src/simpleprobs/SimpleB1.java
Normal file
23
src/simpleprobs/SimpleB1.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package simpleprobs;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
public class SimpleB1 extends SimpleProblemBinary {
|
||||
public String globalInfo() {
|
||||
return "A simple B1 implementation, minimize bits in a binary vector.";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public int getProblemDimension() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
}
|
27
src/simpleprobs/SimpleF1.java
Normal file
27
src/simpleprobs/SimpleF1.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package simpleprobs;
|
||||
|
||||
|
||||
public class SimpleF1 extends SimpleProblemDouble {
|
||||
public String globalInfo() {
|
||||
return "A simple F1 implementation, find the minimum of a hyper parabola.";
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
// setting the return vector and return it
|
||||
res[0] = Math.sqrt(sum);
|
||||
return res;
|
||||
}
|
||||
|
||||
public int getProblemDimension() {
|
||||
return 20;
|
||||
}
|
||||
}
|
10
src/simpleprobs/SimpleProblemBinary.java
Normal file
10
src/simpleprobs/SimpleProblemBinary.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package simpleprobs;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.BitSet;
|
||||
|
||||
public abstract class SimpleProblemBinary implements InterfaceSimpleProblem<BitSet>, Serializable {
|
||||
public String globalInfo() {
|
||||
return "A simple binary problem. Override globalInfo() to insert more information.";
|
||||
}
|
||||
}
|
9
src/simpleprobs/SimpleProblemDouble.java
Normal file
9
src/simpleprobs/SimpleProblemDouble.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package simpleprobs;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class SimpleProblemDouble implements InterfaceSimpleProblem<double[]>, Serializable {
|
||||
public String globalInfo() {
|
||||
return "A simple double valued problem. Override globalInfo() to insert more information.";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user