Package de.mh4j.solver.termination

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


    @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

    @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

TOP

Related Classes of de.mh4j.solver.termination.TerminationCondition

Copyright © 2018 www.massapicom. 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.