parent
2d76544538
commit
49edda5505
@ -237,10 +237,6 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
this.firstindex = firstindex;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* AbstractEAIndividual methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method will initialize the individual with a given value for the
|
||||
* phenotype.
|
||||
@ -305,7 +301,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
}
|
||||
|
||||
|
||||
public double[] mapMatrixToVector(double[][] matrix) {
|
||||
public static double[] mapMatrixToVector(double[][] matrix) {
|
||||
int sumentries = 0;
|
||||
for (int i = 0; i < matrix.length; i++) {
|
||||
sumentries += matrix[i].length;
|
||||
@ -321,7 +317,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
return res;
|
||||
}
|
||||
|
||||
public double[][] mapVectorToMatrix(double[] vector, int[] sizes) {
|
||||
public static double[][] mapVectorToMatrix(double[] vector, int[] sizes) {
|
||||
double[][] matrix = new double[sizes.length][];
|
||||
int counter = 0;
|
||||
for (int i = 0; i < sizes.length; i++) {
|
||||
@ -353,8 +349,6 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,30 @@
|
||||
package eva2.optimization.individuals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ESIndividualPermutationDataTest {
|
||||
|
||||
@Test
|
||||
public void testMapXToY() throws Exception {
|
||||
double[][] matrix = new double[][]{
|
||||
{1.2, 2.3, 3.4, 1.2},
|
||||
{0.2, 0.3, 0.4}
|
||||
};
|
||||
|
||||
// Properly constructs vector from matrix
|
||||
assertArrayEquals(
|
||||
new double[]{1.2, 2.3, 3.4, 1.2, 0.2, 0.3, 0.4},
|
||||
ESIndividualPermutationData.mapMatrixToVector(matrix), 0.0
|
||||
);
|
||||
|
||||
// Properly converts to vector and back to matrix
|
||||
assertArrayEquals(
|
||||
matrix,
|
||||
ESIndividualPermutationData.mapVectorToMatrix(
|
||||
ESIndividualPermutationData.mapMatrixToVector(matrix), new int[]{4,3}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user