Examples of TerminationCondition


Examples of de.mh4j.solver.termination.TerminationCondition

    @Test
    @SuppressWarnings("unchecked")
    public void testShouldTerminate() {
        int maxStepCount = 100;
        Solver<Object> solver = mock(Solver.class);
        TerminationCondition terminator = new StepCountTermination(solver, maxStepCount);

        when(solver.getNumberOfSteps()).thenReturn(0);
        assert terminator.shouldTerminate() == false;

        when(solver.getNumberOfSteps()).thenReturn(99);
        assert terminator.shouldTerminate() == false;

        when(solver.getNumberOfSteps()).thenReturn(100);
        assert terminator.shouldTerminate() == true;

        when(solver.getNumberOfSteps()).thenReturn(1000);
        assert terminator.shouldTerminate() == true;
    }
View Full Code Here

Examples of de.mh4j.solver.termination.TerminationCondition

    @Test
    public void testSolverRun() {
        AbstractSolver<Object> solver = spy(new AbstractSolverMock());

        TerminationCondition terminationCondition = mock(TerminationCondition.class);
        when(terminationCondition.shouldTerminate()).thenReturn(true);
        solver.addTerminationCondition(terminationCondition);

        @SuppressWarnings("unchecked")
        SolverStateListener<Object> stateListener = mock(SolverStateListener.class);
        solver.addStateListener(stateListener);
View Full Code Here

Examples of de.mh4j.solver.termination.TerminationCondition

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void testShouldTerminate() {
        int maxNrOfStagnatingSteps = 50;
        Solver solver = mock(Solver.class);
        when(solver.getCurrentSolution()).thenReturn(mock(Solution.class));
        TerminationCondition terminator = new StagnationTermination(solver, maxNrOfStagnatingSteps);

        assert terminator.shouldTerminate() == false;

        for (int i = 0; i < maxNrOfStagnatingSteps - 1; i++) {
            assert terminator.shouldTerminate() == false;
        }

        assert terminator.shouldTerminate() == true : "Terminator should terminate now because we asked it "
                + maxNrOfStagnatingSteps
                + " if we should terminate without any improvement in the associated solver";
    }
View Full Code Here

Examples of net.sf.cpsolver.ifs.termination.TerminationCondition

        DataProperties properties = new DataProperties();
        properties.setProperty("General.Seed", "123321");
        UniTimeSimpleModel model = createModel();
        Solver solver = new Solver(properties);
        condition.init();
        solver.setTerminalCondition(new TerminationCondition() {

            @Override
            public boolean canContinue(Solution sltn) {
                return condition.canContinue() && !statusBar.getMyProgressMonitor().isCanceled();
            }
View Full Code Here

Examples of org.uncommons.watchmaker.framework.TerminationCondition

public class StagnationTest
{
    @Test
    public void testFittestCandidateStagnation()
    {
        TerminationCondition stagnation = new Stagnation(2, true);
        PopulationData<Object> data = new PopulationData<Object>(new Object(), 2, 1, 0.1, true, 10, 0, 0, 1);
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 2 more generations.";
        // Best doesn't improve even though mean does.
        data = new PopulationData<Object>(new Object(), 1.8, 1.2, 0.1, true, 10, 0, 1, 2);
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 1 more generation.";
        // Best doesn't improve even though mean does.
        data = new PopulationData<Object>(new Object(), 2, 1.5, 0.1, true, 10, 0, 2, 3);
        assert stagnation.shouldTerminate(data) : "Stagnation should be triggered after 2 generations without improvement.";
    }
View Full Code Here

Examples of org.uncommons.watchmaker.framework.TerminationCondition

    }

    @Test
    public void testFittestCandidateStagnationNonNatural()
    {
        TerminationCondition stagnation = new Stagnation(2, false);
        PopulationData<Object> data = new PopulationData<Object>(new Object(), 2, 1.5, 0.1, true, 10, 0, 0, 1);
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 2 more generations.";
        // Best doesn't improve even though mean does.
        data = new PopulationData<Object>(new Object(), 2.2, 1.2, 0.1, true, 10, 0, 1, 2);
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 1 more generation.";
        // Best doesn't improve even though mean does.
        data = new PopulationData<Object>(new Object(), 2, 1, 0.1, true, 10, 0, 2, 3);
        assert stagnation.shouldTerminate(data) : "Stagnation should be triggered after 2 generations without improvement.";
    }
View Full Code Here

Examples of org.uncommons.watchmaker.framework.TerminationCondition


    @Test
    public void testPopulationMeanStagnation()
    {
        TerminationCondition stagnation = new Stagnation(2, true, true);
        PopulationData<Object> data = new PopulationData<Object>(new Object(), 2, 1, 0.1, true, 10, 0, 0, 1);
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 2 more generations.";
        // Best doesn't improve but mean does.
        data = new PopulationData<Object>(new Object(), 2, 1.2, 0.1, true, 10, 0, 1, 2);
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 2 more generations.";
        // Best doesn't improve but mean does.
        data = new PopulationData<Object>(new Object(), 2, 1.5, 0.1, true, 10, 0, 2, 3);
        // Best has stagnated but mean hasn't so shouldn't terminate.
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 2 more generations.";
        // Now we let the mean stagnate...and let the best candidate get fitter...
        data = new PopulationData<Object>(new Object(), 2.1, 1.5, 0.1, true, 10, 0, 3, 4);
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 1 more generation.";
        data = new PopulationData<Object>(new Object(), 2.2, 1.5, 0.1, true, 10, 0, 4, 4);
        assert stagnation.shouldTerminate(data) : "Stagnation should be triggered after 2 generations without improvement.";
    }
View Full Code Here

Examples of org.uncommons.watchmaker.framework.TerminationCondition


    @Test
    public void testPopulationMeanStagnationNonNatural()
    {
        TerminationCondition stagnation = new Stagnation(2, false, true);
        PopulationData<Object> data = new PopulationData<Object>(new Object(), 2, 1.5, 0.1, true, 10, 0, 0, 1);
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 2 more generations.";
        // Best doesn't improve but mean does.
        data = new PopulationData<Object>(new Object(), 2, 1.2, 0.1, true, 10, 0, 1, 2);
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 2 more generations.";
        // Best doesn't improve but mean does.
        data = new PopulationData<Object>(new Object(), 2, 1, 0.1, true, 10, 0, 2, 3);
        // Best has stagnated but mean hasn't so shouldn't terminate.
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 2 more generations.";
        // Now we let the mean stagnate...and let the best candidate get fitter...
        data = new PopulationData<Object>(new Object(), 2.1, 1.6, 0.1, true, 10, 0, 3, 4);
        assert !stagnation.shouldTerminate(data) : "Stagnation should not be triggered for at least 1 more generation.";
        data = new PopulationData<Object>(new Object(), 2.2, 1.5, 0.1, true, 10, 0, 4, 4);
        assert stagnation.shouldTerminate(data) : "Stagnation should be triggered after 2 generations without improvement.";
    }
View Full Code Here

Examples of org.uncommons.watchmaker.framework.TerminationCondition

public class GenerationCountTest
{
    @Test
    public void testGenerationCounts()
    {
        TerminationCondition condition = new GenerationCount(5);
        PopulationData<Object> data = new PopulationData<Object>(new Object(), 0, 0, 0, true, 2, 0, 3, 100);
        // Generation number 3 is the 4th generation (generation numbers are zero-based).
        assert !condition.shouldTerminate(data) : "Should not terminate after 4th generation.";
        data = new PopulationData<Object>(new Object(), 0, 0, 0, true, 2, 0, 4, 100);
        // Generation number 4 is the 5th generation (generation numbers are zero-based).
        assert condition.shouldTerminate(data) : "Should terminate after 5th generation.";
    }
View Full Code Here

Examples of org.uncommons.watchmaker.framework.TerminationCondition

public class TargetFitnessTest
{
    @Test
    public void testNaturalFitness()
    {
        TerminationCondition condition = new TargetFitness(10.0d, true);
        PopulationData<Object> data = new PopulationData<Object>(new Object(), 5.0d, 4.0d, 0, true, 2, 0, 0, 100);
        assert !condition.shouldTerminate(data) : "Should not terminate before target fitness is reached.";
        data = new PopulationData<Object>(new Object(), 10.0d, 8.0d, 0, true, 2, 0, 0, 100);
        assert condition.shouldTerminate(data) : "Should terminate once target fitness is reached.";
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.