1d33d22b |
1 | // Created on: 2014-07-18 |
2 | // Created by: Alexander Malyshev |
3 | // Copyright (c) 2014-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _math_PSO_HeaderFile |
17 | #define _math_PSO_HeaderFile |
18 | |
19 | #include <math_BullardGenerator.hxx> |
20 | #include <math_MultipleVarFunction.hxx> |
21 | #include <math_Vector.hxx> |
22 | |
23 | class math_PSOParticlesPool; |
24 | |
25 | //! In this class implemented variation of Particle Swarm Optimization (PSO) method. |
26 | //! A. Ismael F. Vaz, L. N. Vicente |
27 | //! "A particle swarm pattern search method for bound constrained global optimization" |
55b05039 |
28 | //! |
29 | //! Algorithm description: |
30 | //! Init Section: |
17470159 |
31 | //! At start of computation a number of "particles" are placed in the search space. |
55b05039 |
32 | //! Each particle is assigned a random velocity. |
33 | //! |
34 | //! Computational loop: |
17470159 |
35 | //! The particles are moved in cycle, simulating some "social" behavior, so that new position of |
55b05039 |
36 | //! a particle on each step depends not only on its velocity and previous path, but also on the |
37 | //! position of the best particle in the pool and best obtained position for current particle. |
38 | //! The velocity of the particles is decreased on each step, so that convergence is guaranteed. |
39 | //! |
40 | //! Algorithm output: |
41 | //! Best point in param space (position of the best particle) and value of objective function. |
42 | //! |
43 | //! Pros: |
44 | //! One of the fastest algorithms. |
45 | //! Work over functions with a lot local extremums. |
46 | //! Does not require calculation of derivatives of the functional. |
47 | //! |
48 | //! Cons: |
49 | //! Convergence to global minimum not proved, which is a typical drawback for all stochastic algorithms. |
50 | //! The result depends on random number generator. |
51 | //! |
52 | //! Warning: PSO is effective to walk into optimum surrounding, not to get strict optimum. |
53 | //! Run local optimization from pso output point. |
54 | //! Warning: In PSO used fixed seed in RNG, so results are reproducible. |
17470159 |
55 | |
1d33d22b |
56 | class math_PSO |
57 | { |
58 | public: |
59 | |
60 | /** |
61 | * Constructor. |
62 | * |
63 | * @param theFunc defines the objective function. It should exist during all lifetime of class instance. |
64 | * @param theLowBorder defines lower border of search space. |
65 | * @param theUppBorder defines upper border of search space. |
66 | * @param theSteps defines steps of regular grid, used for particle generation. |
67 | This parameter used to define stop condition (TerminalVelocity). |
68 | * @param theNbParticles defines number of particles. |
69 | * @param theNbIter defines maximum number of iterations. |
70 | */ |
71 | Standard_EXPORT math_PSO(math_MultipleVarFunction* theFunc, |
72 | const math_Vector& theLowBorder, |
73 | const math_Vector& theUppBorder, |
74 | const math_Vector& theSteps, |
75 | const Standard_Integer theNbParticles = 32, |
76 | const Standard_Integer theNbIter = 100); |
77 | |
78 | //! Perform computations, particles array is constructed inside of this function. |
79 | Standard_EXPORT void Perform(const math_Vector& theSteps, |
80 | Standard_Real& theValue, |
81 | math_Vector& theOutPnt, |
82 | const Standard_Integer theNbIter = 100); |
83 | |
84 | //! Perform computations with given particles array. |
85 | Standard_EXPORT void Perform(math_PSOParticlesPool& theParticles, |
86 | Standard_Integer theNbParticles, |
87 | Standard_Real& theValue, |
88 | math_Vector& theOutPnt, |
89 | const Standard_Integer theNbIter = 100); |
90 | |
91 | private: |
92 | |
93 | void performPSOWithGivenParticles(math_PSOParticlesPool& theParticles, |
94 | Standard_Integer theNbParticles, |
95 | Standard_Real& theValue, |
96 | math_Vector& theOutPnt, |
97 | const Standard_Integer theNbIter = 100); |
98 | |
99 | math_MultipleVarFunction *myFunc; |
100 | math_Vector myLowBorder; // Lower border. |
101 | math_Vector myUppBorder; // Upper border. |
102 | math_Vector mySteps; // steps used in PSO algorithm. |
103 | Standard_Integer myN; // Dimension count. |
104 | Standard_Integer myNbParticles; // Particles number. |
105 | Standard_Integer myNbIter; |
106 | }; |
107 | |
108 | #endif |