use of org.evosuite.ga.Chromosome in project evosuite by EvoSuite.
the class SinglePointRelativeCrossOver method crossOver.
/**
* {@inheritDoc}
*
* The splitting point is not an absolute value but a relative value (eg, at
* position 70% of n). For example, if n1=10 and n2=20 and splitting point
* is 70%, we would have position 7 in the first and 14 in the second.
* Therefore, the offspring d have n<=max(n1,n2)
*/
@Override
public void crossOver(Chromosome parent1, Chromosome parent2) throws ConstructionFailedException {
if (parent1.size() < 2 || parent2.size() < 2) {
return;
}
Chromosome t1 = parent1.clone();
Chromosome t2 = parent2.clone();
// Choose a position in the middle
float splitPoint = Randomness.nextFloat();
int pos1 = ((int) Math.floor((t1.size() - 1) * splitPoint)) + 1;
int pos2 = ((int) Math.floor((t2.size() - 1) * splitPoint)) + 1;
parent1.crossOver(t2, pos1, pos2);
parent2.crossOver(t1, pos2, pos1);
}
use of org.evosuite.ga.Chromosome in project evosuite by EvoSuite.
the class GeneticAlgorithm method applyLocalSearch.
/**
* Apply local search, starting from the best individual and continue
* applying it to all individuals until the local search budget is used up.
*
* The population list is re-ordered if needed.
*/
protected void applyLocalSearch() {
if (!shouldApplyLocalSearch())
return;
logger.debug("Applying local search");
LocalSearchBudget.getInstance().localSearchStarted();
boolean improvement = false;
for (Chromosome individual : population) {
if (isFinished())
break;
if (LocalSearchBudget.getInstance().isFinished()) {
logger.debug("Local search budget used up, exiting local search");
break;
}
if (individual.localSearch(localObjective)) {
improvement = true;
}
}
if (improvement) {
DSEStats.getInstance().reportNewIncrease();
updateProbability(true);
logger.debug("Increasing probability of applying LS to " + localSearchProbability);
} else {
DSEStats.getInstance().reportNewDecrease();
updateProbability(false);
logger.debug("Decreasing probability of applying LS to " + localSearchProbability);
}
if (improvement) {
// list not sorted any more.
if (!populationIsSorted()) {
this.sortPopulation();
}
}
}
use of org.evosuite.ga.Chromosome in project evosuite by EvoSuite.
the class GeneticAlgorithm method toString.
/**
* @return
*/
@Override
public String toString() {
StringBuilder str = new StringBuilder();
int i = 0;
for (Chromosome c : population) {
str.append("\n - test " + i);
for (FitnessFunction<T> ff : this.fitnessFunctions) {
DecimalFormat df = new DecimalFormat("#.#####");
str.append(", " + ff.getClass().getSimpleName().replace("CoverageSuiteFitness", "") + " " + df.format(c.getFitness(ff)));
}
i++;
}
return str.toString();
}
use of org.evosuite.ga.Chromosome in project evosuite by EvoSuite.
the class SinglePointFixedCrossOver method crossOver.
/**
* {@inheritDoc}
*
* The splitting point for to individuals p1, p2 is selected within
* min(length(p1),length(p2))
*/
@Override
public void crossOver(Chromosome parent1, Chromosome parent2) throws ConstructionFailedException {
if (parent1.size() < 2 || parent2.size() < 2) {
return;
}
int point = Randomness.nextInt(Math.min(parent1.size(), parent2.size()) - 1) + 1;
Chromosome t1 = parent1.clone();
Chromosome t2 = parent2.clone();
parent1.crossOver(t2, point, point);
parent2.crossOver(t1, point, point);
}
use of org.evosuite.ga.Chromosome in project evosuite by EvoSuite.
the class TestSuiteLocalSearch method applyAVM.
/**
* Applies AVM on the test case in the suite
*
* @param suite
* @param testIndex
* @param test
* @param localSearchObjective
* @return
*/
private boolean applyAVM(TestSuiteChromosome suite, int testIndex, TestChromosome test, LocalSearchObjective<TestSuiteChromosome> objective) {
logger.debug("Local search on test " + testIndex + ", current fitness: " + suite.getFitness());
final List<FitnessFunction<? extends Chromosome>> fitnessFunctions = objective.getFitnessFunctions();
TestSuiteLocalSearchObjective testCaseLocalSearchObjective = TestSuiteLocalSearchObjective.buildNewTestSuiteLocalSearchObjective(fitnessFunctions, suite, testIndex);
AVMTestCaseLocalSearch testCaselocalSearch = new AVMTestCaseLocalSearch();
boolean improved = testCaselocalSearch.doSearch(test, testCaseLocalSearchObjective);
return improved;
}
Aggregations