KnapsackFitnessConvergence.java
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 org.jenetics.tool.evaluation.engines.KNAPSACK;
23 
24 import java.util.function.Supplier;
25 import java.util.stream.IntStream;
26 
27 import org.jenetics.internal.util.Args;
28 
29 import org.jenetics.BitGene;
30 import org.jenetics.engine.limit;
31 import org.jenetics.tool.trial.Params;
32 import org.jenetics.tool.trial.TrialMeter;
33 import org.jenetics.util.ISeq;
34 
35 /**
36  @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
37  @version 3.7
38  @since 3.7
39  */
40 public class KnapsackFitnessConvergence {
41 
42     private static final Params<Double> PARAMS = Params.of(
43         "Convergence epsilon",
44         IntStream.rangeClosed(110)
45             .mapToObj(i -> Math.pow(10, -i))
46             .collect(ISeq.toISeq())
47     );
48 
49     private static final Supplier<TrialMeter<Double>>
50         TRIAL_METER = () -> TrialMeter.of(
51         "Fitness convergence",
52         "Create fitness convergence performance measures",
53         PARAMS,
54         "Generation",
55         "Fitness",
56         "Runtime"
57     );
58 
59     public static void main(final String[] argsthrows InterruptedException {
60         final Args arguments = Args.of(args);
61         final ISeq<Integer> sizes = arguments.intArgs("params");
62 
63         final Runner<Double, BitGene, Double> runner = Runner.of(
64             fitness -> KNAPSACK,
65             epsilon -> limit.byFitnessConvergence(sizes.get(0), sizes.get(1), epsilon),
66             TRIAL_METER,
67             args
68         );
69 
70         runner.start();
71         runner.join();
72     }
73 
74 }