Search in sources :

Example 6 with TestSuite

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());
    }
}
Also used : TestSuite(org.kanonizo.framework.objects.TestSuite) ArrayList(java.util.ArrayList)

Example 7 with TestSuite

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);
}
Also used : TestSuite(org.kanonizo.framework.objects.TestSuite)

Example 8 with TestSuite

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++;
}
Also used : TestSuite(org.kanonizo.framework.objects.TestSuite) TestCase(org.kanonizo.framework.objects.TestCase)

Example 9 with TestSuite

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();
}
Also used : TestSuite(org.kanonizo.framework.objects.TestSuite) TestCase(org.kanonizo.framework.objects.TestCase) FitnessWriter(org.kanonizo.reporting.FitnessWriter) Display(org.kanonizo.display.Display)

Example 10 with TestSuite

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());
        }
    }
}
Also used : TestSuite(org.kanonizo.framework.objects.TestSuite)

Aggregations

TestSuite (org.kanonizo.framework.objects.TestSuite)11 TestCase (org.kanonizo.framework.objects.TestCase)5 ArrayList (java.util.ArrayList)4 Parameter (com.scythe.instrumenter.InstrumentationProperties.Parameter)1 ClassAnalyzer (com.scythe.instrumenter.analysis.ClassAnalyzer)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Scanner (java.util.Scanner)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 CSVFormat (org.apache.commons.csv.CSVFormat)1 CSVParser (org.apache.commons.csv.CSVParser)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 StoppingCondition (org.kanonizo.algorithms.stoppingconditions.StoppingCondition)1 Display (org.kanonizo.display.Display)1