griewank.java

来自「基于差分进化与粒子群混合算法优化源程序,这是一个java语言编制的源程序,很实用」· Java 代码 · 共 46 行

JAVA
46
字号
/**
 * Description: Griewank function
 * X*(Optimal point):
 * X1=0
 * X2=-1
 * Y*(Optimal value)
 * Y1=3
 *
 * @ Author        Create/Modi     Note
 * Xiaofeng Xie    Dec 28, 2001
 * Xiaofeng Xie    Mar 02, 2003
 * Xiaofeng Xie    May 11, 2004
 *
 * @version 1.0
 * @Since MAOS1.0
 *
 * @References:
 * [1] Shi Y H, Eberhart R C. Empirical study of particle swarm optimization.
 * Proc. Congress on Evolutionary Computation, 1999: 1945-1950
 */

package problem.unconstrained;

import problem.*;

public class Griewank extends UnconstrainedProblemEncoder {
  private static int NX = 30; //number of variables
  public Griewank() throws Exception {
    super(NX);
    for(int i=0; i<NX; i++) {
      setDefaultXAt(i, -600, 600); //the range of each variable
    }
  }

  //calculates the objective value
  public double calcTarget(double[] VX) {
    double value1 = 0;
    double value2 = 1;
    for (int i=0; i<NX; i++) {
      value1 += Math.pow(VX[i],2)/4000.0;
      value2 *= Math.cos(VX[i]/Math.sqrt(i+1));
    }
    return value1-value2+1;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?