eva2/src/javaeva/server/go/problems/F12Problem.java
2008-03-11 10:57:37 +00:00

107 lines
3.3 KiB
Java

package javaeva.server.go.problems;
import javaeva.server.go.individuals.AbstractEAIndividual;
import javaeva.server.go.individuals.ESIndividualDoubleData;
import javaeva.server.go.individuals.InterfaceDataTypeDouble;
import javaeva.server.go.populations.Population;
/**
* Created by IntelliJ IDEA.
* User: streiche
* Date: 30.06.2005
* Time: 14:59:33
* To change this template use File | Settings | File Templates.
*/
public class F12Problem extends F1Problem implements java.io.Serializable {
public F12Problem() {
this.m_Template = new ESIndividualDoubleData();
}
public F12Problem(F12Problem b) {
super(b);
}
/** This method returns a deep clone of the problem.
* @return the clone
*/
public Object clone() {
return (Object) new F12Problem(this);
}
/** This method inits a given population
* @param population The populations that is to be inited
*/
public void initPopulation(Population population) {
AbstractEAIndividual tmpIndy;
// this.m_OverallBest = null;
population.clear();
((InterfaceDataTypeDouble)this.m_Template).setDoubleDataLength(this.m_ProblemDimension);
double[][] range = new double[this.m_ProblemDimension][2];
for (int i = 0; i < range.length; i++) {
range[i][0] = -5.0;
range[i][1] = 5.0;
}
((InterfaceDataTypeDouble)this.m_Template).SetDoubleRange(range);
for (int i = 0; i < population.getPopulationSize(); i++) {
tmpIndy = (AbstractEAIndividual)((AbstractEAIndividual)this.m_Template).clone();
tmpIndy.init(this);
population.add(tmpIndy);
}
// population init must be last
// it set's fitcalls and generation to zero
population.init();
}
/** Ths method allows you to evaluate a double[] to determine the fitness
* @param x The n-dimensional input vector
* @return The m-dimensional output vector.
*/
public double[] eval(double[] x) {
double[] result = new double[1];
double tmp = -5;
result[0] = 0;
for (int i = 1; i < x.length-1; i++) {
tmp += Math.pow(x[i], 2);
}
result[0] = (Math.exp(-5*x[0]*x[0])+2*Math.exp(-5*Math.pow(1-x[0], 2)))*Math.exp(tmp);
return result;
}
/** This method returns a string describing the optimization problem.
* @return The description.
*/
public String getStringRepresentationForProblem() {
String result = "";
result += "F12 Galar:\n";
result += "Parameters:\n";
result += "Dimension : " + this.m_ProblemDimension +"\n";
result += "Noise level : " + this.m_Noise + "\n";
result += "Solution representation:\n";
//result += this.m_Template.getSolutionRepresentationFor();
return result;
}
/**********************************************************************************************************************
* These are for GUI
*/
/** This method allows the CommonJavaObjectEditorPanel to read the
* name to the current object.
* @return The name.
*/
public String getName() {
return "F12 Problem";
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "Galar Function";
}
}