📄 fitnessalgorithmf4.java
字号:
/* * FitnessAlgorithmF4.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(Math.PI - (x / y)); dimension boundaries = [100.0..550.0]; *Boundary Type = Constraint.BOUNCE.</code> * * @author AdaptiveView.com */public class FitnessAlgorithmF4 implements IFitnessAlgorithm, DMI_AboutFitnessAlgorithms { private int dimensions; private Constraint dimensionConstraint; private String problemDescription; private String boundaryTypeName; /** Creates a new instance of FitnessAlgorithm1 */ public FitnessAlgorithmF4() { // Set the following according to problem in calculateFitness() dimensions = 2; dimensionConstraint = new Constraint(100.0,550.0,Constraint.BOUNCE); boundaryTypeName = "BOUNCE"; problemDescription = "x / y = Math.PI"; } public double calculateFitness(LocationChange location) { double[] c = location.getCopyOfCoordinates(); double answer = 0.0; /* Problem: x / y * Data sources: x = c[0]; y = c[1] */ answer += c[0] / c[1]; return 0.0 - Math.abs(Math.PI - 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 + -