Package de.mh4j.solver.genetic

Examples of de.mh4j.solver.genetic.Genome


    @Test
    public void testReportDeadGenome_WhenReportedAndGenomeIsNotAChild_UpdateFitnessSum() throws Exception {
        long oldFitnessSum = genePool.getFitnessSum();

        // kill an older genome from a past generation
        Genome olderGenome = mock(Genome.class);
        int fitnessOfOlderGenome = 10;
        when(olderGenome.getFitness()).thenReturn(fitnessOfOlderGenome);
        when(olderGenome.getBirthGeneration()).thenReturn(genePool.getCurrentGeneration() - 1);

        genePool.reportDeadGenome(olderGenome);

        assert genePool.getFitnessSum() == oldFitnessSum - fitnessOfOlderGenome : "If a genome has been reported dead the overall fitness sum should decrease by its fitness";
        assert genePool.getNumberOfDeadChildren() == 0;

        // now kill the genome from current generation (child)
        oldFitnessSum = genePool.getFitnessSum();

        Genome genomeFromCurrentGeneration = mock(Genome.class);
        int fitnessOfGenomeFromCurrentGeneration = 8;
        when(genomeFromCurrentGeneration.getFitness()).thenReturn(fitnessOfGenomeFromCurrentGeneration);
        when(genomeFromCurrentGeneration.getBirthGeneration()).thenReturn(genePool.getCurrentGeneration());

        genePool.reportDeadGenome(genomeFromCurrentGeneration);

        assert genePool.getFitnessSum() == oldFitnessSum - fitnessOfGenomeFromCurrentGeneration : "If a genome has been reported dead the overall fitness sum should decrease by its fitness";
        assert genePool.getNumberOfDeadChildren() == 1;
View Full Code Here


    @Test
    public void testDescendingIterator_WhenDescendingIterator_ThenSortedDescending() throws Exception {
        long lastFitness = Long.MAX_VALUE;
        Iterator<Genome> iterator = genePool.descendingIterator();
        while (iterator.hasNext()) {
            Genome genome = iterator.next();
            assert genome.getFitness() <= lastFitness;
            lastFitness = genome.getFitness();
        }
    }
View Full Code Here

        assert genePool.getFittestGenome() == genome3;
    }

    @Test
    public void testGetFittestGenome_WhenBetterGenomeIsAdded_UpdateBestGenome() throws Exception {
        Genome bestGenome = mock(Genome.class);
        when(bestGenome.getFitness()).thenReturn(Integer.MAX_VALUE);
        makeGenomeMockComparable(bestGenome, genome1);
        makeGenomeMockComparable(bestGenome, genome2);
        makeGenomeMockComparable(bestGenome, genome3);

        genePool.addGenome(bestGenome);
View Full Code Here

        assert cut.hasNext() == false;
    }

    @Test
    public void testNext() {
        Genome next = mock(Genome.class);
        when(decoree.next()).thenReturn(next);
        assert cut.next() == next;
    }
View Full Code Here

        assert cut.next() == next;
    }

    @Test
    public void testRemove() {
        Genome dead = mock(Genome.class);
        when(decoree.next()).thenReturn(dead);
        InOrder inOrder = inOrder(decoree, genePool);

        cut.next();
        cut.remove();
View Full Code Here

TOP

Related Classes of de.mh4j.solver.genetic.Genome

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.