📄 fitnessalgorithmf2.java
字号:
/* * FitnessAlgorithmF2.java * * Created on March 10, 2003, 2:04 PM */package com.adaptiveview.ospso.test;import com.adaptiveview.ospso.*;import com.adaptiveview.ospso.dmi.*;/**<code>Fitness = 0.0 - abs(5(x^2) + 2*(y^3) - (z/w)^2 + 4); dimension boundaries = [-100.0..100.0]; *Boundary Type = Constraint.BOUNCE.</code> * * @author AdaptiveView.com */public class FitnessAlgorithmF2 implements IFitnessAlgorithm, DMI_AboutFitnessAlgorithms { private int dimensions; private Constraint dimensionConstraint; private String problemDescription; private String boundaryTypeName; /** Creates a new instance of FitnessAlgorithm1 */ public FitnessAlgorithmF2() { // Set the following according to problem in calculateFitness() dimensions = 4; dimensionConstraint = new Constraint(-100.0,100.0,Constraint.BOUNCE); boundaryTypeName = "BOUNCE"; problemDescription = "abs(5(x^2) + 2*(y^3) - (z/w)^2 + 4) = 0.0"; } public double calculateFitness(LocationChange location) { double[] c = location.getCopyOfCoordinates(); double answer = 0.0; /* Problem: 5(x^2) + 2*(y^3) - (z/w)^2 + 4 * Data sources: x = c[0]; y = c[1]; z = c[2]; w = c[3]; */ answer += 5.0 * Math.pow(c[0],2.0); answer += 2.0 * Math.pow(c[1],3.0); answer -= Math.pow((c[2] / c[3]),2.0); answer += 4.0; 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 + -