📄 griewank.java
字号:
/**
* 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
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* Please acknowledge the author(s) if you use this code in any way.
*
* @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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -