0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / math / math_PSO.hxx
CommitLineData
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
1d33d22b 19#include <math_MultipleVarFunction.hxx>
20#include <math_Vector.hxx>
21
22class math_PSOParticlesPool;
23
24//! In this class implemented variation of Particle Swarm Optimization (PSO) method.
25//! A. Ismael F. Vaz, L. N. Vicente
26//! "A particle swarm pattern search method for bound constrained global optimization"
55b05039 27//!
28//! Algorithm description:
29//! Init Section:
17470159 30//! At start of computation a number of "particles" are placed in the search space.
55b05039 31//! Each particle is assigned a random velocity.
32//!
33//! Computational loop:
17470159 34//! The particles are moved in cycle, simulating some "social" behavior, so that new position of
55b05039 35//! a particle on each step depends not only on its velocity and previous path, but also on the
36//! position of the best particle in the pool and best obtained position for current particle.
37//! The velocity of the particles is decreased on each step, so that convergence is guaranteed.
38//!
39//! Algorithm output:
40//! Best point in param space (position of the best particle) and value of objective function.
41//!
42//! Pros:
43//! One of the fastest algorithms.
44//! Work over functions with a lot local extremums.
45//! Does not require calculation of derivatives of the functional.
46//!
47//! Cons:
48//! Convergence to global minimum not proved, which is a typical drawback for all stochastic algorithms.
49//! The result depends on random number generator.
50//!
51//! Warning: PSO is effective to walk into optimum surrounding, not to get strict optimum.
52//! Run local optimization from pso output point.
53//! Warning: In PSO used fixed seed in RNG, so results are reproducible.
17470159 54
1d33d22b 55class math_PSO
56{
57public:
58
59 /**
60 * Constructor.
61 *
62 * @param theFunc defines the objective function. It should exist during all lifetime of class instance.
63 * @param theLowBorder defines lower border of search space.
64 * @param theUppBorder defines upper border of search space.
65 * @param theSteps defines steps of regular grid, used for particle generation.
66 This parameter used to define stop condition (TerminalVelocity).
67 * @param theNbParticles defines number of particles.
68 * @param theNbIter defines maximum number of iterations.
69 */
70 Standard_EXPORT math_PSO(math_MultipleVarFunction* theFunc,
71 const math_Vector& theLowBorder,
72 const math_Vector& theUppBorder,
73 const math_Vector& theSteps,
74 const Standard_Integer theNbParticles = 32,
75 const Standard_Integer theNbIter = 100);
76
77 //! Perform computations, particles array is constructed inside of this function.
78 Standard_EXPORT void Perform(const math_Vector& theSteps,
79 Standard_Real& theValue,
80 math_Vector& theOutPnt,
81 const Standard_Integer theNbIter = 100);
82
83 //! Perform computations with given particles array.
84 Standard_EXPORT void Perform(math_PSOParticlesPool& theParticles,
85 Standard_Integer theNbParticles,
86 Standard_Real& theValue,
87 math_Vector& theOutPnt,
88 const Standard_Integer theNbIter = 100);
89
90private:
91
92 void performPSOWithGivenParticles(math_PSOParticlesPool& theParticles,
93 Standard_Integer theNbParticles,
94 Standard_Real& theValue,
95 math_Vector& theOutPnt,
96 const Standard_Integer theNbIter = 100);
97
98 math_MultipleVarFunction *myFunc;
99 math_Vector myLowBorder; // Lower border.
100 math_Vector myUppBorder; // Upper border.
101 math_Vector mySteps; // steps used in PSO algorithm.
102 Standard_Integer myN; // Dimension count.
103 Standard_Integer myNbParticles; // Particles number.
104 Standard_Integer myNbIter;
105};
106
107#endif