2 * Description: The description of differential evolution Generate-and-Test Behavior.
5 NAME VALUE_type Range DefaultV Description
6 FACTOR real (0, 1.2] 0.5 DEAgent: scale constant
7 CR real [0, 1] 0.9 DEAgent: crossover constant
8 //Other choices for FACTOR and CR: (0.5, 0.1)
11 * Author Create/Modi Note
12 * Xiaofeng Xie May 11, 2004
13 * Xiaofeng Xie Jul 01, 2008
19 * [1] Storn R, Price K. Differential evolution - a simple and efficient
20 * heuristic for global optimization over continuous spaces. Journal of
21 * Global Optimization, 1997, 11: 341-359
22 * The original differential evolution idea
23 * [2] X F Xie, W J Zhang. SWAF: swarm algorithm framework for numerical
24 * optimization. Genetic and Evolutionary Computation Conference (GECCO),
25 * Seattle, WA, USA, 2004: 238-250
26 * -> a generate-and-test behavior
29 package net
.adaptivebox
.deps
.behavior
;
31 import net
.adaptivebox
.global
.RandomGenerator
;
32 import net
.adaptivebox
.goodness
.IGoodnessCompareEngine
;
33 import net
.adaptivebox
.knowledge
.Library
;
34 import net
.adaptivebox
.knowledge
.SearchPoint
;
35 import net
.adaptivebox
.problem
.ProblemEncoder
;
36 import net
.adaptivebox
.space
.BasicPoint
;
38 public class DEGTBehavior
extends AbsGTBehavior
{
39 //Number of differential vectors, normally be 1 or 2
40 private static final int DVNum
= 2;
42 //scale constant: (0, 1.2], normally be 0.5
43 public double MIN_FACTOR
= 0.5;
45 //scale constant: (0, 1.2], normally be 0.5
46 public double MAX_FACTOR
= 0.5;
48 //crossover constant: [0, 1], normally be 0.1 or 0.9
49 public double CR
= 0.9;
52 public void setMemPoints(SearchPoint pbest
, BasicPoint pcurrent
, BasicPoint pold
) {
57 * Crossover and mutation for a single vector element done in a single step.
59 * @param index Index of the trial vector element to be changed.
60 * @param trialVector Trial vector reference.
61 * @param globalVector Global best found vector reference.
62 * @param differenceVectors List of vectors used for difference delta
65 private void crossoverAndMutation(int index
, double trialVector
[], double globalVector
[],
66 BasicPoint differenceVectors
[]) {
69 for (int i
= 0; i
< differenceVectors
.length
; i
++) {
70 delta
+= (i
% 2 == 0 ?
+1D
: -1D
) * differenceVectors
[i
].getLocation()[index
];
73 trialVector
[index
] = globalVector
[index
] + RandomGenerator
.doubleRangeRandom(MIN_FACTOR
, MAX_FACTOR
) * delta
;
77 public void generateBehavior(SearchPoint trailPoint
, ProblemEncoder problemEncoder
) {
78 BasicPoint
[] referPoints
= getReferPoints();
79 int DIMENSION
= problemEncoder
.getDesignSpace().getDimension();
80 int guaranteeIndex
= RandomGenerator
.intRangeRandom(0, DIMENSION
- 1);
82 double[] trailVector
= trailPoint
.getLocation();
83 double[] locaclVector
= pbest_t
.getLocation();
84 double[] globalVector
= socialLib
.getGbest().getLocation();
86 /* Handle first part of the trial vector. */
87 for (int index
= 0; index
< guaranteeIndex
; index
++) {
88 if (CR
<= RandomGenerator
.doubleZeroOneRandom()) {
89 trailVector
[index
] = locaclVector
[index
];
93 crossoverAndMutation(index
, trailVector
, globalVector
, referPoints
);
96 /* Guarantee for at least one change in the trial vector. */
97 crossoverAndMutation(guaranteeIndex
, trailVector
, globalVector
, referPoints
);
99 /* Handle second part of the trial vector. */
100 for (int index
= guaranteeIndex
+ 1; index
< DIMENSION
; index
++) {
101 if (CR
<= RandomGenerator
.doubleZeroOneRandom()) {
102 trailVector
[index
] = locaclVector
[index
];
106 crossoverAndMutation(index
, trailVector
, globalVector
, referPoints
);
111 public void testBehavior(SearchPoint trailPoint
, IGoodnessCompareEngine qualityComparator
) {
112 Library
.replace(qualityComparator
, trailPoint
, pbest_t
);
115 private SearchPoint
[] getReferPoints() {
116 SearchPoint
[] referPoints
= new SearchPoint
[DVNum
* 2];
117 for (int i
= 0; i
< referPoints
.length
; i
++) {
118 referPoints
[i
] = socialLib
.getRandomPoint();