simpleobjectivefunction2.java

来自「eclispse下运行 模拟退火算法的java源代码」· Java 代码 · 共 42 行

JAVA
42
字号
package org.theblueplanet.annealing.examples;

import org.theblueplanet.annealing.ObjectiveFunction;

/**
 *  A NDIM-dimension paraboloid
 *
 * @author     Charles M間nin
 * @since    November 3, 2001
 * @version    1.0
 */
public class SimpleObjectiveFunction2 implements ObjectiveFunction {
    private final static int NDIM      = 8;
    private final static double offset = -10.;

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

    /**
     *  The paraboloid algorithm
     *
     * @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 sumr  = 0;
        for (int jj = 1; jj <= NDIM; jj++) {//Fortran convention
            double q  = vertex[jj];
            sumr += q * q;
        }
        return (sumr + offset);
    }

}

⌨️ 快捷键说明

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