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

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

?? chromosome.java

?? java neural networkin
?? JAVA
字號:
/**
 * Chromosome
 * Copyright 2005 by Jeff Heaton(jeff@jeffheaton.com)
 *
 * Example program from Chapter 9
 * Programming Neural Networks in Java
 * http://www.heatonresearch.com/articles/series/1/
 *
 * This class implements a single chromosome. This
 * will generally be the weight matrix to a neural network.
 *
 * This software is copyrighted. You may use it in programs
 * of your own, without restriction, but you may not
 * publish the source code without the author's permission.
 * For more information on distributing this code, please
 * visit:
 *    http://www.heatonresearch.com/hr_legal.php
 *
 * @author Jeff Heaton
 * @version 1.1
 */

class Chromosome {

  /**
   * The list of cities, which are the genes of this
   * chromosome.
   */
  protected int [] cityList;

  /**
   * The cost of following the cityList order of this
   * chromosome.
   */
  protected double cost;

  /**
   * The mutation percent.
   */
  protected double mutationPercent;

  /**
   * How much genetic material to take.
   */
  protected int cutLength;

  /**
   * The constructor, takes a list of cities to
   * set the initial "genes" to.
   *
   * @param cities The order that this chromosome would
   * visit the
   * cities. These cities can be thought of as the
   * genes of this chromosome.
   */
  Chromosome(City [] cities) {
    boolean taken[] = new boolean[cities.length];
    cityList = new int[cities.length];
    cost = 0.0;
    for ( int i=0;i<cityList.length;i++ ) taken[i] = false;
    for ( int i=0;i<cityList.length-1;i++ ) {
      int icandidate;
      do {
        icandidate = (int) ( 0.999999* Math.random() *
                             (double) cityList.length );
      } while ( taken[icandidate] );
      cityList[i] = icandidate;
      taken[icandidate] = true;
      if ( i == cityList.length-2 ) {
        icandidate = 0;
        while ( taken[icandidate] ) icandidate++;
        cityList[i+1] = icandidate;
      }
    }
    calculateCost(cities);
    cutLength = 1;
  }

  /**
   * Calculate the cost of of the specified list of
   * cities.
   *
   * @param cities A list of cities.
   */
  void calculateCost(City [] cities) {
    cost=0;
    for ( int i=0;i<cityList.length-1;i++ ) {
      double dist = cities[cityList[i]].proximity(cities[cityList[i+1]]);
      cost += dist;
    }
  }


  /**
   * Get the cost for this chromosome. This is the
   * amount of distance that must be traveled
   * for this chromosome's plan for moving through
   * the cities. The cost of a chromosome determines
   * its rank in terms of being able to mate and not
   * being killed off.
   */
  double getCost() {
    return cost;
  }

  /**
   * Get the ith city in this chromosome. For example the
   * value 3 would return the fourth city this chromosome
   * would visit. Similarly 0 would return the first city
   * that this chromosome would visit.
   *
   * @param i The city you want.
   * @return The ith city.
   */
  int getCity(int i) {
    return cityList[i];
  }

  /**
   * Set the order of cities that this chromosome
   * would visit.
   *
   * @param list A list of cities.
   */
  void setCities(int [] list) {
    for ( int i=0;i<cityList.length;i++ ) {
      cityList[i] = list[i];
    }
  }

  /**
   * Set the index'th city in the city list.
   *
   * @param index The city index to change
   * @param value The city number to place into the index.
   */
  void setCity(int index, int value) {
    cityList[index] = value;
  }

  /**
   * Set the cut. The cut determines how much
   * genetic material to take from each "partner"
   * when mating occurs.
   *
   * @param cut The new cut value.
   */
  void setCut(int cut) {
    cutLength = cut;
  }

  /**
   * Set the mutation percent. This is what percentage
   * of birth's will be mutated.
   *
   * @param prob The probability that a mutation will occur.
   */
  void setMutation(double prob) {
    mutationPercent = prob;
  }
  /**
   * Assuming this chromosome is the "mother" mate with
   * the passed in "father".
   *
   * @param father The father.
   * @param offspring1 Returns the first offspring
   * @param offspring2 Returns the second offspring.
   * @return The amount of mutation that was applied.
   */


