diff --git a/src/main/java/jp/kusumotolab/kgenprog/ga/crossover/CrossoverAdaptor.java b/src/main/java/jp/kusumotolab/kgenprog/ga/crossover/CrossoverAdaptor.java index a068501ec..b021d329b 100644 --- a/src/main/java/jp/kusumotolab/kgenprog/ga/crossover/CrossoverAdaptor.java +++ b/src/main/java/jp/kusumotolab/kgenprog/ga/crossover/CrossoverAdaptor.java @@ -67,7 +67,7 @@ public SecondVariantSelectionStrategy getSecondVariantSelectionStrategy() { * @param variantStore 交叉対象の個体群 * @return 交叉により生成された個体群 */ - //@Override + @Override public List exec(final VariantStore variantStore) { final List validVariants = filter(variantStore.getCurrentVariants()); final List variants = new ArrayList<>(); @@ -91,36 +91,6 @@ public List exec(final VariantStore variantStore) { return variants.subList(0, generatingCount); } - //@Override - public final List execx(final VariantStore variantStore) { - - final List filteredVariants = variantStore.getCurrentVariants() - .stream() - .filter(e -> 1 < e.getGene() // 遺伝子の長さが2に満たないバリアントは交叉に使えない - .getBases() - .size()) - .collect(Collectors.toList()); - - // filteredVariantsの要素数が2に満たない場合は交叉しない - if (filteredVariants.size() < 2) { - return Collections.emptyList(); - } - - final List variants = new ArrayList<>(); - try { - // generatingCountを超えるまでバリアントを作りづづける - while (variants.size() < generatingCount) { - final List newVariants = makeVariants(filteredVariants, variantStore); - variants.addAll(newVariants); - } - } catch (final CrossoverInfeasibleException e) { - log.debug(e.getMessage()); - } - - // バリアントを作りすぎた場合はそれを除いてリターン - return variants.subList(0, generatingCount); - } - protected abstract List makeVariants(List variants, VariantStore variantStore) throws CrossoverInfeasibleException; diff --git a/src/main/java/jp/kusumotolab/kgenprog/project/jdt/JDTASTLocation.java b/src/main/java/jp/kusumotolab/kgenprog/project/jdt/JDTASTLocation.java index 0a64c2142..c43e6b804 100644 --- a/src/main/java/jp/kusumotolab/kgenprog/project/jdt/JDTASTLocation.java +++ b/src/main/java/jp/kusumotolab/kgenprog/project/jdt/JDTASTLocation.java @@ -22,8 +22,8 @@ public class JDTASTLocation implements ASTLocation { public final ASTNode node; - protected final SourcePath sourcePath; - protected final GeneratedJDTAST generatedAST; + private final SourcePath sourcePath; + private final GeneratedJDTAST generatedAST; public JDTASTLocation(final SourcePath sourcePath, final ASTNode node, final GeneratedJDTAST generatedAST) { diff --git a/src/test/java/jp/kusumotolab/kgenprog/ga/crossover/CascadeCrossoverTest.java b/src/test/java/jp/kusumotolab/kgenprog/ga/crossover/CascadeCrossoverTest.java index 63e9a816b..df09b5778 100644 --- a/src/test/java/jp/kusumotolab/kgenprog/ga/crossover/CascadeCrossoverTest.java +++ b/src/test/java/jp/kusumotolab/kgenprog/ga/crossover/CascadeCrossoverTest.java @@ -65,7 +65,7 @@ public void setup() { */ @Test public void testForSimpleInsertions01() { - // 親1: n=0の後ろにn=0を2つ追加 + // 親1: n=0の後ろにn=2を2つ追加 final Base base1a = new Base(loc0, new InsertAfterOperation(loc2.getNode())); final Base base1b = new Base(loc0, new InsertAfterOperation(loc2.getNode())); final Gene gene1 = new Gene(Arrays.asList(base1a, base1b)); @@ -79,7 +79,7 @@ public void testForSimpleInsertions01() { + "}" + "n=2;}}"); - // 親2: n=1の後ろにn=1を2つ追加 + // 親2: n=1の後ろにn=2を2つ追加 final Base base2a = new Base(loc1, new InsertAfterOperation(loc2.getNode())); final Base base2b = new Base(loc1, new InsertAfterOperation(loc2.getNode())); final Gene gene2 = new Gene(Arrays.asList(base2a, base2b)); @@ -94,14 +94,14 @@ public void testForSimpleInsertions01() { + "n=2;}}"); // setup mocked objects used in crossover - final VariantStore spyedStore = createMockedStore(parent1, parent2); + final VariantStore spiedStore = createMockedStore(parent1, parent2); final FirstVariantSelectionStrategy strategy1 = createMocked1stStrategy(parent1); final SecondVariantSelectionStrategy strategy2 = createMocked2ndStrategy(parent2); // テスト対象のセットアップ final Crossover crossover = new CascadeCrossover(strategy1, strategy2); - final List variants = crossover.exec(spyedStore); + final List variants = crossover.exec(spiedStore); assertThat(variants) .hasSize(2) .doesNotContainNull(); @@ -163,14 +163,14 @@ public void testForSimpleInsertions02() { + "n=2;}}"); // setup mocked objects used in crossover - final VariantStore spyedStore = createMockedStore(parent1, parent2); + final VariantStore spiedStore = createMockedStore(parent1, parent2); final FirstVariantSelectionStrategy strategy1 = createMocked1stStrategy(parent1); final SecondVariantSelectionStrategy strategy2 = createMocked2ndStrategy(parent2); // テスト対象のセットアップ Crossover crossover = new CascadeCrossover(strategy1, strategy2); - final List variants = crossover.exec(spyedStore); + final List variants = crossover.exec(spiedStore); assertThat(variants) .hasSize(2) .doesNotContainNull(); @@ -202,7 +202,7 @@ public void testForSimpleInsertions02() { */ @Test public void testForComplicatedMutations() { - // 親1: n=0の後ろにn=2を追加,さらにn=0後ろにn=1を追加 + // 親1: n=0の後ろにn=2を追加,さらにn=0の後ろにn=1を追加 final Base base1a = new Base(loc0, new InsertAfterOperation(loc2.getNode())); final Base base1b = new Base(loc0, new InsertAfterOperation(loc1.getNode())); final Gene gene1 = new Gene(Arrays.asList(base1a, base1b)); @@ -232,14 +232,14 @@ public void testForComplicatedMutations() { + "n=2;}}"); // setup mocked objects used in crossover - final VariantStore spyedStore = createMockedStore(parent1, parent2); + final VariantStore spiedStore = createMockedStore(parent1, parent2); final FirstVariantSelectionStrategy strategy1 = createMocked1stStrategy(parent1); final SecondVariantSelectionStrategy strategy2 = createMocked2ndStrategy(parent2); // テスト対象のセットアップ Crossover crossover = new CascadeCrossover(strategy1, strategy2); - final List variants = crossover.exec(spyedStore); + final List variants = crossover.exec(spiedStore); assertThat(variants) .hasSize(2) .doesNotContainNull(); @@ -269,7 +269,7 @@ public void testForComplicatedMutations() { /** * 2つの親が矛盾する塩基を持つケース. - * 親2によってlocate先のstmtが消えてしまうため親1の生成に失敗 + * 親2によってlocate先のstmtが消えてしまうため子2の生成に失敗 */ @Test public void testForInconsistentParents() { @@ -301,14 +301,14 @@ public void testForInconsistentParents() { + "n=2;}}"); // setup mocked objects used in crossover - final VariantStore spyedStore = createMockedStore(parent1, parent2); + final VariantStore spiedStore = createMockedStore(parent1, parent2); final FirstVariantSelectionStrategy strategy1 = createMocked1stStrategy(parent1); final SecondVariantSelectionStrategy strategy2 = createMocked2ndStrategy(parent2); // テスト対象のセットアップ Crossover crossover = new CascadeCrossover(strategy1, strategy2); - final List variants = crossover.exec(spyedStore); + final List variants = crossover.exec(spiedStore); assertThat(variants) .hasSize(2) .doesNotContainNull(); @@ -373,14 +373,14 @@ public void testForDerivedParents() { + "n=2;}}"); // setup mocked objects used in crossover - final VariantStore spyedStore = createMockedStore(parent1, parent2); + final VariantStore spiedStore = createMockedStore(parent1, parent2); final FirstVariantSelectionStrategy strategy1 = createMocked1stStrategy(parent1); final SecondVariantSelectionStrategy strategy2 = createMocked2ndStrategy(parent2); // テスト対象のセットアップ Crossover crossover = new CascadeCrossover(strategy1, strategy2); - final List variants = crossover.exec(spyedStore); + final List variants = crossover.exec(spiedStore); assertThat(variants) .hasSize(2) .doesNotContainNull(); @@ -427,10 +427,10 @@ private JDTASTLocation getLocation(final Variant v, int idx) { private VariantStore createMockedStore(final Variant v1, final Variant v2) { // always return the specified variants for store#getCurrentVariants() - final VariantStore spyedStore = Mockito.spy(store); - when(spyedStore.getGeneratedVariants()).thenReturn(Arrays.asList(v1, v2)); - when(spyedStore.getCurrentVariants()).thenReturn(Arrays.asList(v1, v2)); - return spyedStore; + final VariantStore spiedStore = Mockito.spy(store); + when(spiedStore.getGeneratedVariants()).thenReturn(Arrays.asList(v1, v2)); + when(spiedStore.getCurrentVariants()).thenReturn(Arrays.asList(v1, v2)); + return spiedStore; } private FirstVariantSelectionStrategy createMocked1stStrategy(final Variant v) {