⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fitnessalgorithmf1.java

📁 使用java编写的关于通讯及串口编程所必需的类库
💻 JAVA
字号:
/* * FitnessAlgorithmF1.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 - (x^2 + y^2 + z^2 + w^2); dimension boundaries = [-10.0..10.0]; *Boundary Type = Constraint.WRAP.</code> * * @author  AdaptiveView.com */public class FitnessAlgorithmF1 implements IFitnessAlgorithm, DMI_AboutFitnessAlgorithms {        private int dimensions;    private Constraint dimensionConstraint;    private String problemDescription;    private String boundaryTypeName;        /** Creates a new instance of FitnessAlgorithm1 */    public FitnessAlgorithmF1() {        // Set the following according to problem in calculateFitness()        dimensions = 4;         dimensionConstraint = new Constraint(-10.0,10.0,Constraint.WRAP);        boundaryTypeName = "WRAP";        problemDescription = "abs(x^2 + y^2 + z^2 + w^2) = 0.0";    }        public double calculateFitness(LocationChange location) {        double[] c = location.getCopyOfCoordinates();        double answer = 0.0;               /* Problem:      x^2 + y^2 + z^2 + w^2        * Data sources: x = c[0]; y = c[1]; z = c[2]; w = c[3];        */                answer += Math.pow(c[0],2.0);        answer += Math.pow(c[1],2.0);        answer += Math.pow(c[2],2.0);        answer += Math.pow(c[3],2.0);                return convertToFitness(answer);    }        private double convertToFitness(double answer) {        return 0.0 - Math.abs(answer);    }     public int getDimensions() {        return dimensions;    }        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 + -