  int mate(Chromosome father, Chromosome offspring1, Chromosome offspring2) {
    int cutpoint1 = (int) (0.999999*Math.random()*(double)(cityList.length-cutLength));
    int cutpoint2 = cutpoint1 + cutLength;

    boolean taken1 [] = new boolean[cityList.length];
    boolean taken2 [] = new boolean[cityList.length];
    int off1 [] = new int[cityList.length];
    int off2 [] = new int[cityList.length];

    for ( int i=0;i<cityList.length;i++ ) {
      taken1[i] = false;
      taken2[i] = false;
    }

    for ( int i=0;i<cityList.length;i++ ) {
      if ( i<cutpoint1 || i>= cutpoint2 ) {
        off1[i] = -1;
        off2[i] = -1;
      } else {
        int imother = cityList[i];
        int ifather = father.getCity(i);
        off1[i] = ifather;
        off2[i] = imother;
        taken1[ifather] = true;
        taken2[imother] = true;
      }
    }

    for ( int i=0;i<cutpoint1;i++ ) {
      if ( off1[i] == -1 ) {
        for ( int j=0;j<cityList.length;j++ ) {
          int imother = cityList[j];
          if ( !taken1[imother] ) {
            off1[i] = imother;
            taken1[imother] = true;
            break;
          }
        }
      }
      if ( off2[i] == -1 ) {
        for ( int j=0;j<cityList.length;j++ ) {
          int ifather = father.getCity(j);
          if ( !taken2[ifather] ) {
            off2[i] = ifather;
            taken2[ifather] = true;
            break;
          }
        }
      }
    }
    for ( int i=cityList.length-1;i>=cutpoint2;i-- ) {
      if ( off1[i] == -1 ) {
        for ( int j=cityList.length-1;j>=0;j-- ) {
          int imother = cityList[j];
          if ( !taken1[imother] ) {
            off1[i] = imother;
            taken1[imother] = true;
            break;
          }
        }
      }
      if ( off2[i] == -1 ) {
        for ( int j=cityList.length-1;j>=0;j-- ) {
          int ifather = father.getCity(j);
          if ( !taken2[ifather] ) {
            off2[i] = ifather;
            taken2[ifather] = true;
            break;
          }
        }
      }
    }

    offspring1.setCities(off1);
    offspring2.setCities(off2);

    int mutate = 0;
    if ( Math.random() < mutationPercent ) {
      int iswap1 = (int) (0.999999*Math.random()*(double)(cityList.length));
      int iswap2 = (int) (0.999999*Math.random()*(double)cityList.length);
      int i = off1[iswap1];
      off1[iswap1] = off1[iswap2];
      off1[iswap2] = i;
      mutate++;
    }
    if ( Math.random() < mutationPercent ) {
      int iswap1 = (int) (0.999999*Math.random()*(double)(cityList.length));
      int iswap2 = (int) (0.999999*Math.random()*(double)cityList.length);
      int i = off2[iswap1];
      off2[iswap1] = off2[iswap2];
      off2[iswap2] = i;
      mutate++;
    }
    return mutate;
  }

