zoukankan      html  css  js  c++  java
  • 模拟退火算法

     //模拟退火算法效果稍稍好于爬山算法,核心思想是以一定的概率接受一个比当前解更差的解

    public Individual<G, X> solve(final IObjectiveFunction<X> f) {

        Individual<G, X> pcur, pnew;
        Random r =new Random();
        pcur = new Individual<>();
        pnew= new Individual<>();

        pcur.g = this.nullary.create(this.random);
        pcur.x = this.gpm.gpm(pcur.g);
        pcur.v = f.compute(pcur.x); 
        X tmp= pcur.x;

        int t=1;
        double Temp;

        while (!(this.termination.shouldTerminate())) {
          pnew.g = this.unary.mutate(pcur.g, this.random);
          pnew.x = this.gpm.gpm(pnew.g);
          pnew.v = f.compute(pnew.x);
          double value=pnew.v - pcur.v;
          if (value<=0) {
            pcur.assign(pnew);
            if(f.compute(pcur.x)<f.compute(tmp))
              tmp=pcur.x;
          }
          else{
            Temp=this.temperature. getTemperature(t);


            if(r.nextDouble()<Math.exp(-(value/Temp))){
              pcur.assign(pnew);
            }
          }
          t++;
        }
        pcur.x=tmp;
        pcur.v = f.compute(pcur.x); 
        return pcur;
      }
  • 相关阅读:
    转:深入 AngularUI Router
    angularJS $scope的$apply方法实现model刷新
    CSS 如何让 height:100%; 起作用
    【AngularJs】---$sce 输出Html
    angular 组件之间传值
    kendo Grid 列添加自定义模板
    关于“内控点”
    关于总结
    咏春
    一只老鼠夹
  • 原文地址:https://www.cnblogs.com/gaoxiangde/p/4379878.html
Copyright © 2011-2022 走看看