杜鹃搜索与Java中的征费飞行

时间:2017-12-14 07:16:13

标签: algorithm optimization machine-learning

我试图学习关于布谷鸟搜索算法的概念。老实说,我正在使用java源代码学习布谷鸟搜索。我们知道杜鹃搜索使用征收分布进行随机游走。我有java源代码inslements布谷鸟搜索优化,但我怀疑使用征收分发的源代码。任何人都可以帮助我使用征税分配检查我的源代码吗?。

这是实现随机漫步的方法..

public CSSolution randomWalk (OptimizationProblem prob, String distribution) {
        int n = prob.getNumVar(); //2
        // creates a neighborhood of size 1 times the scaling factor
        double distanceSquared = Math.pow(rand.nextDouble() * 
           prob.getScalingFactor(),2);
       System.out.println("distance Squared : "+distanceSquared);
        // creates an ArrayList from 0 to n-1 (for indexing purposes only)
        ArrayList<Integer> varIndices = new ArrayList<Integer>(n);
        for (int i = 0; i < n; i++) {
            varIndices.add(i, i);
        }
        ArrayList<Double> vars = this.getVars();
        CSSolution newSol = new CSSolution(this.numVars);
        newSol.initializeWithNull();
        ArrayList<Double> newVars = newSol.getVars();
        for (int i = 0; i < n; i++) {
            /* Chooses a random variable index from the indices
             * of the remaining/unwalked variables. */
            int index = rand.nextInt(varIndices.size());
            // Finds the variable value that this index corresponds to.
            int varIndex = varIndices.get(index);
 //               System.out.println("varIndicesSize:"+varIndices.size()+" index: "+index+" varIndex: "+varIndex);
            double curVar = vars.get(varIndex);

            // use correct distribution to generate random double [0,1)
            double r;
            if (distribution == "weibull"){
                r = weibull.random(1.5, 1, new uniform());
            }
            else if(distribution == "levy"){
                r = 0.0;
            }
            else
                r = rand.nextDouble();
            // alters this variable coefficient by adding a random step between (-distance,distance)
            double distance = Math.sqrt(distanceSquared);
                System.out.println("distance : "+distance+" distance Squared : "+distanceSquared);
            double varStep = r*distance*2-distance;
            double newVar = curVar + varStep;
//          System.out.println("x"+varIndex+" : "+curVar+" to "+newVar);
                newVars.set(varIndex, newVar);
            // removes the variable that has already been visited
            varIndices.remove(index);
            // updates distance for next for loop
            distanceSquared -= Math.pow(varStep, 2);

        }
//        System.out.println("");
        return newSol;
    }

源代码:https://github.com/cloudrave/Optimizer

0 个答案:

没有答案