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

📄 swisscheese4d.java

📁 模拟退火是一种启发式算法
💻 JAVA
字号:
package org.theblueplanet.annealing.examples;

import org.theblueplanet.annealing.ObjectiveFunction;

/**
 *  JAVA Wrapper around the example in Numerical Recipes in C,
 *  example book, pp 183
 *
 * @author     Charles M間nin
 * @since    October 29, 2001
 * @version    1.0
 */
public class SwissCheese4d implements ObjectiveFunction {
    private final static int NDIM    = 4;
    private final static double RAD  = 0.3;
    private final static double AUG  = 2.0;

    /**
     *  Gets the Ndim attribute of the SwissCheese4d object
     *
     * @return    The number of dimensions
     */
    public int getNdim() {
        return NDIM;
    }

    /**
     *  The 4d swiss cheese function
     *
     * @param  vertex  The vertices of the Simplex that the function is to evaluate
     * @return          The value of the function at the vertices
     */
    public static double func(double[] vertex) {
        double sumd   = 0;
        double sumr   = 0;
        double[] wid  = { 0.0, 1.0, 3.0, 10.0, 30.0 };
        for (int jj = 1; jj <= NDIM; jj++) {        //Fortran convention
            double q  = vertex[jj] * wid[jj];
            double r  = (double) (q >= 0 ? (int) (q + 0.5) : -(int) (0.5 - q));
            sumr += q * q;
            sumd += (q - r) * (q - r);
        }
        return 1 + sumr * (1 + (sumd > RAD * RAD ? AUG : AUG * sumd / (RAD * RAD)));
    }

    /**
     *  The main program to test the SwissCheese4d class
     *
     * @param  args  The command line arguments
     */
    public static void main(String[] args) {
        double[] vertex  = { 0, 0, 0, -10, 30 };
        System.out.println("" + func(vertex));
    }

}

⌨️ 快捷键说明

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