use of org.kanonizo.framework.objects.TestSuite in project kanonizo by kanonizo.
the class GeneticAlgorithm method evolve.
protected void evolve() {
long startTime = System.currentTimeMillis();
List<TestSuite> newIndividuals = new ArrayList<>();
// apply elitism
newIndividuals.addAll(elitism());
while (!isNewGenerationFull(newIndividuals)) {
TestSuite parent1 = selection.select(population);
TestSuite parent2 = selection.select(population);
TestSuite offspring1 = parent1.clone();
TestSuite offspring2 = parent2.clone();
if (RandomInstance.nextDouble() <= CROSSOVER_CHANCE) {
crossover.crossover(offspring1, offspring2);
}
if (RandomInstance.nextDouble() <= MUTATION_CHANCE) {
offspring1 = offspring1.mutate();
offspring2 = offspring2.mutate();
}
evolutionComplete(offspring1, offspring2);
newIndividuals.addAll(getNFittest(2, parent1, parent2, offspring1, offspring2));
}
population = newIndividuals;
if (Properties.PROFILE) {
System.out.println("Evolution completed in: " + (System.currentTimeMillis() - startTime) + "ms");
System.out.println("Fittest individual has fitness: " + population.get(0).getFitness());
}
}
use of org.kanonizo.framework.objects.TestSuite in project kanonizo by kanonizo.
the class SinglePointCrossover method crossover.
@Override
public void crossover(TestSuite parent1, TestSuite parent2) {
if (parent1.size() < 2 || parent2.size() < 2) {
return;
}
int point = RandomInstance.nextInt(Math.min(parent1.size(), parent2.size()) - 1) + 1;
TestSuite t1 = parent1.clone();
TestSuite t2 = parent2.clone();
parent1.crossover(t2, point, point);
parent2.crossover(t1, point, point);
}
use of org.kanonizo.framework.objects.TestSuite in project kanonizo by kanonizo.
the class RandomAlgorithm method generateSolution.
@Override
protected void generateSolution() {
TestSuite suite = problem.clone().getTestSuite();
List<TestCase> testCases = suite.getTestCases();
Collections.shuffle(testCases);
suite.setTestCases(testCases);
setCurrentOptimal(suite);
fitnessEvaluations++;
}
use of org.kanonizo.framework.objects.TestSuite in project kanonizo by kanonizo.
the class RandomSearchAlgorithm method generateSolution.
@Override
public void generateSolution() {
FitnessWriter writer = new FitnessWriter(this);
List<TestCase> testCases = problem.getTestSuite().getTestCases();
Display d = Framework.getInstance().getDisplay();
System.out.println("Running Random Search");
while (!shouldFinish()) {
age++;
TestSuite clone = getCurrentOptimal().clone();
List<TestCase> randomOrdering = generateRandomOrder(testCases);
clone.setTestCases(randomOrdering);
fitnessEvaluations++;
if (clone.fitter(getCurrentOptimal()).equals(clone)) {
setCurrentOptimal(clone);
}
if (TRACK_GENERATION_FITNESS) {
writer.addRow(age, getCurrentOptimal().getFitness());
} else {
writer.addRow(age, clone.getFitness());
}
d.reportProgress(Math.min((double) System.currentTimeMillis() - startTime, MAX_EXECUTION_TIME), MAX_EXECUTION_TIME);
}
System.out.println();
writer.write();
}
use of org.kanonizo.framework.objects.TestSuite in project kanonizo by kanonizo.
the class GeneticAlgorithm method evolutionComplete.
protected void evolutionComplete(TestSuite... evolved) {
for (TestSuite ts : evolved) {
ts.evolutionComplete();
fitnessEvaluations++;
if (!TRACK_GENERATION_FITNESS) {
writer.addRow(fitnessEvaluations, ts.getFitness());
}
}
}
Aggregations