2 * Description: provide the information for the search space (S)
4 * @ Author Create/Modi Note
5 * Xiaofeng Xie Mar 2, 2003
6 * Xiaofeng Xie May 11, 2004
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * Please acknowledge the author(s) if you use this code in any way.
21 * [1] Zhang W J, Xie X F, Bi D C. Handling boundary constraints for numerical
22 * optimization by particle swarm flying in periodic search space. Congress
23 * on Evolutionary Computation, Oregon, USA, 2004
24 * @ especially for particle swarm agent
27 package net
.adaptivebox
.space
;
28 import net
.adaptivebox
.global
.*;
30 public class DesignSpace
{
31 //The information of all the dimension
32 private DesignDim
[] dimProps
;
34 public DesignSpace(int dim
) {
35 dimProps
= new DesignDim
[dim
];
38 public DesignDim
getDimAt(int index
) {
39 return dimProps
[index
];
42 public void setElemAt(DesignDim elem
, int index
) {
43 dimProps
[index
] = elem
;
46 public int getDimension() {
50 return dimProps
.length
;
53 public double boundAdjustAt(double val
, int dim
){
54 return dimProps
[dim
].paramBound
.boundAdjust(val
);
57 public void annulusAdjust (double[] location
){
58 for (int i
=0; i
<getDimension(); i
++) {
59 location
[i
] = dimProps
[i
].paramBound
.annulusAdjust(location
[i
]);
63 public void randomAdjust (double[] location
){
64 for (int i
=0; i
<getDimension(); i
++) {
65 location
[i
] = dimProps
[i
].paramBound
.randomAdjust(location
[i
]);
69 public boolean satisfyCondition(double[] location
){
70 for (int i
=0; i
<getDimension(); i
++) {
71 if (!dimProps
[i
].paramBound
.isSatisfyCondition(location
[i
])) {
75 /*If the limits are not violated, return TRUE*/
79 public void mutationAt(double[] location
, int i
){
80 location
[i
] = dimProps
[i
].paramBound
.getRandomValue();
83 public double mutationUniformAtPointAsCenter (double pointX
, int i
){
84 double length
= this.getMagnitudeIn(i
)/2;
85 pointX
+= RandomGenerator
.doubleRangeRandom(-1*length
, length
);
90 public double getUpValueAt(int dimensionIndex
) {
91 return dimProps
[dimensionIndex
].paramBound
.maxValue
;
94 public double getLowValueAt(int dimensionIndex
) {
95 return dimProps
[dimensionIndex
].paramBound
.minValue
;
98 public double getMagnitudeIn(int dimensionIndex
) {
99 return dimProps
[dimensionIndex
].paramBound
.getLength();
103 public boolean initilizeGeneAtPointAsCenter(double[] tempX
){
104 if (tempX
.length
!=this.getDimension()) {
107 for(int i
=0;i
<tempX
.length
;i
++) {
108 double length
= this.getMagnitudeIn(i
)/2;
109 tempX
[i
]+=RandomGenerator
.doubleRangeRandom(-1*length
, length
);
114 public void initializeGene(double[] tempX
){
115 for(int i
=0;i
<tempX
.length
;i
++) tempX
[i
] = dimProps
[i
].paramBound
.getRandomValue(); //Global.RandomGenerator.doubleRangeRandom(9.8, 10);
118 public double[] getFreshGene() {
119 double[] tempX
= new double[this.getDimension()];
120 initializeGene(tempX
);
123 public void getMappingPoint(double[] point
) {
124 for(int i
=0; i
<getDimension(); i
++) {
125 point
[i
] = dimProps
[i
].paramBound
.annulusAdjust(point
[i
]);
126 if(dimProps
[i
].isDiscrete()) {
127 point
[i
] = dimProps
[i
].getGrainedValue(point
[i
]);
132 public double[] getRealLoc(double[] imageLoc
) {
133 double[] realLoc
= new double[imageLoc
.length
];
134 for (int i
=0; i
<imageLoc
.length
; i
++) {
135 realLoc
[i
] = imageLoc
[i
];
137 annulusAdjust(realLoc
);