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

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

?? jgapgreedycrossoverengine.java.svn-base

?? Traveling Salesman Problem Java Genetic Algorithm Solution, Hope all enjoy it.
?? SVN-BASE
字號:
/*
 * $Source: f:/cvs/prgm/tsp/src/org/saiko/ai/genetics/tsp/engines/jgapCrossover/JGapGreedyCrossoverEngine.java,v $
 * $Id: JGapGreedyCrossoverEngine.java,v 1.4 2005/08/24 12:33:13 dsaiko Exp $
 * $Date: 2005/08/24 12:33:13 $
 * $Revision: 1.4 $
 * $Author: dsaiko $
 *
 * Traveling Salesman Problem genetic algorithm.
 * This source is released under GNU public licence agreement.
 * dusan@saiko.cz
 * http://www.saiko.cz/ai/tsp/
 * 
 * Change log:
 * $Log: JGapGreedyCrossoverEngine.java,v $
 * Revision 1.4  2005/08/24 12:33:13  dsaiko
 * Documentation finished
 *
 * Revision 1.3  2005/08/23 23:18:04  dsaiko
 * Finished.
 *
 * Revision 1.2  2005/08/22 22:13:53  dsaiko
 * Packages rearanged
 *
 * Revision 1.1  2005/08/22 22:08:51  dsaiko
 * Created engines with heuristics
 *
 * Revision 1.1  2005/08/12 23:52:17  dsaiko
 * Initial revision created
 *
 */

package org.saiko.ai.genetics.tsp.engines.jgapCrossover;

import java.util.Random;

import org.jgap.Chromosome;
import org.jgap.Configuration;
import org.jgap.DefaultFitnessEvaluator;
import org.jgap.FitnessFunction;
import org.jgap.Gene;
import org.jgap.Genotype;
import org.jgap.InvalidConfigurationException;
import org.jgap.Population;
import org.jgap.RandomGenerator;
import org.jgap.event.EventManager;
import org.jgap.impl.BestChromosomesSelector;
import org.jgap.impl.ChromosomePool;
import org.jgap.impl.GreedyCrossover;
import org.jgap.impl.IntegerGene;
import org.jgap.impl.StockRandomGenerator;
import org.jgap.impl.SwappingMutationOperator;
import org.saiko.ai.genetics.tsp.City;
import org.saiko.ai.genetics.tsp.TSPChromosome;
import org.saiko.ai.genetics.tsp.TSPConfiguration;
import org.saiko.ai.genetics.tsp.TSPEngine;
import org.saiko.ai.genetics.tsp.engines.simpleUnisexMutator.SimpleUnisexMutatorEngine;

/**
 * @author Dusan Saiko (dusan@saiko.cz)
 * Last change $Date: 2005/08/24 12:33:13 $
 * 
 * Implements solving the Traveling Salesman Problem using JGap libraries
 * and connecting this to TSPEngine interface so it can be used in the TSP gui
 * 
 * For the population modification, GreeadyCrossover algorithm is used
 * 
 * @see org.saiko.ai.genetics.tsp.engines.simpleUnisexMutatorHibrid2Opt.SimpleUnisexMutatorHibrid2OptEngine
 * @see org.jgap.impl.GreedyCrossover
 * @see org.saiko.ai.genetics.tsp.TSPEngine
 * @see org.jgap.impl.salesman.Salesman
 * @see examples.salesman.TravellingSalesman
 */
public class JGapGreedyCrossoverEngine implements TSPEngine {

   /** String containing the CVS revision. **/
   public final static String CVS_REVISION = "$Revision: 1.4 $";
 

   /**
    * Population of all chromosomes
    */
   protected Genotype   population =null;
   
   
   /**
    * Reference to cities for converting JGap Gene/Chromosome to City/City[]
    */
   protected City       originalCities[]   =null;

   /**
    * Application configuration parameters.
    * @see TSPConfiguration 
    */
   protected TSPConfiguration configuration;
   
