|
package com.dam.heuristic.afas.test;
import java.io.Serializable;
import java.util.Random;
/**
* 人工鱼
*/
public class Fish implements Serializable {
//记录位置的维度(x,y,z,……)
private int dimension;
//记录位置
private double[] position;
//鱼的适应度
private double fitness;
//位置每个维度坐标的区间
private double[][] axisScopeArr;
//目标函数是否为取最大值
private boolean isGetMax;
public Fish(int dimension, double[][] axisScopeArr, boolean isGetMax) {
this.dimension = dimension;
this.position = new double[this.dimension];
this.axisScopeArr = axisScopeArr;
this.isGetMax = isGetMax;
this.fitness = 0;
}
/**
* 初始化鱼的位置及适应度
*/
public void initFishMessage() {
Random random = new Random();
//初始化位置
for (int i = 0; i < this.dimension; i++) {
position[i] = random.nextDouble() * (this.axisScopeArr[i][1] - this.axisScopeArr[i][0]) + this.axisScopeArr[i][0];
}
//初始化适应度
this.fitness = new ObjectFunction().objectFunction(position,this.isGetMax);
}
public int getDimension() {
return dimension;
}
public void setDimension(int dimension) {
this.dimension = dimension;
}
public double[] getPosition() {
return position;
}
public void setPosition(double[] position) {
this.position = position;
}
public double getFitness() {
return fitness;
}
public void setFitness(double fitness) {
this.fitness = fitness;
}
} |
|