Search in sources :

Example 1 with Display

use of org.kanonizo.display.Display 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());
}
Also used : LocalDateTime(java.time.LocalDateTime) StoppingCondition(org.kanonizo.algorithms.stoppingconditions.StoppingCondition) FitnessWriter(org.kanonizo.reporting.FitnessWriter) DateTimeFormatter(java.time.format.DateTimeFormatter) Display(org.kanonizo.display.Display)

Example 2 with Display

use of org.kanonizo.display.Display in project kanonizo by kanonizo.

the class Main method main.

public static void main(String[] args) {
    Framework fw = Framework.getInstance();
    // org.evosuite.Properties.TT = true;
    Options options = TestSuitePrioritisation.getCommandLineOptions();
    CommandLine line = null;
    try {
        line = new DefaultParser().parse(options, args, false);
        if (TestSuitePrioritisation.hasHelpOption(line)) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Search Algorithms", options);
            return;
        }
        Reflections r = Util.getReflections();
        Set<Field> parameters = r.getFieldsAnnotatedWith(Parameter.class);
        TestSuitePrioritisation.handleProperties(line, parameters);
        if (MutationProperties.VISIT_MUTANTS) {
            InstrumentingClassLoader.getInstance().setVisitMutants(true);
        }
        setupFramework(line, fw);
    } catch (Exception e) {
        logger.error(e);
    }
    Display d = null;
    if (!line.hasOption(TestSuitePrioritisation.GUI_SHORT)) {
        d = new ConsoleDisplay();
        d.initialise();
        fw.setDisplay(d);
        fw.addSelectionListener((ConsoleDisplay) d);
        try {
            fw.run();
        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
        }
        // necessary due to random thread creation during test cases (don't do
        // this ever again)
        java.lang.System.exit(0);
    } else {
        d = new KanonizoFrame();
        d.initialise();
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) Field(java.lang.reflect.Field) CommandLine(org.apache.commons.cli.CommandLine) KanonizoFrame(org.kanonizo.display.fx.KanonizoFrame) ConsoleDisplay(org.kanonizo.display.ConsoleDisplay) SystemConfigurationException(org.kanonizo.exception.SystemConfigurationException) MissingOptionException(org.apache.commons.cli.MissingOptionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DefaultParser(org.apache.commons.cli.DefaultParser) Reflections(org.reflections.Reflections) ConsoleDisplay(org.kanonizo.display.ConsoleDisplay) Display(org.kanonizo.display.Display)

Example 3 with Display

use of org.kanonizo.display.Display 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)

Aggregations

Display (org.kanonizo.display.Display)3 FitnessWriter (org.kanonizo.reporting.FitnessWriter)2 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 CommandLine (org.apache.commons.cli.CommandLine)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 MissingOptionException (org.apache.commons.cli.MissingOptionException)1 Options (org.apache.commons.cli.Options)1 StoppingCondition (org.kanonizo.algorithms.stoppingconditions.StoppingCondition)1 ConsoleDisplay (org.kanonizo.display.ConsoleDisplay)1 KanonizoFrame (org.kanonizo.display.fx.KanonizoFrame)1 SystemConfigurationException (org.kanonizo.exception.SystemConfigurationException)1 TestCase (org.kanonizo.framework.objects.TestCase)1 TestSuite (org.kanonizo.framework.objects.TestSuite)1 Reflections (org.reflections.Reflections)1