   /**
    * Initializes the engine for population size and set of cities
    * @see TSPEngine
    */
   public void initialize(TSPConfiguration appConfiguration, City[] cities) {
      try {
         this.originalCities=cities;
         this.configuration=appConfiguration;

         //set configuration
         Genotype.setConfiguration(createConfiguration());
         Genotype.getConfiguration()
               .setFitnessFunction(createFitnessFunction());
         Genotype.getConfiguration().setSampleChromosome(
               new Chromosome(cities2gene(cities)));
         Genotype.getConfiguration().setPopulationSize(configuration.getInitialPopulationSize());
         Chromosome chromosomes[]=new Chromosome[Genotype.getConfiguration()
               .getPopulationSize()];
         
         //create randomized chromosomes
         for(int i=0; i < chromosomes.length; i++) {
            City[] c=new City[cities.length];
            for(int k=0; k < c.length; k++) {
               c[k]=cities[k];
            }
            randomize(c);
            chromosomes[i]=new Chromosome(cities2gene(c));
         }
         
         population=new Genotype(Genotype.getConfiguration(), 
               new Population(chromosomes));
      } catch(Throwable e) {
         e.printStackTrace();
         throw new RuntimeException(e);
      }
   }   
   /**
    * @param from  
    * @param to 
    * @return cost of traveling between two cities
    * @see City#cost(City)
    * @see City#distance(City)
    */
   public double cost(Gene from, Gene to) {
      IntegerGene g1=(IntegerGene) from;
      IntegerGene g2=(IntegerGene) to;

      City a = getCityById(g1.intValue());
      City b = getCityById(g2.intValue());
      return a.cost(b);
   }

  

   /**
    * Creates fitness function which evaluates the chromosome.
    * @see org.jgap.impl.salesman.Salesman
    * @see examples.salesman.TravellingSalesman
    * @return FitnessFunction
    */
   public FitnessFunction createFitnessFunction() {
      return new FitnessFunction() {

         private static final long serialVersionUID =-4530787614587664634L;

         @Override
         protected double evaluate(Chromosome a_subject) {
            double s=0;
            Gene[] genes=a_subject.getGenes();
            for(int i=0; i < genes.length - 1; i++) {
               s+=cost(genes[i], genes[i + 1]);
            }
            // add distance of coming back:
            s+=cost(genes[genes.length - 1], genes[0]);

            //better fitness = better chromosome -> invert the cost 
            return Long.MAX_VALUE - s;
         }
      };
   }

  /**
    * @return JGap configuration
    * @see org.jgap.impl.salesman.Salesman
    * @see examples.salesman.TravellingSalesman
    */
   public Configuration createConfiguration() {
      try {
         // This is copied from DefaultConfiguration
         // ----------------------------------------
         Configuration config=new Configuration();
         BestChromosomesSelector bestChromsSelector=new BestChromosomesSelector(
               1.0d);
         bestChromsSelector.setDoubletteChromosomesAllowed(false);
         config.addNaturalSelector(bestChromsSelector, true);
         config.setRandomGenerator(new StockRandomGenerator());
         config.setMinimumPopSizePercent(0);
         config.setEventManager(new EventManager());
         config.setFitnessEvaluator(new DefaultFitnessEvaluator());
         config.setChromosomePool(new ChromosomePool());
         config.setKeepPopulationSizeConstant(false);
         // These are different:
         // -----------------------------------------
         GreedyCrossover o1=new GreedyCrossover();
         o1.setStartOffset(0);
         config.addGeneticOperator(o1);
         // mutation ratio is 1/parameter
         SwappingMutationOperator o2=new SwappingMutationOperator(
               (int) (1 / configuration.getMutationRatio()));
         o2.setStartOffset(0);
         config.addGeneticOperator(o2);
         return config;
      } catch(InvalidConfigurationException e) {
         throw new RuntimeException(e);
      }
   }


   /**
    * Converts array of cities into array of integer genes
    * IntegerGene is JGap gene holding the city id
    * @param cities
    * @return array of IntegerGene
    * @see City#getId()
    */
   protected IntegerGene[] cities2gene(City cities[]) {
      IntegerGene[] gene=new IntegerGene[cities.length];
      for(int i=0; i < cities.length; i++) {
         gene[i]=new IntegerGene();
         gene[i].setAllele(cities[i].getId());
      }
      return gene;
   }

   /**
    * Converts array of integer genes into array of cities
    * IntegerGene is JGap gene holding the city id
    * @param genes
    * @return array of IntegerGene
    * @see City#getId()
    */
   protected City[] genes2cities(Gene genes[]) {
      City[] c=new City[genes.length];
      for(int i=0; i < originalCities.length; i++) {
         c[i]=getCityById((Integer) genes[i].getAllele());
      }
      return c;
   }

   /**
    * @param id
    * @return city from id
    */
   protected City getCityById(int id) {
      return originalCities[id];
   }

   /**
    * @see TSPEngine
    */
   public int getPopulationSize() {
      return population.getPopulation().size();
   }

   /**
    * @see TSPEngine
    */
   public TSPChromosome getBestChromosome() {
      return new TSPChromosome(genes2cities(population.getFittestChromosome()
            .getGenes()));
   }

   /**
    * @see TSPEngine
    */
   public void nextGeneration() {
      population.evolve();
   }

   /**
    * Randomizes the array of cities
    * @param cities 
    */
   void randomize(City[] cities) {
      RandomGenerator rnd=Genotype.getConfiguration().getRandomGenerator();
      SimpleUnisexMutatorEngine.randomize((Random) rnd, cities);
   }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本不卡视频一二三区| 成人精品一区二区三区中文字幕| 日韩国产成人精品| 精品一区二区三区欧美| 成人激情小说乱人伦| 欧美中文字幕一二三区视频| 日韩欧美一区二区在线视频| 在线电影一区二区三区| 欧美经典一区二区| 午夜精品视频在线观看| 国产乱码一区二区三区| 在线免费一区三区| 久久九九全国免费| 五月婷婷激情综合网| 盗摄精品av一区二区三区| 欧美日韩免费观看一区二区三区| 久久伊99综合婷婷久久伊| 亚洲午夜日本在线观看| 秋霞电影一区二区| 在线观看免费亚洲| 国产午夜精品美女毛片视频| 婷婷夜色潮精品综合在线| 99在线精品免费| www一区二区| 亚洲一区二区偷拍精品| 国产精品综合久久| 日韩一区二区三区av| 一区二区三区在线观看动漫| 捆绑紧缚一区二区三区视频| 欧美午夜宅男影院| 最新不卡av在线| 成人免费高清视频在线观看| 欧美日韩在线精品一区二区三区激情| 国产日产欧美一区二区三区| 一个色综合av| 91美女蜜桃在线| 国产精品欧美久久久久一区二区| 午夜国产精品一区| 在线欧美一区二区| 亚洲人成亚洲人成在线观看图片 | 另类小说图片综合网| 555www色欧美视频| 卡一卡二国产精品| 国产午夜精品久久久久久免费视 | 精品久久久久香蕉网| 久久99久国产精品黄毛片色诱| 日韩视频一区二区| 国产精品123区| 日韩久久一区二区| 色94色欧美sute亚洲线路二| 亚洲国产精品一区二区www在线| 666欧美在线视频| 国产精品一卡二卡| 亚洲人成网站精品片在线观看 | 日韩一二三区不卡| 国产成人免费视频网站| 一区二区中文字幕在线| 欧美撒尿777hd撒尿| 狠狠色综合色综合网络| 国产精品伦一区二区三级视频| 色欧美乱欧美15图片| 日韩电影在线观看电影| 国产日韩av一区| 欧美视频一区在线| 激情图区综合网| 一区二区三区在线看| 欧美成va人片在线观看| 99精品视频一区| 免费人成在线不卡| 国产精品国产三级国产aⅴ原创| 欧美日韩久久一区| 高清av一区二区| 日韩精品一级中文字幕精品视频免费观看 | 欧美日韩一区二区三区高清| 久热成人在线视频| 亚洲激情第一区| 久久众筹精品私拍模特| 欧美丝袜自拍制服另类| 国产成人午夜精品影院观看视频| 亚洲一区av在线| 国产精品久久久久影院亚瑟| 欧美一区在线视频| 欧美亚洲一区二区在线观看| 国产成人综合精品三级| 午夜精品久久久久久久蜜桃app| 欧美激情在线看| 欧美zozo另类异族| 欧美猛男超大videosgay| av资源网一区| 国产乱人伦精品一区二区在线观看 | 久久99久久99小草精品免视看| 一区二区三区在线播| 国产精品免费看片| 久久精品亚洲一区二区三区浴池| 欧美日韩一区二区三区视频| 色呦呦国产精品| a4yy欧美一区二区三区| 久久国产夜色精品鲁鲁99| 午夜激情久久久| 亚洲一二三区不卡| 一区二区三区在线观看网站| 最好看的中文字幕久久| 中文字幕中文字幕在线一区| 国产无遮挡一区二区三区毛片日本| 欧美一级日韩一级| 欧美一级高清大全免费观看| 欧美欧美欧美欧美| 欧美日韩一本到| 欧美少妇bbb| 欧美三级日韩在线| 欧美日韩国产高清一区二区| 欧美性生活大片视频| 日本久久电影网| 欧美亚一区二区| 欧美亚洲综合一区| 欧美性极品少妇| 欧美日韩电影在线播放| 欧美在线观看18| 欧美日韩久久一区二区| 欧洲精品一区二区三区在线观看| 日本高清成人免费播放| 色成人在线视频| 欧美精品三级在线观看| 欧美一区二区三区白人| 日韩精品专区在线| 久久午夜色播影院免费高清| 国产日韩视频一区二区三区| 亚洲国产精品激情在线观看| 中文字幕视频一区| 亚洲精品成人悠悠色影视| 亚洲国产va精品久久久不卡综合| 性感美女久久精品| 精品一区二区三区在线播放 | 日韩av一二三| 久久精品久久综合| 粉嫩欧美一区二区三区高清影视| 91年精品国产| 91麻豆精品国产91久久久| 精品91自产拍在线观看一区| 亚洲国产精品国自产拍av| 亚洲黄一区二区三区| 免费在线看成人av| 成人久久久精品乱码一区二区三区| 91蜜桃网址入口| 正在播放亚洲一区| 国产精品丝袜黑色高跟| 夜夜嗨av一区二区三区网页| 麻豆精品在线看| 99久久精品国产观看| 欧美精品亚洲二区| 国产精品水嫩水嫩| 日韩av中文字幕一区二区三区| 国产91精品入口| 欧美日韩国产精选| 国产精品天美传媒沈樵| 五月婷婷色综合| www.亚洲色图| 精品久久久久香蕉网| 亚洲男同性恋视频| 激情综合五月婷婷| 欧美色图片你懂的| 久久精品日韩一区二区三区| 亚洲午夜三级在线| www.成人在线| 精品播放一区二区| 日韩精品成人一区二区三区| 成人av网址在线观看| 日韩三级视频在线看| 亚洲乱码精品一二三四区日韩在线| 精品一区二区三区不卡| 欧美日韩国产bt| 亚洲日本一区二区| 成人午夜av电影| 久久午夜国产精品| 麻豆国产欧美一区二区三区| 91激情五月电影| 日本一区二区三区在线不卡 | 精品电影一区二区三区| 婷婷国产在线综合| 欧美亚洲一区二区三区四区| 国产精品久久久久影院老司| 国精产品一区一区三区mba桃花 | 欧美国产激情二区三区| 久久国产精品第一页| 欧美三级电影一区| 亚洲一区二区三区四区在线免费观看| 成人综合婷婷国产精品久久免费| 日韩免费看的电影| 蜜桃久久av一区| 欧美一卡在线观看| 日本成人超碰在线观看| 欧美日韩精品福利| 亚洲成人三级小说| 欧美日韩你懂得| 日韩不卡一二三区| 日韩亚洲欧美在线| 狠狠色丁香久久婷婷综合丁香| 日韩精品一区二区三区蜜臀| 免费成人美女在线观看| 日韩你懂的在线播放|