use of org.kanonizo.algorithms.stoppingconditions.StoppingCondition in project kanonizo by kanonizo.
the class TestCasePrioritiser method generateSolution.
@Override
protected final void generateSolution() {
TestSuite suite = problem.clone().getTestSuite();
List<TestCase> testCases = suite.getTestCases();
List<TestCase> orderedTestCases = new ArrayList<>();
init(testCases);
while (!testCases.isEmpty() && !shouldFinish()) {
TestCase tc = selectTestCase(testCases);
testCases.remove(tc);
orderedTestCases.add(tc);
fw.notifyTestCaseSelection(tc);
fw.getDisplay().reportProgress(orderedTestCases.size(), testCases.size() + orderedTestCases.size());
}
if (!testCases.isEmpty()) {
StoppingCondition terminatingStoppingCondition = stoppingConditions.stream().filter(cond -> cond.shouldFinish(this)).findFirst().get();
logger.info("Algorithm terminated by " + terminatingStoppingCondition.getClass().getSimpleName());
orderedTestCases.addAll(testCases);
}
suite.setTestCases(orderedTestCases);
fw.getDisplay().fireTestSuiteChange(suite);
setCurrentOptimal(suite);
}
use of org.kanonizo.algorithms.stoppingconditions.StoppingCondition in project kanonizo by kanonizo.
the class GeneticAlgorithm method generateSolution.
@Override
public void generateSolution() {
if (writer == null) {
writer = new FitnessWriter(this);
}
LocalDateTime date = LocalDateTime.ofInstant(Instant.ofEpochMilli(startTime), TimeZone.getDefault().toZoneId());
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd/MM/yyyy 'at' HH:mm:ss");
logger.info("Genetic Algorithm started searching at : " + date.format(format));
generateInitialPopulation();
startTime = System.currentTimeMillis();
logger.info("Genetic Algorithm running for: " + MAX_EXECUTION_TIME / 1000 + " seconds");
setCurrentOptimal(population.get(0));
Display d = Framework.getInstance().getDisplay();
System.out.println("Genetic Algorithm");
while (!shouldFinish()) {
age++;
evolve();
sortPopulation();
setCurrentOptimal(population.get(0));
if (TRACK_GENERATION_FITNESS) {
writer.addRow(age, getCurrentOptimal().getFitness());
}
d.reportProgress(Math.min((double) System.currentTimeMillis() - startTime, MAX_EXECUTION_TIME), MAX_EXECUTION_TIME);
}
writer.write();
System.out.println();
StoppingCondition terminatingStoppingCondition = stoppingConditions.stream().filter(cond -> cond.shouldFinish(this)).findFirst().get();
LocalDateTime enddate = LocalDateTime.ofInstant(Instant.ofEpochMilli(System.currentTimeMillis()), TimeZone.getDefault().toZoneId());
logger.info("Total Number of iterations: " + age + "\n");
logger.info("Genetic Algorithm finished execution at : " + enddate.format(format));
logger.info("Genetic Algorithm terminated by: " + terminatingStoppingCondition.getClass().getSimpleName());
}
Aggregations