parent
28f442af50
commit
469e2033d6
@ -4,6 +4,7 @@ import eva2.optimization.population.InterfaceSolutionSet;
|
||||
import eva2.optimization.population.PopulationInterface;
|
||||
import eva2.problems.InterfaceOptimizationProblem;
|
||||
import eva2.util.annotation.Description;
|
||||
import eva2.util.annotation.Parameter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -24,8 +25,7 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
|
||||
msg = "Not terminated.";
|
||||
}
|
||||
|
||||
public GenerationTerminator() {
|
||||
}
|
||||
public GenerationTerminator() {}
|
||||
|
||||
public GenerationTerminator(int gens) {
|
||||
maxGenerations = gens;
|
||||
@ -37,8 +37,8 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTerminated(PopulationInterface Pop) {
|
||||
if (maxGenerations < Pop.getGeneration()) {
|
||||
public boolean isTerminated(PopulationInterface pop) {
|
||||
if (maxGenerations < pop.getGeneration()) {
|
||||
msg = maxGenerations + " generations reached.";
|
||||
return true;
|
||||
}
|
||||
@ -52,10 +52,10 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = "Generations calls=" + maxGenerations;
|
||||
return ret;
|
||||
return "Generations calls = " + maxGenerations;
|
||||
}
|
||||
|
||||
@Parameter(description = "Number of generations to evaluate.")
|
||||
public void setGenerations(int x) {
|
||||
maxGenerations = x;
|
||||
}
|
||||
@ -63,13 +63,4 @@ public class GenerationTerminator implements InterfaceTerminator, Serializable {
|
||||
public int getGenerations() {
|
||||
return maxGenerations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tip text for this property
|
||||
*
|
||||
* @return tip text for this property
|
||||
*/
|
||||
public String generationsTipText() {
|
||||
return "number of generations to evaluate.";
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package eva2.optimization.operator.terminators;
|
||||
|
||||
import eva2.optimization.population.Population;
|
||||
import eva2.optimization.population.SolutionSet;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class GenerationTerminatorTest {
|
||||
GenerationTerminator terminator;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
terminator = new GenerationTerminator();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsTerminated() throws Exception {
|
||||
Population pop = new Population();
|
||||
pop.setGeneration(100);
|
||||
assertFalse(terminator.isTerminated(pop));
|
||||
pop.incrGeneration();
|
||||
assertTrue(terminator.isTerminated(pop));
|
||||
|
||||
pop.setGeneration(100);
|
||||
SolutionSet sset = new SolutionSet(pop);
|
||||
assertFalse(terminator.isTerminated(sset));
|
||||
pop.incrGeneration();
|
||||
assertTrue(terminator.isTerminated(sset));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastTerminationMessage() throws Exception {
|
||||
assertNotNull(terminator.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() throws Exception {
|
||||
assertEquals("Generation calls = 100", terminator.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetGenerations() throws Exception {
|
||||
// Defaults to 100 generations
|
||||
assertEquals(100, terminator.getGenerations());
|
||||
|
||||
terminator.setGenerations(42);
|
||||
|
||||
assertEquals(42, terminator.getGenerations());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGenerations() throws Exception {
|
||||
// Defaults to 100 generations
|
||||
assertEquals(100, terminator.getGenerations());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user