01 /*
02 * Java Genetic Algorithm Library (jenetics-3.7.0).
03 * Copyright (c) 2007-2016 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.time.Duration;
28 import java.util.function.Supplier;
29 import java.util.stream.IntStream;
30
31 import org.jenetics.BitGene;
32 import org.jenetics.engine.limit;
33 import org.jenetics.tool.trial.Params;
34 import org.jenetics.tool.trial.TrialMeter;
35 import org.jenetics.util.ISeq;
36
37 /**
38 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
39 * @version 3.4
40 * @since 3.4
41 */
42 public class KnapsackExecutionTime {
43
44 private static final double GEN_BASE = pow(10, log10(100)/20.0);
45 private static final Params<Long> PARAMS = Params.of(
46 "Generations",
47 IntStream.rangeClosed(1, 50)
48 .mapToLong(i -> max((long)pow(GEN_BASE, i), i))
49 .mapToObj(Long::valueOf)
50 .collect(ISeq.toISeq())
51 );
52
53 private static final Supplier<TrialMeter<Long>>
54 TRIAL_METER = () -> TrialMeter.of(
55 "Execution time",
56 "Create execution time performance measures",
57 PARAMS,
58 "Generation",
59 "Fitness",
60 "Runtime"
61 );
62
63 public static void main(final String[] args) throws InterruptedException {
64 final Runner<Long, BitGene, Double> runner = Runner.of(
65 duration -> KNAPSACK,
66 duration -> limit.byExecutionTime(Duration.ofMillis(duration)),
67 TRIAL_METER,
68 args
69 );
70
71 runner.start();
72 runner.join();
73 }
74
75 }
|