01 /*
02 * CISELab, Computational and Intelligent Systems Engineering Laboratory
03 * Department of Engineering
04 * University of Sannio, 82100 Benevento (ITALY)
05 * web-site: www.ciselab.org
06 *
07 * JENES, A Java Library for Genetic Algorithms
08 * Copyright (C) 2009, Luigi Troiano
09 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 02110-1301 USA
24 *
25 * COPYRIGHT DISCLAIMER
26 * CISELab, hereby disclaims all copyright interest in the
27 * library `JENES' (A Java Library for Genetic Algorithms)
28 * written by Luigi Troiano et al.
29 *
30 * Luigi Troiano, 1 January 2009
31 * CISELab Coordinator
32 *
33 */
34 package jenes.tutorials.problem5;
35
36 import java.util.HashSet;
37 import java.util.Set;
38
39 import jenes.Random;
40 import jenes.chromosome.GenericAlleleSet;
41
42 public class DoubleAlleleSet extends GenericAlleleSet<Double> {
43
44 public DoubleAlleleSet(Set<Double> set) {
45 super(set);
46 }
47
48 /**
49 * Builds a DoubleAlleleSet with random values within the range [lowerBound,upperBound]
50 * <p>
51 * @param size the allala set cardinality
52 * @param lowerBound the min value to choose
53 * @param upperBound the max value to choose
54 * @return a new DoubleAlleleSet
55 */
56 public static DoubleAlleleSet createRandom(int size, double lowerBound, double upperBound ) {
57 HashSet<Double> values = new HashSet<Double>();
58 Random rand = Random.getInstance();
59
60 for( int i = 0; i < size; ++i ) {
61 values.add(rand.nextDouble(lowerBound, upperBound+Double.MIN_VALUE));
62 }
63
64 return new DoubleAlleleSet(values);
65 }
66
67 /**
68 * Builds a new DoubleAlleleSet with uniformly distributed values within the range [lowerBound,upperBound]
69 * <p>
70 * @param size the allala set cardinality
71 * @param lowerBound the min value to choose
72 * @param upperBound the max value to choose
73 * @return a new DoubleAlleleSet
74 */
75 public static DoubleAlleleSet createUniform(int size, int lowerBound, int upperBound ) {
76 HashSet<Double> values = new HashSet<Double>();
77
78 double step = 1.0/upperBound - lowerBound;
79 for( double x = lowerBound; x <= upperBound; x += step ) {
80 values.add(x);
81 }
82
83 return new DoubleAlleleSet(values);
84 }
85
86
87 }
88
|
|
|