2 * Description: provide an bound, and the corresponding operations
4 * @ Author Create/Modi Note
5 * Xiaofeng Xie Oct. 9, 2002
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * Please acknowledge the author(s) if you use this code in any way.
20 package net
.adaptivebox
.global
;
22 public class BasicBound
{
23 public static final double MINDOUBLE
= -1e308
;
24 public static final double MAXDOUBLE
= 1e308
;
26 public double minValue
= MINDOUBLE
;
27 public double maxValue
= MAXDOUBLE
;
31 public BasicBound(double min
, double max
) {
32 minValue
= Math
.min(min
, max
);
33 maxValue
= Math
.max(min
, max
);
36 public double getLength() {
37 return Math
.abs(maxValue
-minValue
);
40 public boolean isSatisfyCondition(double child
){
41 if(child
> maxValue
|| child
< minValue
) {
47 public double boundAdjust(double value
){
48 if(value
> maxValue
) {
50 } else if (value
< minValue
) {
56 public double annulusAdjust (double value
) {
57 if(value
> maxValue
) {
58 double extendsLen
= (value
-maxValue
)%getLength();
59 value
= minValue
+extendsLen
;
60 } else if (value
< minValue
) {
61 double extendsLen
= (minValue
-value
)%getLength();
62 value
= maxValue
-extendsLen
;
67 public static BasicBound
getBound(double[] data
) {
68 BasicBound bound
= new BasicBound();
72 bound
.minValue
= data
[0];
73 bound
.maxValue
= data
[0];
74 for(int i
=1; i
<data
.length
; i
++) {
75 bound
.minValue
= Math
.min(bound
.minValue
, data
[i
]);
76 bound
.maxValue
= Math
.max(bound
.maxValue
, data
[i
]);
84 public double randomAdjust (double value
){
85 if(value
> maxValue
|| value
< minValue
) {
86 value
= getRandomValue();
91 public double getRandomValue(){
92 return RandomGenerator
.doubleRangeRandom(minValue
, maxValue
);