コード例 #1
0
/**
 * @author <a href="mailto:[email protected]">Franz Wilhelmstötter</a>
 * @version 3.4
 * @since 3.4
 */
public class KnapsackFitnessThreshold {

  private static final double MIN_FITNESS = 7000;
  private static final double MAX_FITNESS = 10900; // 11000;
  private static final int POINTS = 20;

  private static final Params<Double> PARAMS =
      Params.of(
          "Fitness threshold",
          IntStream.rangeClosed(0, POINTS)
              .mapToDouble(i -> MIN_FITNESS + (MAX_FITNESS - MIN_FITNESS) / POINTS * i)
              .mapToObj(Double::valueOf)
              .collect(ISeq.toISeq()));

  private static final Supplier<TrialMeter<Double>> TRIAL_METER =
      () ->
          TrialMeter.of(
              "Fitness threshold",
              "Create fitness threshold performance measures",
              PARAMS,
              "Generation",
              "Fitness",
              "Runtime");

  public static void main(final String[] args) throws InterruptedException {
    final Runner<Double, BitGene, Double> runner =
        Runner.of(threshold -> KNAPSACK, limit::byFitnessThreshold, TRIAL_METER, args);

    runner.start();
    runner.join();
  }
}
コード例 #2
0
/**
 * @author <a href="mailto:[email protected]">Franz Wilhelmstötter</a>
 * @version 3.4
 * @since 3.4
 */
public class KnapsackExecutionTime {

  private static final double GEN_BASE = pow(10, log10(100) / 20.0);
  private static final Params<Long> PARAMS =
      Params.of(
          "Execution time",
          IntStream.rangeClosed(1, 50)
              .mapToLong(i -> max((long) pow(GEN_BASE, i), i))
              .mapToObj(Long::new)
              .collect(ISeq.toISeq()));

  private static final Supplier<TrialMeter<Long>> TRIAL_METER =
      () ->
          TrialMeter.of(
              "Execution time",
              "Create execution time performance measures",
              PARAMS,
              "Generation",
              "Fitness",
              "Runtime");

  public static void main(final String[] args) throws InterruptedException {
    final Runner<Long, BitGene, Double> runner =
        Runner.of(
            KNAPSACK,
            duration -> limit.byExecutionTime(Duration.ofMillis(duration)),
            TRIAL_METER,
            args);

    runner.start();
    runner.join();
  }
}
コード例 #3
0
/**
 * @author <a href="mailto:[email protected]">Franz Wilhelmstötter</a>
 * @version 3.5
 * @since 3.5
 */
public class KnapsackSelectorComparison {

  private static final double GEN_BASE = pow(10, log10(100) / 20.0);
  private static final Params<Long> PARAMS =
      Params.of(
          "Fixed generation",
          IntStream.rangeClosed(1, 50)
              .mapToLong(i -> max((long) pow(GEN_BASE, i), i))
              .mapToObj(Long::valueOf)
              .collect(ISeq.toISeq()));

  private static final Supplier<TrialMeter<Long>> TRIAL_METER =
      () ->
          TrialMeter.of(
              "Fixed generation",
              "Create fixed generation performance measures",
              PARAMS,
              "Generation1",
              "Fitness1",
              "Runtime1",
              "Generation2",
              "Fitness2",
              "Runtime2");

  public static void main(final String[] args) throws InterruptedException {
    final Runner2<Long, BitGene, Double> runner =
        Runner2.of(
            KNAPSACK.builder().selector(new MonteCarloSelector<>()).build(),
            limit::byFixedGeneration,
            KNAPSACK,
            limit::byFixedGeneration,
            TRIAL_METER,
            args);

    runner.start();
    runner.join();
  }
}