use of org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition in project evosuite by EvoSuite.
the class PropertiesTestGAFactory method getSearchAlgorithm.
@Override
public GeneticAlgorithm<TestChromosome> getSearchAlgorithm() {
ChromosomeFactory<TestChromosome> factory = getChromosomeFactory();
// FIXXME
GeneticAlgorithm<TestChromosome> ga = getGeneticAlgorithm(factory);
if (Properties.NEW_STATISTICS)
ga.addListener(new org.evosuite.statistics.StatisticsListener());
// How to select candidates for reproduction
SelectionFunction<TestChromosome> selection_function = getSelectionFunction();
selection_function.setMaximize(false);
ga.setSelectionFunction(selection_function);
// When to stop the search
StoppingCondition stopping_condition = getStoppingCondition();
ga.setStoppingCondition(stopping_condition);
// ga.addListener(stopping_condition);
if (Properties.STOP_ZERO) {
ga.addStoppingCondition(new ZeroFitnessStoppingCondition());
}
if (!(stopping_condition instanceof MaxTimeStoppingCondition)) {
ga.addStoppingCondition(new GlobalTimeStoppingCondition());
}
if (ArrayUtil.contains(Properties.CRITERION, Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Criterion.STRONGMUTATION)) {
ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
}
ga.resetStoppingConditions();
ga.setPopulationLimit(getPopulationLimit());
// How to cross over
CrossOverFunction crossover_function = getCrossoverFunction();
ga.setCrossOverFunction(crossover_function);
if (Properties.CHECK_BEST_LENGTH) {
org.evosuite.testcase.RelativeTestLengthBloatControl bloat_control = new org.evosuite.testcase.RelativeTestLengthBloatControl();
ga.addBloatControl(bloat_control);
ga.addListener(bloat_control);
}
TestCaseSecondaryObjective.setSecondaryObjectives();
if (Properties.DYNAMIC_LIMIT) {
// max_s = GAProperties.generations * getBranches().size();
// TODO: might want to make this dependent on the selected coverage
// criterion
// TODO also, question: is branchMap.size() really intended here?
// I think BranchPool.getBranchCount() was intended
Properties.SEARCH_BUDGET = Properties.SEARCH_BUDGET * (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getNumBranchlessMethods(Properties.TARGET_CLASS) + BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchCountForClass(Properties.TARGET_CLASS) * 2);
stopping_condition.setLimit(Properties.SEARCH_BUDGET);
logger.info("Setting dynamic length limit to " + Properties.SEARCH_BUDGET);
}
if (Properties.RECYCLE_CHROMOSOMES) {
if (Properties.STRATEGY == Strategy.ONEBRANCH)
ga.addListener(TestCaseRecycler.getInstance());
}
// ga.addListener(new ResourceController<TestChromosome>());
return ga;
}
use of org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition in project evosuite by EvoSuite.
the class PropertiesNoveltySearchFactory method getSearchAlgorithm.
@Override
public // public GeneticAlgorithm<TestChromosome> getSearchAlgorithm() {
NoveltySearch<TestChromosome> getSearchAlgorithm() {
ChromosomeFactory<TestChromosome> factory = getChromosomeFactory();
NoveltySearch<TestChromosome> ga = new NoveltySearch<>(factory);
if (Properties.NEW_STATISTICS)
ga.addListener(new StatisticsListener());
// How to select candidates for reproduction
SelectionFunction<TestChromosome> selectionFunction = getSelectionFunction();
selectionFunction.setMaximize(false);
ga.setSelectionFunction(selectionFunction);
// When to stop the search
StoppingCondition stopping_condition = getStoppingCondition();
ga.setStoppingCondition(stopping_condition);
// ga.addListener(stopping_condition);
if (Properties.STOP_ZERO) {
ga.addStoppingCondition(new ZeroFitnessStoppingCondition());
}
if (!(stopping_condition instanceof MaxTimeStoppingCondition)) {
ga.addStoppingCondition(new GlobalTimeStoppingCondition());
}
if (ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.STRONGMUTATION)) {
if (Properties.STRATEGY == Properties.Strategy.ONEBRANCH)
ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
else
ga.addListener(new MutationTestPool());
// } else if (Properties.CRITERION == Criterion.DEFUSE) {
// if (Properties.STRATEGY == Strategy.EVOSUITE)
// ga.addListener(new DefUseTestPool());
}
ga.resetStoppingConditions();
ga.setPopulationLimit(getPopulationLimit());
// How to cross over
CrossOverFunction crossover_function = getCrossoverFunction();
ga.setCrossOverFunction(crossover_function);
if (Properties.CHECK_BEST_LENGTH) {
RelativeSuiteLengthBloatControl bloat_control = new org.evosuite.testsuite.RelativeSuiteLengthBloatControl();
ga.addBloatControl(bloat_control);
ga.addListener(bloat_control);
}
// ga.addBloatControl(new MaxLengthBloatControl());
TestCaseSecondaryObjective.setSecondaryObjectives();
if (Properties.DYNAMIC_LIMIT) {
// max_s = GAProperties.generations * getBranches().size();
// TODO: might want to make this dependent on the selected coverage
// criterion
// TODO also, question: is branchMap.size() really intended here?
// I think BranchPool.getBranchCount() was intended
Properties.SEARCH_BUDGET = Properties.SEARCH_BUDGET * (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getNumBranchlessMethods(Properties.TARGET_CLASS) + BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchCountForClass(Properties.TARGET_CLASS) * 2);
stopping_condition.setLimit(Properties.SEARCH_BUDGET);
logger.info("Setting dynamic length limit to " + Properties.SEARCH_BUDGET);
}
if (Properties.LOCAL_SEARCH_RESTORE_COVERAGE) {
org.evosuite.ga.metaheuristics.SearchListener map = BranchCoverageMap.getInstance();
ga.addListener(map);
}
if (Properties.SHUTDOWN_HOOK) {
// ShutdownTestWriter writer = new
// ShutdownTestWriter(Thread.currentThread());
ShutdownTestWriter writer = new ShutdownTestWriter();
ga.addStoppingCondition(writer);
RMIStoppingCondition rmi = RMIStoppingCondition.getInstance();
ga.addStoppingCondition(rmi);
if (Properties.STOPPING_PORT != -1) {
SocketStoppingCondition ss = new SocketStoppingCondition();
ss.accept();
ga.addStoppingCondition(ss);
}
// Runtime.getRuntime().addShutdownHook(writer);
Signal.handle(new Signal("INT"), writer);
}
ga.addListener(new ResourceController());
return ga;
}
use of org.evosuite.ga.stoppingconditions.GlobalTimeStoppingCondition in project evosuite by EvoSuite.
the class PropertiesSuiteGAFactory method getSearchAlgorithm.
@Override
public GeneticAlgorithm<TestSuiteChromosome> getSearchAlgorithm() {
ChromosomeFactory<TestSuiteChromosome> factory = getChromosomeFactory();
// FIXXME
GeneticAlgorithm<TestSuiteChromosome> ga = getGeneticAlgorithm(factory);
if (Properties.NEW_STATISTICS)
ga.addListener(new StatisticsListener());
// How to select candidates for reproduction
SelectionFunction<TestSuiteChromosome> selectionFunction = getSelectionFunction();
selectionFunction.setMaximize(false);
ga.setSelectionFunction(selectionFunction);
// When to stop the search
StoppingCondition stopping_condition = getStoppingCondition();
ga.setStoppingCondition(stopping_condition);
// ga.addListener(stopping_condition);
if (Properties.STOP_ZERO) {
ga.addStoppingCondition(new ZeroFitnessStoppingCondition());
}
if (!(stopping_condition instanceof MaxTimeStoppingCondition)) {
ga.addStoppingCondition(new GlobalTimeStoppingCondition());
}
if (ArrayUtil.contains(Properties.CRITERION, Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Criterion.STRONGMUTATION)) {
if (Properties.STRATEGY == Strategy.ONEBRANCH)
ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
else
ga.addListener(new MutationTestPool());
// } else if (Properties.CRITERION == Criterion.DEFUSE) {
// if (Properties.STRATEGY == Strategy.EVOSUITE)
// ga.addListener(new DefUseTestPool());
}
ga.resetStoppingConditions();
ga.setPopulationLimit(getPopulationLimit());
// How to cross over
CrossOverFunction crossover_function = getCrossoverFunction();
ga.setCrossOverFunction(crossover_function);
if (Properties.CHECK_BEST_LENGTH) {
RelativeSuiteLengthBloatControl bloat_control = new org.evosuite.testsuite.RelativeSuiteLengthBloatControl();
ga.addBloatControl(bloat_control);
ga.addListener(bloat_control);
}
// ga.addBloatControl(new MaxLengthBloatControl());
TestSuiteSecondaryObjective.setSecondaryObjectives();
if (Properties.DYNAMIC_LIMIT) {
// max_s = GAProperties.generations * getBranches().size();
// TODO: might want to make this dependent on the selected coverage
// criterion
// TODO also, question: is branchMap.size() really intended here?
// I think BranchPool.getBranchCount() was intended
Properties.SEARCH_BUDGET = Properties.SEARCH_BUDGET * (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getNumBranchlessMethods(Properties.TARGET_CLASS) + BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchCountForClass(Properties.TARGET_CLASS) * 2);
stopping_condition.setLimit(Properties.SEARCH_BUDGET);
logger.info("Setting dynamic length limit to " + Properties.SEARCH_BUDGET);
}
if (Properties.LOCAL_SEARCH_RESTORE_COVERAGE) {
org.evosuite.ga.metaheuristics.SearchListener map = BranchCoverageMap.getInstance();
ga.addListener(map);
}
if (Properties.SHUTDOWN_HOOK) {
// ShutdownTestWriter writer = new
// ShutdownTestWriter(Thread.currentThread());
ShutdownTestWriter writer = new ShutdownTestWriter();
ga.addStoppingCondition(writer);
RMIStoppingCondition rmi = RMIStoppingCondition.getInstance();
ga.addStoppingCondition(rmi);
if (Properties.STOPPING_PORT != -1) {
SocketStoppingCondition ss = new SocketStoppingCondition();
ss.accept();
ga.addStoppingCondition(ss);
}
// Runtime.getRuntime().addShutdownHook(writer);
Signal.handle(new Signal("INT"), writer);
}
ga.addListener(new ResourceController());
return ga;
}
Aggregations