fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / nlpsolver / ThirdParty / EvolutionarySolver / src / net / adaptivebox / deps / behavior / PSGTBehavior.java
blobb4ae0017eb69f19c121dee7de755eef5842ed9ee
1 /**
2 * Description: The description of particle swarm (PS) Generate-and-test Behavior.
4 #Supported parameters:
5 NAME VALUE_type Range DefaultV Description
6 c1 real [0, 2] 1.494 PSAgent: learning factor for pbest
7 c2 real [0, 2] 1.494 PSAgent: learning factor for gbest
8 w real [0, 1] 0.729 PSAgent: inertia weight
9 CL real [0, 0.1] 0 PSAgent: chaos factor
10 //Other choices for c1, c2, w, and CL: (2, 2, 0.4, 0.001)
12 * @ Author Create/Modi Note
13 * Xiaofeng Xie May 11, 2004
14 * Xiaofeng Xie Jul 01, 2008
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * Please acknowledge the author(s) if you use this code in any way.
28 * @version 1.0
29 * @Since MAOS1.0
31 * @References:
32 * [1] Kennedy J, Eberhart R C. Particle swarm optimization. IEEE Int. Conf. on
33 * Neural Networks, Perth, Australia, 1995: 1942-1948
34 * @ For original particle swarm idea
35 * [2] Shi Y H, Eberhart R C. A Modified Particle Swarm Optimizer. IEEE Inter. Conf.
36 * on Evolutionary Computation, Anchorage, Alaska, 1998: 69-73
37 * @ For the inertia weight: adjust the trade-off between exploitation & exploration
38 * [3] Clerc M, Kennedy J. The particle swarm - explosion, stability, and
39 * convergence in a multidimensional complex space. IEEE Trans. on Evolutionary
40 * Computation. 2002, 6 (1): 58-73
41 * @ Constriction factor: ensures the convergence
42 * [4] Xie X F, Zhang W J, Yang Z L. A dissipative particle swarm optimization.
43 * Congress on Evolutionary Computation, Hawaii, USA, 2002: 1456-1461
44 * @ The CL parameter
45 * [5] Xie X F, Zhang W J, Bi D C. Optimizing semiconductor devices by self-
46 * organizing particle swarm. Congress on Evolutionary Computation, Oregon, USA,
47 * 2004: 2017-2022
48 * @ Further experimental analysis on the convergence of PSO
49 * [6] X F Xie, W J Zhang. SWAF: swarm algorithm framework for numerical
50 * optimization. Genetic and Evolutionary Computation Conference (GECCO),
51 * Seattle, WA, USA, 2004: 238-250
52 * -> a generate-and-test behavior
56 package net.adaptivebox.deps.behavior;
58 import net.adaptivebox.goodness.*;
59 import net.adaptivebox.knowledge.*;
60 import net.adaptivebox.problem.*;
61 import net.adaptivebox.space.*;
63 public class PSGTBehavior extends AbsGTBehavior {
64 // Two normally choices for (c1, c2, weight), i.e., (2, 2, 0.4), or (1.494, 1.494, 0.729)
65 // The first is used in dissipative PSO (cf. [4]) as CL>0, and the second is achieved by using
66 // constriction factors (cf. [3])
67 public double c1=2;
68 public double c2=2;
69 public double weight = 0.4; //inertia weight
71 public double CL=0; //See ref[4], normally be 0.001~0.005
73 //the own memory: store the point that generated in old learning cycle
74 protected BasicPoint pold_t;
75 //the own memory: store the point that generated in last learning cycle
76 protected BasicPoint pcurrent_t;
77 //the own memory: store the personal best point
78 protected SearchPoint pbest_t;
80 public void setMemPoints(SearchPoint pbest, BasicPoint pcurrent, BasicPoint pold) {
81 pcurrent_t = pcurrent;
82 pbest_t = pbest;
83 pold_t = pold;
86 public void generateBehavior(SearchPoint trailPoint, ProblemEncoder problemEncoder) {
87 SearchPoint gbest_t = socialLib.getGbest();
88 DesignSpace designSpace = problemEncoder.getDesignSpace();
89 int DIMENSION = designSpace.getDimension();
90 double deltaxb, deltaxbm;
91 for (int b=0;b<DIMENSION;b++) {
92 if (Math.random()<CL) {
93 designSpace.mutationAt(trailPoint.getLocation(), b);
94 } else {
95 deltaxb = weight*(pcurrent_t.getLocation()[b]-pold_t.getLocation()[b])
96 + c1*Math.random()*(pbest_t.getLocation()[b]-pcurrent_t.getLocation()[b])
97 + c2*Math.random()*(gbest_t.getLocation()[b]-pcurrent_t.getLocation()[b]);
98 //limitation for delta_x
99 deltaxbm = 0.5*designSpace.getMagnitudeIn(b);
100 if(deltaxb<-deltaxbm) {
101 deltaxb = -deltaxbm;
102 } else if (deltaxb>deltaxbm) {
103 deltaxb = deltaxbm;
105 trailPoint.getLocation()[b] = pcurrent_t.getLocation()[b]+deltaxb;
110 public void testBehavior(SearchPoint trailPoint, IGoodnessCompareEngine qualityComparator) {
111 Library.replace(qualityComparator, trailPoint, pbest_t);
112 pold_t.importLocation(pcurrent_t);
113 pcurrent_t.importLocation(trailPoint);