@Test public void testMutation() { Portfolio portfolio = new Portfolio(3); portfolio.getPortfolio().set(0, 0.25); portfolio.getPortfolio().set(1, 0.5); portfolio.getPortfolio().set(2, 0.25); GeneticAlgUtils.mutate(portfolio); System.out.println(portfolio); }
@Test public void testCrossoverWithGenesSwapping() { GeneticAlgorithmImpl gen = new GeneticAlgorithmImpl(5, 5, 0.2, 0.1, 0.3, dataSource); Portfolio parentA = gen.getPopulation().get(0); Portfolio parentB = gen.getPopulation().get(1); System.out.println("parents:"); System.out.println(parentA); System.out.println(parentB); List<Portfolio> children = GeneticAlgUtils.crossoverWithGenomeSwapping(parentA, parentB); System.out.println("Children:"); for (Portfolio portfolio : children) { System.out.println(portfolio); } }