  /**
   * Sort the chromosomes by their cost.
   *
   * @param chromosomes An array of chromosomes to sort.
   * @param num How much of the chromosome list to sort.
   */
  public static void sortChromosomes(Chromosome chromosomes[],int num) {
    Chromosome ctemp;
    boolean swapped = true;
    while ( swapped ) {
      swapped = false;
      for ( int i=0;i<num-1;i++ ) {
        if ( chromosomes[i].getCost() > chromosomes[i+1].getCost() ) {
          ctemp = chromosomes[i];
          chromosomes[i] = chromosomes[i+1];
          chromosomes[i+1] = ctemp;
          swapped = true;
        }
      }
    }
  }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
麻豆国产精品777777在线| 国产精品卡一卡二卡三| 日韩中文字幕不卡| 91精品国产一区二区| 视频一区中文字幕国产| 日韩午夜在线影院| 国产一区二区在线视频| 中文字幕av一区二区三区| 色88888久久久久久影院按摩| 亚洲一级电影视频| 日韩精品一区二区三区在线播放 | 久久成人免费网| 久久综合九色综合欧美就去吻| 国产高清无密码一区二区三区| 国产精品乱码一区二三区小蝌蚪| 99久久免费国产| 青青草精品视频| 国产精品亲子伦对白| 欧美伦理影视网| 激情综合一区二区三区| 国产午夜精品久久久久久久| 91精品1区2区| 国产一区二区精品久久91| 亚洲精品高清在线| 日韩欧美一级片| 国产精品中文字幕一区二区三区| 国产精品国模大尺度视频| 欧美精选在线播放| 国产精品一级二级三级| 亚洲人成精品久久久久久| 精品三级在线看| av电影在线不卡| 蜜桃av一区二区在线观看| 亚洲人成网站色在线观看| 日韩免费观看2025年上映的电影| 成人性生交大片| 奇米综合一区二区三区精品视频 | 97超碰欧美中文字幕| 久久国产精品露脸对白| 亚洲精品国产视频| 欧美经典一区二区三区| 欧美精品一卡两卡| 91啪亚洲精品| 国产精品资源网| 青青草成人在线观看| 亚洲精品少妇30p| 国产精品天美传媒沈樵| 欧美一区二区在线视频| 欧美亚洲国产一卡| 99久久亚洲一区二区三区青草| 激情六月婷婷久久| 日本怡春院一区二区| 成人免费在线视频观看| 国产欧美精品国产国产专区| 欧美一级理论性理论a| 欧美午夜精品一区二区三区| 99久久伊人精品| 播五月开心婷婷综合| 国产福利视频一区二区三区| 久久99精品久久久久久动态图| 无码av免费一区二区三区试看 | 一区二区在线观看av| 中文成人av在线| 欧美国产亚洲另类动漫| 久久人人97超碰com| 精品欧美乱码久久久久久| 制服.丝袜.亚洲.另类.中文| 欧美色涩在线第一页| 欧美影院一区二区| 在线观看91精品国产入口| 在线观看日韩一区| 精品视频在线免费| 欧美乱妇23p| 日韩一区二区在线观看| 欧美一区二区三区性视频| 欧美一区二区三区四区五区| 制服丝袜av成人在线看| 日韩精品一区二区三区视频播放| 在线91免费看| 日韩免费成人网| 精品国产乱码久久久久久浪潮| 精品国产乱子伦一区| 日本一区二区三区在线不卡| 国产免费成人在线视频| 亚洲欧美区自拍先锋| 曰韩精品一区二区| 午夜欧美视频在线观看| 麻豆91在线播放免费| 国产成人丝袜美腿| 色综合久久中文综合久久牛| 欧美三级午夜理伦三级中视频| 5858s免费视频成人| 日韩天堂在线观看| 国产欧美1区2区3区| 亚洲三级电影全部在线观看高清| 一区二区三区免费看视频| 亚洲高清在线精品| 久久99精品久久久久久久久久久久 | 麻豆成人在线观看| 国产成人精品影视| 日本韩国欧美国产| 6080午夜不卡| 久久久久久久综合日本| 国产精品日韩成人| 亚洲一区二区av在线| 久久99精品国产麻豆不卡| 福利91精品一区二区三区| 91福利精品第一导航| 日韩精品一区二区三区蜜臀| 国产精品久久看| 日韩专区一卡二卡| 成人激情午夜影院| 911精品产国品一二三产区| 久久久精品日韩欧美| 亚洲一区二区av在线| 国产精品一区二区无线| 欧美日韩不卡在线| 国产精品日韩精品欧美在线| 青青草伊人久久| 色哟哟日韩精品| 久久综合成人精品亚洲另类欧美| 一区二区在线观看免费| 国产精品白丝jk白祙喷水网站| 91福利在线看| 久久久久久久一区| 婷婷中文字幕综合| 91免费版在线| 久久奇米777| 日韩经典一区二区| 在线看国产一区二区| 国产农村妇女毛片精品久久麻豆 | 精品国产1区二区| 亚洲国产裸拍裸体视频在线观看乱了| 久久99国内精品| 欧美日韩日日骚| 国产精品久久久久久久久免费丝袜| 秋霞影院一区二区| 欧美色中文字幕| 亚洲日本成人在线观看| 国产成人综合自拍| 精品久久久久久久久久久院品网 | 亚洲视频一区二区免费在线观看| 毛片一区二区三区| 欧美精品一卡两卡| 亚洲免费av观看| 成人久久18免费网站麻豆| 精品国产乱码久久久久久免费| 午夜久久久影院| 欧美日韩成人高清| 亚洲小少妇裸体bbw| 色丁香久综合在线久综合在线观看| 久久久久久黄色| 国产一区视频网站| 精品久久国产97色综合| 奇米影视一区二区三区小说| 国产一区二区视频在线| 91国产丝袜在线播放| 欧美韩国日本不卡| 国产麻豆精品一区二区| 日韩精品一区二区三区中文不卡| 视频一区视频二区中文| 欧美日韩成人一区二区| 午夜精品在线视频一区| 精品一区二区影视| 国产精品私人影院| 欧美系列日韩一区| 极品少妇xxxx偷拍精品少妇| 国产精品免费视频网站| 精品污污网站免费看| 激情久久五月天| 亚洲欧美视频在线观看视频| 制服视频三区第一页精品| 国产盗摄视频一区二区三区| 亚洲黄色性网站| 精品电影一区二区三区| 91美女在线看| 精品无人码麻豆乱码1区2区| 亚洲欧洲综合另类| 精品欧美久久久| 色综合天天狠狠| 欧美日韩一二区| 国产精品中文欧美| 亚洲aaa精品| 国产日韩v精品一区二区| 欧美日韩免费观看一区二区三区| 国产在线日韩欧美| 亚洲高清免费在线| 国产欧美精品一区二区色综合朱莉| 在线看不卡av| 福利一区福利二区| 免费日本视频一区| 一区二区不卡在线视频 午夜欧美不卡在| 欧美一级xxx| 91福利精品第一导航| 国产传媒欧美日韩成人| 免费的成人av| 亚洲在线免费播放| 日韩伦理免费电影| 国产亚洲欧美日韩在线一区| 91精品久久久久久久99蜜桃|