📄 fitnessalgorithmf5.java
字号:
/* * FitnessAlgorithmF5.java * * Created on March 10, 2003, 2:04 PM */package com.adaptiveview.ospso.test;import com.adaptiveview.ospso.*;import com.adaptiveview.ospso.dmi.*;/**Shaffer's test function "f6" -- *<code>Fitness = 0.0 - abs(0.5 - ((sin(sqrt(x^2 + y^2))^2 - 0.5)/((1.0 + 0.001*(x^2 + y^2))^2)); * Dimension Boundaries = [-25.0..25.0]; * Boundary Type = Constraint.BOUNCE.</code> * * @author AdaptiveView.com */public class FitnessAlgorithmF5 implements IFitnessAlgorithm, DMI_AboutFitnessAlgorithms { private int dimensions; private Constraint dimensionConstraint; private String problemDescription; private String boundaryTypeName; /** Creates a new instance of FitnessAlgorithm1 */ public FitnessAlgorithmF5() { // Set the following according to problem in calculateFitness() dimensions = 2; dimensionConstraint = new Constraint(-100.0,100.0,Constraint.BOUNCE); boundaryTypeName = "BOUNCE"; problemDescription = "Shaffer's f6: 0.5 + ((sin(sqrt(x^2 + y^2))^2 - 0.5)/((1.0 + 0.001*(x^2 + y^2))^2) = 0.0"; } public double calculateFitness(LocationChange location) { double[] c = location.getCopyOfCoordinates(); double answer = 0.0; /* Problem: 0.5 + ((sin(sqrt(x^2 + y^2))^2 - 0.5)/((1.0 + 0.001*(x^2 + y^2))^2) * Data sources: x = c[0]; y = c[1]; */ double x2y2 = c[0]*c[0]+c[1]*c[1]; double n = Math.pow(Math.sin(Math.sqrt(x2y2)),2.0) - 0.5; double d = Math.pow((1.0 + 0.001*x2y2),2.0); answer = 0.5 + (n / d); return convertToFitness(answer); } private double convertToFitness(double answer) { return 0.0 - Math.abs(answer); } /** Returns the number of dimesnions (unknowns) in the solution space. * @return the number of dimesnions */ public int getDimensions() { return dimensions; } /** Returns a reference to the dimension Constraint instance. * @return the dimension Constraint */ public Constraint getDimensionConstraint() { return dimensionConstraint; } /** Returns a description of the solution space. * @return a String describing the solution space. */ public String toString() { StringBuffer s = new StringBuffer(); s.append(problemDescription); s.append(" (Dimensions="); s.append(dimensions); s.append("; Dimension[Minimum="); s.append(dimensionConstraint.getMinimum()); s.append(", Maximum="); s.append(dimensionConstraint.getMaximum()); s.append(", BoundaryType='"); s.append(boundaryTypeName); s.append("'])"); return s.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -