当前位置: 首页>>代码示例>>Java>>正文


Java UniformCrossover类代码示例

本文整理汇总了Java中org.apache.commons.math3.genetics.UniformCrossover的典型用法代码示例。如果您正苦于以下问题:Java UniformCrossover类的具体用法?Java UniformCrossover怎么用?Java UniformCrossover使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UniformCrossover类属于org.apache.commons.math3.genetics包,在下文中一共展示了UniformCrossover类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ga

import org.apache.commons.math3.genetics.UniformCrossover; //导入依赖的package包/类
/**
 * Genetic algorithm global optimization.
 * 
 * @param work
 *            Work unit to be optimized.
 * @return Solution found.
 */
private static List<Task> ga(WorkUnit work) {
	/*
	 * Generate initial population.
	 */
	List<Chromosome> list = new LinkedList<Chromosome>();
	for (int i = 0; i < populationSize; i++) {
		list.add(new TaskListChromosome(work.generateRandomValidSolution(), work));
	}
	Population initial = new ElitisticListPopulation(list, 2 * list.size(), elitismRate);

	/*
	 * Initialize genetic algorithm.
	 */
	GeneticAlgorithm algorithm = new GeneticAlgorithm(new UniformCrossover<TaskListChromosome>(0.5), crossoverRate,
			new RandomTaskMutation(lowMutationBoundary, highMutationBoundary), mutationRate,
			new TournamentSelection(tournamentArity));

	/*
	 * Run optimization.
	 */
	Population optimized = algorithm.evolve(initial, new FixedElapsedTime(optimizationTimeout));

	/*
	 * Obtain result.
	 */
	return ((TaskListChromosome) optimized.getFittestChromosome()).getSolution();
}
 
开发者ID:TodorBalabanov,项目名称:Genetic-Algorithm-for-Machinery-Usage-Scheduling,代码行数:35,代码来源:Main.java

示例2: Display

import org.apache.commons.math3.genetics.UniformCrossover; //导入依赖的package包/类
public Display() throws Exception {
    setTitle("Commons-Math: Image Evolution Example");
    setSize(600, 400);
    
    setLayout(new FlowLayout());

    Box bar = Box.createHorizontalBox();

    ref = ImageIO.read(new File("resources/monalisa.png"));
    //ref = ImageIO.read(new File("resources/feather-small.gif"));

    referenceImage = resizeImage(ref, 50, 50, BufferedImage.TYPE_INT_ARGB);
    testImage = new BufferedImage(referenceImage.getWidth(), referenceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);

    JLabel picLabel = new JLabel(new ImageIcon(ref));
    bar.add(picLabel);

    painter = new ImagePainter(ref.getWidth(), ref.getHeight());
    bar.add(painter);

    // set the images used for calculating the fitness function:
    //   refImage  - the reference image
    //   testImage - the test image to draw the current chromosome
    PolygonChromosome.setRefImage(referenceImage);
    PolygonChromosome.setTestImage(testImage);

    add(bar);

    JButton startButton = new JButton("Start");
    startButton.setActionCommand("start");
    add(startButton);

    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (isAlive()) {
                stopRequest();
            } else {
                startEvolution();
            }
        }
    });

    // initialize a new genetic algorithm
    ga = new GeneticAlgorithm(new UniformCrossover<Polygon>(0.5), 1.0,
                              new RandomPolygonMutation(MUTATION_RATE, MUTATION_CHANGE), 1.0,
                              new TournamentSelection(TOURNAMENT_ARITY));

    // initial population
    currentPopulation = getInitialPopulation();
    bestFit = currentPopulation.getFittestChromosome();
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:52,代码来源:ImageEvolutionExample.java


注:本文中的org.apache.commons.math3.genetics.UniformCrossover类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。