parent
3133652cd2
commit
6ea7dc46f0
@ -883,7 +883,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the fitnes to the maximum possible value for the given individual.
|
* Resets the fitness to the maximum possible value for the given individual.
|
||||||
*
|
*
|
||||||
* @param indy an individual whose fitness will be reset
|
* @param indy an individual whose fitness will be reset
|
||||||
*/
|
*/
|
||||||
@ -2091,7 +2091,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
*/
|
*/
|
||||||
public double[] getCenter() {
|
public double[] getCenter() {
|
||||||
if (size() == 0) {
|
if (size() == 0) {
|
||||||
EVAERROR.errorMsgOnce("Invalid pop size in DistractingPopulation:getCenter!");
|
return null;
|
||||||
}
|
}
|
||||||
double[] centerPos = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
|
double[] centerPos = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
|
||||||
for (int i = 1; i < size(); i++) {
|
for (int i = 1; i < size(); i++) {
|
||||||
@ -2123,7 +2123,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
|
|||||||
*/
|
*/
|
||||||
public double[] getCenterWeighted(double[] weights) {
|
public double[] getCenterWeighted(double[] weights) {
|
||||||
if (size() == 0 || (weights.length > size()) || (weights.length == 0)) {
|
if (size() == 0 || (weights.length > size()) || (weights.length == 0)) {
|
||||||
EVAERROR.errorMsgOnce("Invalid pop size in DistractingPopulation:getCenterWeighted!");
|
return null;
|
||||||
}
|
}
|
||||||
double[] centerPos = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
|
double[] centerPos = AbstractEAIndividual.getDoublePosition(getEAIndividual(0));
|
||||||
Mathematics.svMult(weights[0], centerPos, centerPos);
|
Mathematics.svMult(weights[0], centerPos, centerPos);
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package eva2.optimization.population;
|
package eva2.optimization.population;
|
||||||
|
|
||||||
import com.sun.org.apache.bcel.internal.generic.POP;
|
import com.sun.org.apache.bcel.internal.generic.POP;
|
||||||
|
import eva2.optimization.individuals.AbstractEAIndividual;
|
||||||
import eva2.optimization.individuals.ESIndividualDoubleData;
|
import eva2.optimization.individuals.ESIndividualDoubleData;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class PopulationTest {
|
public class PopulationTest {
|
||||||
Population emptyPopulation;
|
Population emptyPopulation;
|
||||||
@ -21,11 +23,6 @@ public class PopulationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPutData() throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetData() throws Exception {
|
public void testGetData() throws Exception {
|
||||||
// Simple data
|
// Simple data
|
||||||
@ -314,7 +311,17 @@ public class PopulationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCenter() throws Exception {
|
public void testGetCenter() throws Exception {
|
||||||
|
assertNull(emptyPopulation.getCenter());
|
||||||
|
|
||||||
|
for(int i = 0; i < 10; i++) {
|
||||||
|
ESIndividualDoubleData indy = mock(ESIndividualDoubleData.class);
|
||||||
|
when(indy.getDGenotype()).thenReturn(new double[]{i, i, i, i, i});
|
||||||
|
emptyPopulation.add(indy);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertArrayEquals(new double[]{
|
||||||
|
4.5, 4.5, 4.5, 4.5, 4.5
|
||||||
|
}, emptyPopulation.getCenter(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -334,7 +341,15 @@ public class PopulationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFitSum() throws Exception {
|
public void testGetFitSum() throws Exception {
|
||||||
|
for(int i = 0; i < 10; i++) {
|
||||||
|
ESIndividualDoubleData indy = mock(ESIndividualDoubleData.class);
|
||||||
|
when(indy.getFitness(0)).thenReturn((double)i);
|
||||||
|
when(indy.getFitness(1)).thenReturn((double)i*2);
|
||||||
|
emptyPopulation.add(indy);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(45.0, emptyPopulation.getFitSum(0), 0.0);
|
||||||
|
assertEquals(90.0, emptyPopulation.getFitSum(1), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -354,7 +369,12 @@ public class PopulationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFreeSlots() throws Exception {
|
public void testGetFreeSlots() throws Exception {
|
||||||
|
assertEquals(10, emptyPopulation.getFreeSlots());
|
||||||
|
|
||||||
|
ESIndividualDoubleData indy = mock(ESIndividualDoubleData.class);
|
||||||
|
emptyPopulation.add(indy);
|
||||||
|
|
||||||
|
assertEquals(9, emptyPopulation.getFreeSlots());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -367,6 +387,19 @@ public class PopulationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutDataAllIndies() throws Exception {
|
||||||
|
ESIndividualDoubleData indy1 = mock(ESIndividualDoubleData.class);
|
||||||
|
ESIndividualDoubleData indy2 = mock(ESIndividualDoubleData.class);
|
||||||
|
|
||||||
|
emptyPopulation.add(indy1);
|
||||||
|
emptyPopulation.add(indy2);
|
||||||
|
emptyPopulation.putDataAllIndies("test", 12);
|
||||||
|
|
||||||
|
verify(indy1).putData("test", 12);
|
||||||
|
verify(indy2).putData("test", 12);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFilterByFitness() throws Exception {
|
public void testFilterByFitness() throws Exception {
|
||||||
ESIndividualDoubleData indy1, indy2, indy3;
|
ESIndividualDoubleData indy1, indy2, indy3;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user