當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。