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;
      }
  • 相关阅读:
    天心阁漫步
    大美湘江
    easyui tree基本操作
    盗墓笔记
    半年了
    文件上传控件值发生变化后自动提交表单
    宁静的夏夜
    今天您给别人让座,将来别人给您让座
    优先队列priority_queue 用法详解
    POJ2387
  • 原文地址:https://www.cnblogs.com/gaoxiangde/p/4379878.html
Copyright © 2011-2022 走看看