01 /*
02 * Java Genetic Algorithm Library (jenetics-3.8.0).
03 * Copyright (c) 2007-2017 Franz Wilhelmstötter
04 *
05 * Licensed under the Apache License, Version 2.0 (the "License");
06 * you may not use this file except in compliance with the License.
07 * You may obtain a copy of the License at
08 *
09 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Author:
18 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
19 */
20 package org.jenetics.tool.evaluation;
21
22 import static java.lang.Math.log10;
23 import static java.lang.Math.max;
24 import static java.lang.Math.pow;
25 import static org.jenetics.tool.evaluation.engines.KNAPSACK;
26
27 import java.util.function.Supplier;
28 import java.util.stream.IntStream;
29
30 import org.jenetics.BitGene;
31 import org.jenetics.engine.limit;
32 import org.jenetics.tool.trial.Params;
33 import org.jenetics.tool.trial.TrialMeter;
34 import org.jenetics.util.ISeq;
35
36 /**
37 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
38 * @version 3.4
39 * @since 3.4
40 */
41 public class KnapsackFixedGeneration {
42
43 private static final double GEN_BASE = pow(10, log10(100)/20.0);
44 private static final Params<Long> PARAMS = Params.of(
45 "Fixed generation",
46 IntStream.rangeClosed(1, 50)
47 .mapToLong(i -> max((long)pow(GEN_BASE, i), i))
48 .mapToObj(Long::valueOf)
49 .collect(ISeq.toISeq())
50 );
51
52 private static final Supplier<TrialMeter<Long>>
53 TRIAL_METER = () -> TrialMeter.of(
54 "Fixed generation",
55 "Create fixed generation performance measures",
56 PARAMS,
57 "Generation",
58 "Fitness",
59 "Runtime"
60 );
61
62 public static void main(final String[] args) throws InterruptedException {
63 final Runner<Long, BitGene, Double> runner = Runner.of(
64 generation -> KNAPSACK,
65 limit::byFixedGeneration,
66 TRIAL_METER,
67 args
68 );
69
70 runner.start();
71 runner.join();
72 }
73
74 }
|