From 282c31b833ea09406643f431149385c400b931b1 Mon Sep 17 00:00:00 2001 From: Ryoko Izuta Date: Tue, 1 Sep 2020 22:32:11 +0900 Subject: [PATCH] add information to summary output --- .../jp/kusumotolab/kgenprog/KGenProgMain.java | 20 ++++++++- .../kgenprog/ga/variant/VariantStore.java | 42 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/main/java/jp/kusumotolab/kgenprog/KGenProgMain.java b/src/main/java/jp/kusumotolab/kgenprog/KGenProgMain.java index 81798879b..07bed5d7f 100644 --- a/src/main/java/jp/kusumotolab/kgenprog/KGenProgMain.java +++ b/src/main/java/jp/kusumotolab/kgenprog/KGenProgMain.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jp.kusumotolab.kgenprog.fl.FaultLocalization; @@ -117,6 +118,9 @@ public List run() throws RuntimeException { // 世代別サマリの出力 logGenerationSummary(stopwatch.toString(), variantsByMutation, variantsByCrossover); stopwatch.split(); + variantStore.updateVariantCounts( + Stream.concat(variantsByMutation.stream(), variantsByCrossover.stream()) + .collect(Collectors.toList())); // しきい値以上の completedVariants が生成された場合は,GA を抜ける if (areEnoughCompletedVariants(variantStore.getFoundSolutions())) { @@ -146,7 +150,9 @@ public List run() throws RuntimeException { stopwatch.unsplit(); strategies.finish(); - logGAStopped(variantStore.getGenerationNumber(), stopwatch.toString(), exitStatus); + logGAStopped(variantStore.getGenerationNumber(), variantStore.getVariantCount(), + variantStore.getSyntaxValidVariantCount(), variantStore.getBuildSuccessVariantCount(), + stopwatch.toString(), exitStatus); return variantStore.getFoundSolutions(config.getRequiredSolutionsCount()); } @@ -289,7 +295,8 @@ private DecimalFormat createDecimalFormat() { return new DecimalFormat("#.###"); } - private void logGAStopped(final OrdinalNumber generation, final String time, + private void logGAStopped(final OrdinalNumber generation, final int variantCount, + final int syntaxValidCount, final int buildSuccessCount, final String time, final ExitStatus exitStatus) { final StringBuilder sb = new StringBuilder(); sb// @@ -298,6 +305,15 @@ private void logGAStopped(final OrdinalNumber generation, final String time, .append("Reached generation = ") .append(generation.intValue()) .append(System.lineSeparator()) + .append("Generated variants = ") + .append(variantCount) + .append(System.lineSeparator()) + .append("Syntax valid variants = ") + .append(syntaxValidCount) + .append(System.lineSeparator()) + .append("Build succeeded variants = ") + .append(buildSuccessCount) + .append(System.lineSeparator()) .append("Time elapsed = ") .append(time) .append(System.lineSeparator()) diff --git a/src/main/java/jp/kusumotolab/kgenprog/ga/variant/VariantStore.java b/src/main/java/jp/kusumotolab/kgenprog/ga/variant/VariantStore.java index b559ae8c1..2441a6d95 100644 --- a/src/main/java/jp/kusumotolab/kgenprog/ga/variant/VariantStore.java +++ b/src/main/java/jp/kusumotolab/kgenprog/ga/variant/VariantStore.java @@ -36,6 +36,9 @@ public class VariantStore { private final AtomicLong variantCounter; private final Function elementReplacer; private final Consumer variantRecorder; + private int variantCount; + private int syntaxValidVariantCount; + private int buildSuccessVariantCount; /** * @param config 設定 @@ -57,6 +60,9 @@ public VariantStore(final Configuration config, final Strategies strategies) { foundSolutions = new ArrayList<>(); // 最後に次の世代番号に進めておく generation.incrementAndGet(); + variantCount = 0; + syntaxValidVariantCount = 0; + buildSuccessVariantCount = 0; } /** @@ -129,6 +135,27 @@ public List getFoundSolutions(final int maxNumber) { return foundSolutions.subList(0, length); } + /** + * @return 今まで生成した個体数 + */ + public int getVariantCount() { + return variantCount; + } + + /** + * @return 今まで生成した個体のうち、Syntax Valid な個体数 + */ + public int getSyntaxValidVariantCount() { + return syntaxValidVariantCount; + } + + /** + * @return 今まで生成した個体のうち、ビルド成功個体数 + */ + public int getBuildSuccessVariantCount() { + return buildSuccessVariantCount; + } + /** * 引数の要素すべてを次世代のVariantとして追加する * @@ -233,4 +260,19 @@ private Consumer newVariantRecorder(final boolean historyRecord) { public Configuration getConfiguration() { return config; } + + /** + * variantCount, syntaxValidVariantCount, buildSuccessVariantCountを更新する + * + * @param variants 前回の更新以降新たに生成した個体のリスト + */ + public void updateVariantCounts(final List variants) { + variantCount += variants.size(); + syntaxValidVariantCount += variants.stream() + .filter(Variant::isSyntaxValid) + .count(); + buildSuccessVariantCount += variants.stream() + .filter(Variant::isBuildSucceeded) + .count(); + } }