亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? antcolony.java

?? ACO JAVA 應用JAVA編寫的解決TSP問題的源代碼。多多交流
?? JAVA
字號:
/*----------------------------------------------------------------------  File    : AntColony.java  Contents: an ant colony of an ant colony optimization algorithm            for the traveling salesman problem  Author  : Christian Borgelt  History : 19.11.2005 file created            03.12.2005 trail and inverse distance exponents exchanged----------------------------------------------------------------------*/package acopt;import java.util.Random;/*--------------------------------------------------------------------*/public class AntColony {/*--------------------------------------------------------------------*/  /* --- instance variables --- */  protected TSP        tsp;     /* traveling salesman problem */  protected double[][] dists;   /* distances between vertices */  protected double[][] nears;   /* nearness factors: d_ij^{-\alpha} */  protected double[][] trail;   /* pheromone trail on edges */  protected double[][] delta;   /* change of pheromone trail on edges */  protected double[][] quals;   /* qualities of the edges */  protected boolean[]  visited; /* flags for visited vertices */  protected int[]      tour;    /* tour of current ant */  protected double     len;     /* and its length */  protected int[]      brun;    /* best tour in current run */  protected double     brlen;   /* and its length */  protected int[]      best;    /* best tour found so far */  protected double     bestlen; /* and its length */  protected double     avglen;  /* average tour length */  private   double     max;     /* maximal trail value */  private   double     avg;     /* average trail value */  protected int        antcnt;  /* number of ants in each run */  protected int        epoch;   /* current number of epochs */  protected double     exploit; /* prob. for exploiting the best edge */  protected double     alpha;   /* exponent for trail values */  protected double     beta;    /* exponent for distances */  protected double     evap;    /* pheromone evaporation factor */  protected double     layexp;  /* pheromone laying exponent */  protected double     elite;   /* best tour enhancement factor */  private   Random     rand;    /* random number generator */  private   int[]      dsts;    /* buffer for destinations */  private   double[]   sums;    /* buffer for probabilities */  /*------------------------------------------------------------------*/  public AntColony (TSP tsp, int antcnt, Random rand)  {                             /* --- create an ant colony */    this.tsp     = tsp;         /* note traveling salesman problem */    this.dists   = tsp.dists;   /* and its distance matrix */    int size     = tsp.size();  /* create the trail matrices */    this.nears   = new double[size][size];    this.trail   = new double[size][size];    this.delta   = new double[size][size];    this.quals   = new double[size][size];    this.visited = new boolean[size];    this.tour    = new int[size]; this.len     = Double.MAX_VALUE;    this.brun    = new int[size]; this.brlen   = Double.MAX_VALUE;    this.best    = new int[size]; this.bestlen = Double.MAX_VALUE;    this.dsts    = new int[size];    this.sums    = new double[size];    this.rand    = rand;        /* store the random number generator */    this.antcnt  = antcnt;      /* note the number of ants and */    this.exploit = 0.0;         /* prob. for exploiting best edge */    this.alpha   = 1.0;         /* weighting exponents for */    this.beta    = 1.0;         /* distance versus trail */    this.evap    = 0.1;         /* pheromone evaporation factor */    this.epoch   = 0;           /* initialize the epoch counter */  }  /* AntColony() */  /*------------------------------------------------------------------*/  public AntColony (TSP tsp, int antcnt)  { this(tsp, antcnt, new Random()); }  /*------------------------------------------------------------------*/  public TSP getTSP () { return this.tsp; }  /*------------------------------------------------------------------*/  public void   setExploit  (double exploit) { this.exploit = exploit; }  public void   setAlpha    (double alpha)   { this.alpha   = alpha; }  public void   setBeta     (double beta)    { this.beta    = beta; }  public void   setEvap     (double evap)    { this.evap    = evap; }  public void   setTrail    (double trail)   { this.elite   = elite; }  public void   setElite    (double elite)   { this.elite   = elite; }  /*------------------------------------------------------------------*/  public double getDist     (int i, int j) { return this.dists[i][j]; }  public double getTrail    (int i, int j) { return this.trail[i][j]; }  public double getTrailAvg ()             { return this.avg; }  public double getTrailMax ()             { return this.max; }  public int[]  getBestTour ()             { return this.best; }  public double getBestLen  ()             { return this.bestlen; }  public int    getEpoch    ()             { return this.epoch; }  /*------------------------------------------------------------------*/  public void init () { this.init(-1); }  public void init (double val)  {                             /* --- initialize nearness and trail */    int    i, j;                /* loop variables */    double sum = 0;             /* sum of edge lengths */    for (i = this.tour.length; --i >= 0; )      for (j = this.tour.length; --j >= 0; )        sum += this.dists[i][j];/* compute the average tour length */    this.avglen = sum /this.tour.length;    if (val <= 0) val = 1;      /* check and adapt initial value */    for (i = this.tour.length; --i >= 0; ) {      for (j = this.tour.length; --j >= 0; ) {        this.nears[i][j] = Math.pow(this.dists[i][j], -this.beta);        this.trail[i][j] = val; /* compute nearness from distance */      }                         /* and set all trail elements */    }                           /* to the same value */    this.max = this.avg = val;  /* set maximal/average trail value */    this.bestlen = Double.MAX_VALUE;    this.epoch  = 0;            /* init. length of best tour */  }  /* init() */               /* and the epoch counter */  /*------------------------------------------------------------------*/  private static int find (double vec[], int n, double val)  {                             /* --- find edge based on random val. */    int i, k;                   /* left and middle element */    for (--n, i = 0; i < n; ) { /* do a binary search */      k = (i +n) >> 1;          /* in the given vector */      if (vec[k] < val) i = k+1;      else              n = k;  /* i and n are the boundaries */    }                           /* of the section still to search */    return i;                   /* return index i for which it is */  }  /* find() */               /* vec[i-1] < val <= vec[i] */  /*------------------------------------------------------------------*/  private void placePhero (int[] tour, double amount)  {                             /* --- place pheromone on ant's tour */    int     i;                  /* loop variable */    int     src, dst;           /* source and destination of an edge */    boolean sym;                /* whether TSP is symmetric */    src = this.tour[0];         /* get the start of the tour */    for (i = tour.length; --i >= 0; ) {      dst = src; src = tour[i]; /* traverse the vertices on the tour */      this.delta[src][dst] += amount;    }                           /* place pheromone on the edge */  }  /* placeTrail() */  /*------------------------------------------------------------------*/  public double runAnt ()  {                             /* --- run one ant of the colony */    int    i, j, n;             /* loop variables, counter */    int    src, dst = 0;        /* source and dest. of next edge */    double emax;                /* maximal value of an edge */    double sum;                 /* sum of edge values */    double chg;                 /* change of trail */    /* --- initialize variables --- */    for (i = this.visited.length; --i >= 0; )      this.visited[i] = false;  /* clear the visited flags */    this.len = 0;               /* and the tour length */    /* --- run the ant --- */    src = this.rand.nextInt(this.tour.length);    this.tour[0]      = src;    /* randomly select the vertex */    this.visited[src] = true;   /* the ant starts from */    for (i = 0; ++i < this.tour.length; ) {      if ((this.exploit > 0)    /* if to exploit best known edge */      &&  (rand.nextDouble() < this.exploit)) {        emax = -1.0;            /* init. the best edge value */        for (j = this.tour.length; --j >= 0; ) {          if (!this.visited[j]  /* traverse edges to unvisited verts. */          &&  (this.quals[src][j] > emax)) {            emax = this.quals[src][j]; dst = j; }	} }                     /* find the best edge to follow */      else {                    /* if to choose edge randomly */        sum = 0;                /* init. the quality sum */        for (j = n = 0; j < this.tour.length; j++) {          if (this.visited[j]) continue;          sum += this.quals[src][j];          this.sums[n  ] = sum; /* collect and sum the qualities */          this.dsts[n++] = j;   /* of the different edges */        }                       /* to unvisited destinations */        j   = find(this.sums, n, sum *rand.nextDouble());        dst = this.dsts[j];     /* choose destination randomly */      }                         /* based on the edge qualities */      this.visited[dst] = true; /* mark the destination as visited */      this.len += this.dists[src][dst];      this.tour[i] = src = dst; /* sum the edge lengths and */    }                           /* add the vertex to the tour */    this.len += this.dists[src][this.tour[0]];    /* --- place pheromone --- */    chg = this.avglen/this.len; /* compute amount of pheromone */    if (this.layexp != 1) chg = Math.pow(chg, this.layexp);    this.placePhero(this.tour, chg);    return this.len;            /* return the length of the tour */  }  /* runAnt() */  /*------------------------------------------------------------------*/  public double runAllAnts ()  {                             /* --- run all ants of the colony */    int    i, j;                /* loop variables */    double t, min;              /* new/minimal trail value */    double stick;               /* stick factor for pheromone */    /* --- initialize the edge qualities --- */    for (i = this.delta.length; --i >= 0; ) {      for (j = this.delta.length; --j >= 0; ) {        this.delta[i][j] = 0;   /* init. the trail change matrix */        this.quals[i][j] = this.nears[i][j]                         * ((this.alpha == 1.0) ? this.trail[i][j]                         : Math.pow(this.trail[i][j], this.alpha));      }                         /* compute the current qualities */    }                           /* of the different edges */    /* --- run the ants --- */    this.brlen = Double.MAX_VALUE;    for (i = this.antcnt; --i >= 0; ) {      this.runAnt();            /* run an ant on the trail */      if (this.len >= this.brlen) continue;      System.arraycopy(this.tour, 0, this.brun, 0, this.brun.length);      this.brlen = this.len;    /* if the new tour is better than */    }                           /* the currently best, replace it */    if (this.brlen < this.bestlen) {      System.arraycopy(this.brun, 0, this.best, 0, this.best.length);      this.bestlen = this.brlen;/* if the best run tour is better */    }                           /* than the best, replace it */    if (this.elite > 0) {       /* strengthen best tour */      t = this.avglen/this.bestlen;      if (this.layexp != 1) t = Math.pow(t, this.layexp);      this.placePhero(this.best, this.elite *this.antcnt *t);    }                           /* place pheromone on best tour */    /* --- update trail matrix --- */    min = this.avg/this.tour.length;    this.max = this.avg = 0;    /* reinit. the max./avg. trail value */    stick    = 1 -this.evap;    /* and compute stick factor */    if (this.tsp.isSymmetric()){/* if symmetric distances */      for (i = this.trail.length; --i >= 0; ) {        for (j = i; --j >= 0; ) {          t = stick     * this.trail[i][j]            + this.evap *(this.delta[i][j] +this.delta[j][i]);          if (t < min) t = min; /* compute the new trail value */          this.trail[i][j] =    /* from both edge directions */          this.trail[j][i] = t; /* and store it symmetrically */          if (t > this.max) this.max = t;          this.avg += t;        /* update the trail matrix, */        }                       /* find highest trail value, */      }                         /* and sum the trail values */      this.avg /= 0.5 *this.tour.length *this.tour.length; }    else {                      /* if asymmetric distances */      for (i = this.trail.length; --i >= 0; ) {        for (j = this.trail.length; --j >= 0; ) {          t = stick     *this.trail[i][j]            + this.evap *this.delta[i][j];          if (t < min) t = min; /* compute the new trail value */          this.trail[i][j] = t; /* and store it asymmetrically */          if (t > this.max) this.max = t;          this.avg += t;        /* update the trail matrix, */        }                       /* find highest trail value, */      }                         /* and sum the trail values */      if (this.tour.length > 1) /* compute average trail value */        this.avg /= this.tour.length *(this.tour.length -1);    }    this.epoch++;               /* count the run */    return this.bestlen;        /* return length of best tour */  }  /* runAllAnts() */}  /* class AntColony */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色哟哟在线观看一区二区三区| 欧美一区二区三区在线电影| 欧美三级日韩三级国产三级| 精品美女在线观看| 一区二区三区成人在线视频| 国产乱对白刺激视频不卡| 91国模大尺度私拍在线视频| 国产日韩欧美不卡在线| 午夜视频在线观看一区二区| 成人激情小说乱人伦| 国产精品国产三级国产aⅴ原创| 一片黄亚洲嫩模| 成人午夜伦理影院| 精品国产a毛片| 蜜臀久久99精品久久久画质超高清| 97久久久精品综合88久久| 久久久噜噜噜久久人人看| 日本亚洲免费观看| 欧美精品久久99久久在免费线| 亚洲视频1区2区| 成人a级免费电影| 国产三级久久久| 国产伦精品一区二区三区免费迷 | 精品国产电影一区二区| 亚洲r级在线视频| 色婷婷国产精品综合在线观看| 国产日韩av一区| 国产一区欧美一区| 精品播放一区二区| 久久99国内精品| 欧美日韩一区二区三区免费看| 中文字幕日韩av资源站| 高清久久久久久| 国产精品电影一区二区三区| 国产成人亚洲综合色影视| 精品盗摄一区二区三区| 日韩二区三区四区| 欧美tickle裸体挠脚心vk| 麻豆精品久久精品色综合| 3atv在线一区二区三区| 日本伊人色综合网| 欧美不卡一二三| 国产在线精品一区二区| 久久久久久久久99精品| 成人网男人的天堂| 亚洲国产精品ⅴa在线观看| av成人免费在线观看| 亚洲欧美一区二区三区孕妇| 色噜噜夜夜夜综合网| 五月综合激情网| 欧美大片日本大片免费观看| 国产乱一区二区| 国产精品久久久久aaaa| 色诱视频网站一区| 视频一区视频二区中文| 精品国产人成亚洲区| 成人性生交大片免费看中文 | 麻豆免费看一区二区三区| 欧美www视频| 成人黄色软件下载| 亚洲成人免费看| 2021国产精品久久精品| 99久久精品情趣| 亚洲一区成人在线| 久久蜜桃av一区精品变态类天堂| 国产精品99久久久久久似苏梦涵| 亚洲欧美国产高清| 91精品国产色综合久久不卡电影 | 99国产精品国产精品毛片| 亚洲一区二区欧美激情| 欧美精品一区在线观看| 91黄色在线观看| 久久国产夜色精品鲁鲁99| 国产精品久久网站| 91精品欧美综合在线观看最新| 国产自产视频一区二区三区| 尤物在线观看一区| 精品999在线播放| 日本精品裸体写真集在线观看 | 99久久99久久精品免费看蜜桃| 午夜精品视频在线观看| 欧美国产成人在线| 欧美一区二区三区免费在线看| 福利一区在线观看| 日本91福利区| 亚洲精品综合在线| 国产日韩欧美不卡在线| 欧美一级一级性生活免费录像| 国产91精品露脸国语对白| 人人爽香蕉精品| 亚洲精品欧美激情| 国产精品人成在线观看免费| 欧美一区二区三区色| 91小视频免费看| 国产v综合v亚洲欧| 日韩中文欧美在线| 一二三区精品视频| 中文字幕综合网| 欧美激情在线免费观看| 精品国产区一区| 日韩欧美一区二区在线视频| 日本精品免费观看高清观看| 成人一区在线看| 国内精品国产成人| 黄页网站大全一区二区| 蜜桃一区二区三区在线观看| 亚洲国产你懂的| 亚洲国产欧美在线| 一区二区理论电影在线观看| 亚洲欧洲成人av每日更新| 久久精品免费在线观看| 精品日韩一区二区三区免费视频| 欧美精品丝袜中出| 欧美精品乱人伦久久久久久| 欧美视频在线观看一区| 日本久久一区二区| 欧美日韩一区在线观看| 欧美精品在欧美一区二区少妇| 欧美日韩国产综合视频在线观看| 欧美在线短视频| 欧美日韩成人综合天天影院| 欧美精品在线视频| 日韩欧美国产高清| 精品成人佐山爱一区二区| 亚洲精品在线网站| 亚洲国产精品精华液2区45| 中文字幕在线不卡| 亚洲自拍偷拍九九九| 三级亚洲高清视频| 免费久久精品视频| 国产91精品一区二区| 91麻豆国产在线观看| 91行情网站电视在线观看高清版| 色婷婷综合在线| 欧美一区二区三区日韩| 亚洲精品在线免费观看视频| 国产欧美日韩在线观看| 日韩毛片视频在线看| 亚洲bt欧美bt精品777| 麻豆精品视频在线| 成人妖精视频yjsp地址| 91福利小视频| 欧美一卡二卡在线观看| 欧美国产禁国产网站cc| 亚洲成a人片在线不卡一二三区| 日韩成人精品视频| 高清在线成人网| 在线精品国精品国产尤物884a| 欧美群妇大交群的观看方式| 欧美v亚洲v综合ⅴ国产v| 亚洲图片另类小说| 久久电影网站中文字幕| 99re成人在线| 欧美精品一区在线观看| 一区二区三区四区不卡在线| 日本视频中文字幕一区二区三区| 国产成人免费在线| 欧美日韩在线综合| 中文字幕乱码日本亚洲一区二区| 亚洲午夜精品在线| 国产成人精品免费网站| 欧美人狂配大交3d怪物一区| 国产欧美精品一区二区色综合| 亚洲一区二区欧美| 成人福利电影精品一区二区在线观看| 欧美色电影在线| 国产精品国产三级国产| 另类小说图片综合网| 久久久久久久综合狠狠综合| 亚洲综合激情小说| 成人免费黄色在线| 日韩欧美一级精品久久| 亚洲资源在线观看| www.亚洲激情.com| 国产亚洲欧美中文| 免费成人小视频| 在线观看国产一区二区| 国产精品剧情在线亚洲| 国产米奇在线777精品观看| 欧美久久久久久久久中文字幕| 亚洲欧美福利一区二区| 成人综合婷婷国产精品久久| 精品国产伦一区二区三区观看体验| 亚洲综合小说图片| 色94色欧美sute亚洲线路一久| 国产精品天干天干在观线| 久久99精品久久久久久国产越南 | 91免费看片在线观看| 久久久久久久网| 国产精品综合二区| 欧美电影免费观看高清完整版在线| 亚洲h在线观看| 欧美日韩亚洲高清一区二区| 亚洲免费av网站| 色悠悠久久综合| 亚洲主播在线播放| 欧美少妇一区二区| 亚洲第一久久影院| 91精品午夜视频| 视频在线在亚洲|