parent
469e2033d6
commit
327a95b037
@ -29,12 +29,12 @@ public class KnownOptimaFoundTerminator implements InterfaceTerminator, Serializ
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(InterfaceOptimizationProblem prob) {
|
public void initialize(InterfaceOptimizationProblem prob) throws IllegalArgumentException {
|
||||||
if (prob != null) {
|
if (prob != null) {
|
||||||
if (prob instanceof InterfaceMultimodalProblemKnown) {
|
if (prob instanceof InterfaceMultimodalProblemKnown) {
|
||||||
mProblem = (InterfaceMultimodalProblemKnown) prob;
|
mProblem = (InterfaceMultimodalProblemKnown) prob;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.log(Level.WARNING, "KnownOptimaFoundTerminator only works with InterfaceMultimodalProblemKnown instances!");
|
throw new IllegalArgumentException("KnownOptimaFoundTerminator only works with InterfaceMultimodalProblemKnown instances!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOGGER.log(Level.WARNING, "KnownOptimaFoundTerminator wont work with null problem!");
|
LOGGER.log(Level.WARNING, "KnownOptimaFoundTerminator wont work with null problem!");
|
||||||
|
@ -722,9 +722,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
this.historyList.add((AbstractEAIndividual) this.getBestEAIndividual().clone());
|
this.historyList.add((AbstractEAIndividual) this.getBestEAIndividual().clone());
|
||||||
}
|
}
|
||||||
if (isAutoAging()) {
|
if (isAutoAging()) {
|
||||||
for (AbstractEAIndividual individual : this) {
|
this.forEach(AbstractEAIndividual::incrAge);
|
||||||
individual.incrAge();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.generationCount++;
|
this.generationCount++;
|
||||||
firePropertyChangedEvent(NEXT_GENERATION_PERFORMED);
|
firePropertyChangedEvent(NEXT_GENERATION_PERFORMED);
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package eva2.optimization.operator.terminators;
|
||||||
|
|
||||||
|
import eva2.optimization.population.Population;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class MaximumTimeTerminatorTest {
|
||||||
|
MaximumTimeTerminator terminator;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
terminator = new MaximumTimeTerminator();
|
||||||
|
terminator.setMaximumTime(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 2500)
|
||||||
|
public void testIsTerminated() throws Exception {
|
||||||
|
terminator.initialize(null);
|
||||||
|
|
||||||
|
while(!terminator.isTerminated(new Population()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLastTerminationMessage() throws Exception {
|
||||||
|
assertNotNull(terminator.lastTerminationMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInitialize() throws Exception {
|
||||||
|
terminator.initialize(null);
|
||||||
|
// Should not be terminated after reinitialization
|
||||||
|
assertFalse(terminator.isTerminated(new Population()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToString() throws Exception {
|
||||||
|
assertNotNull(terminator.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetMaximumTime() throws Exception {
|
||||||
|
assertEquals(1, terminator.getMaximumTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetMaximumTime() throws Exception {
|
||||||
|
terminator.setMaximumTime(10);
|
||||||
|
assertEquals(10, terminator.getMaximumTime());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user