@Test public void testFullFillAllGoals() { ChromosomeFactory factory = Mockito.mock(ChromosomeFactory.class); TestChromosome ch1 = Mockito.mock(TestChromosome.class, Mockito.RETURNS_DEEP_STUBS); TestChromosome ch2 = Mockito.mock(TestChromosome.class); TestCase testCase = Mockito.mock(TestCase.class); Mockito.doNothing().when(testCase).addCoveredGoal(Mockito.any()); Iterator testIt = Mockito.mock(Iterator.class); Mockito.when(testIt.hasNext()).thenReturn(false); Mockito.when(testCase.iterator()).thenReturn(testIt); Mockito.when(ch1.getTestCase()).thenReturn(testCase); Mockito.when(ch1.size()).thenReturn(10); Mockito.when(ch1.clone()).thenReturn(ch1); Mockito.doNothing().when(testCase).addCoveredGoal(Mockito.any()); Mockito.when(ch2.getTestCase()).thenReturn(testCase); Mockito.when(ch2.size()).thenReturn(9); Mockito.when(ch2.clone()).thenReturn(ch2); Mockito.when(factory.getChromosome()).thenReturn(ch1).thenReturn(ch2); List<TestFitnessFunction> ffList = new ArrayList<>(); TestFitnessFunction ff1 = Mockito.mock(TestFitnessFunction.class); Mockito.doReturn(0.0).when(ff1).getFitness(Mockito.any()); TestFitnessFunction ff2 = Mockito.mock(TestFitnessFunction.class); Mockito.doReturn(0.0).when(ff1).getFitness(Mockito.any()); ffList.add(ff1); ffList.add(ff2); FitnessFunctions fitnessFunctions = Mockito.mock(FitnessFunctions.class); Mockito.doReturn(ffList).when(fitnessFunctions).getFitnessFunctionList(); CrossOverFunction crossOver = Mockito.mock(CrossOverFunction.class); Mutation mutation = Mockito.mock(Mutation.class); AbstractMOSA MOSA = new MOSA(factory,crossOver,mutation,fitnessFunctions); MOSA.addFitnessFunctions(ffList); MOSA.generateSolution(); }
@Override public void generateSolution() { LOG.info("Generating solution in MOSA"); this.startTime = System.nanoTime(); for (FitnessFunction<T> goal : fitnessFunctions) { uncoveredGoals.add(goal); } fitnessFunctions.clear(); fitnessFunctions.addAll(uncoveredGoals); if (this.population.isEmpty()) { this.initializePopulation(); } this.rankingFunction.computeRankingAssignment(this.population, this.uncoveredGoals); for (int i = 0; i < this.rankingFunction.getNumberOfSubfronts(); i++) { this.distance.fastEpsilonDominanceAssignment(this.rankingFunction.getSubfront(i), this.uncoveredGoals); } while (!this.isFinished() && this.getNumberOfCoveredGoals()<this.fitnessFunctions.size() && ! fitnessCollector.isCriticalGoalsAreCovered(this.uncoveredGoals)) { LOG.info("Number of covered goals are {}/{}",this.getNumberOfCoveredGoals(),this.fitnessFunctions.size()); this.evolve(); LOG.info("generation #{} is created.",this.currentIteration); this.notifyIteration(); } if(this.isFinished()){ for(StoppingCondition stoppingCondition : this.stoppingConditions){ if(stoppingCondition.isFinished()){ LOG.info("Stopping reason: {}", stoppingCondition.toString()); LOG.info("Number of covered goals are: {}", this.coveredGoals.size()); } } } }
MOSA extends AbstractMOSA<T> { @Override public void generateSolution() { LOG.info("Generating solution in MOSA"); this.startTime = System.nanoTime(); for (FitnessFunction<T> goal : fitnessFunctions) { uncoveredGoals.add(goal); } fitnessFunctions.clear(); fitnessFunctions.addAll(uncoveredGoals); if (this.population.isEmpty()) { this.initializePopulation(); } this.rankingFunction.computeRankingAssignment(this.population, this.uncoveredGoals); for (int i = 0; i < this.rankingFunction.getNumberOfSubfronts(); i++) { this.distance.fastEpsilonDominanceAssignment(this.rankingFunction.getSubfront(i), this.uncoveredGoals); } while (!this.isFinished() && this.getNumberOfCoveredGoals()<this.fitnessFunctions.size() && ! fitnessCollector.isCriticalGoalsAreCovered(this.uncoveredGoals)) { LOG.info("Number of covered goals are {}/{}",this.getNumberOfCoveredGoals(),this.fitnessFunctions.size()); this.evolve(); LOG.info("generation #{} is created.",this.currentIteration); this.notifyIteration(); } if(this.isFinished()){ for(StoppingCondition stoppingCondition : this.stoppingConditions){ if(stoppingCondition.isFinished()){ LOG.info("Stopping reason: {}", stoppingCondition.toString()); LOG.info("Number of covered goals are: {}", this.coveredGoals.size()); } } } } }
MOSA extends AbstractMOSA<T> { @Override public void generateSolution() { LOG.info("Generating solution in MOSA"); this.startTime = System.nanoTime(); for (FitnessFunction<T> goal : fitnessFunctions) { uncoveredGoals.add(goal); } fitnessFunctions.clear(); fitnessFunctions.addAll(uncoveredGoals); if (this.population.isEmpty()) { this.initializePopulation(); } this.rankingFunction.computeRankingAssignment(this.population, this.uncoveredGoals); for (int i = 0; i < this.rankingFunction.getNumberOfSubfronts(); i++) { this.distance.fastEpsilonDominanceAssignment(this.rankingFunction.getSubfront(i), this.uncoveredGoals); } while (!this.isFinished() && this.getNumberOfCoveredGoals()<this.fitnessFunctions.size() && ! fitnessCollector.isCriticalGoalsAreCovered(this.uncoveredGoals)) { LOG.info("Number of covered goals are {}/{}",this.getNumberOfCoveredGoals(),this.fitnessFunctions.size()); this.evolve(); LOG.info("generation #{} is created.",this.currentIteration); this.notifyIteration(); } if(this.isFinished()){ for(StoppingCondition stoppingCondition : this.stoppingConditions){ if(stoppingCondition.isFinished()){ LOG.info("Stopping reason: {}", stoppingCondition.toString()); LOG.info("Number of covered goals are: {}", this.coveredGoals.size()); } } } } MOSA(ChromosomeFactory factory, CrossOverFunction crossOverOperator, Mutation mutationOperator, FitnessFunctions fitnessCollector); }
MOSA extends AbstractMOSA<T> { @Override public void generateSolution() { LOG.info("Generating solution in MOSA"); this.startTime = System.nanoTime(); for (FitnessFunction<T> goal : fitnessFunctions) { uncoveredGoals.add(goal); } fitnessFunctions.clear(); fitnessFunctions.addAll(uncoveredGoals); if (this.population.isEmpty()) { this.initializePopulation(); } this.rankingFunction.computeRankingAssignment(this.population, this.uncoveredGoals); for (int i = 0; i < this.rankingFunction.getNumberOfSubfronts(); i++) { this.distance.fastEpsilonDominanceAssignment(this.rankingFunction.getSubfront(i), this.uncoveredGoals); } while (!this.isFinished() && this.getNumberOfCoveredGoals()<this.fitnessFunctions.size() && ! fitnessCollector.isCriticalGoalsAreCovered(this.uncoveredGoals)) { LOG.info("Number of covered goals are {}/{}",this.getNumberOfCoveredGoals(),this.fitnessFunctions.size()); this.evolve(); LOG.info("generation #{} is created.",this.currentIteration); this.notifyIteration(); } if(this.isFinished()){ for(StoppingCondition stoppingCondition : this.stoppingConditions){ if(stoppingCondition.isFinished()){ LOG.info("Stopping reason: {}", stoppingCondition.toString()); LOG.info("Number of covered goals are: {}", this.coveredGoals.size()); } } } } MOSA(ChromosomeFactory factory, CrossOverFunction crossOverOperator, Mutation mutationOperator, FitnessFunctions fitnessCollector); @Override void generateSolution(); @Override @SuppressWarnings("unchecked") T getBestIndividual(); @SuppressWarnings("unchecked") @Override List<T> getBestIndividuals(); }
MOSA extends AbstractMOSA<T> { @Override public void generateSolution() { LOG.info("Generating solution in MOSA"); this.startTime = System.nanoTime(); for (FitnessFunction<T> goal : fitnessFunctions) { uncoveredGoals.add(goal); } fitnessFunctions.clear(); fitnessFunctions.addAll(uncoveredGoals); if (this.population.isEmpty()) { this.initializePopulation(); } this.rankingFunction.computeRankingAssignment(this.population, this.uncoveredGoals); for (int i = 0; i < this.rankingFunction.getNumberOfSubfronts(); i++) { this.distance.fastEpsilonDominanceAssignment(this.rankingFunction.getSubfront(i), this.uncoveredGoals); } while (!this.isFinished() && this.getNumberOfCoveredGoals()<this.fitnessFunctions.size() && ! fitnessCollector.isCriticalGoalsAreCovered(this.uncoveredGoals)) { LOG.info("Number of covered goals are {}/{}",this.getNumberOfCoveredGoals(),this.fitnessFunctions.size()); this.evolve(); LOG.info("generation #{} is created.",this.currentIteration); this.notifyIteration(); } if(this.isFinished()){ for(StoppingCondition stoppingCondition : this.stoppingConditions){ if(stoppingCondition.isFinished()){ LOG.info("Stopping reason: {}", stoppingCondition.toString()); LOG.info("Number of covered goals are: {}", this.coveredGoals.size()); } } } } MOSA(ChromosomeFactory factory, CrossOverFunction crossOverOperator, Mutation mutationOperator, FitnessFunctions fitnessCollector); @Override void generateSolution(); @Override @SuppressWarnings("unchecked") T getBestIndividual(); @SuppressWarnings("unchecked") @Override List<T> getBestIndividuals();  }