KnapsackFitnessThreshold.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.BitGene;
28 import org.jenetics.engine.limit;
29 import org.jenetics.tool.trial.Params;
30 import org.jenetics.tool.trial.TrialMeter;
31 import org.jenetics.util.ISeq;
32 
33 /**
34  @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
35  @version 3.4
36  @since 3.4
37  */
38 public class KnapsackFitnessThreshold {
39 
40     private static final double MIN_FITNESS = 7000;
41     private static final double MAX_FITNESS = 10900//11000;
42     private static final int POINTS = 20;
43 
44 
45     private static final Params<Double> PARAMS = Params.of(
46         "Fitness threshold",
47         IntStream.rangeClosed(0, POINTS)
48             .mapToDouble(i -> MIN_FITNESS + (MAX_FITNESS - MIN_FITNESS)/POINTS*i)
49             .mapToObj(Double::valueOf)
50             .collect(ISeq.toISeq())
51     );
52 
53     private static final Supplier<TrialMeter<Double>>
54         TRIAL_METER = () -> TrialMeter.of(
55         "Fitness threshold",
56         "Create fitness threshold performance measures",
57         PARAMS,
58         "Generation",
59         "Fitness",
60         "Runtime"
61     );
62 
63     public static void main(final String[] argsthrows InterruptedException {
64         final Runner<Double, BitGene, Double> runner = Runner.of(
65             threshold -> KNAPSACK,
66             limit::byFitnessThreshold,
67             TRIAL_METER,
68             args
69         );
70 
71         runner.start();
72         runner.join();
73     }
74 }