Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:15

0001 // Created on: 2014-07-18
0002 // Created by: Alexander Malyshev
0003 // Copyright (c) 2014-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _math_PSO_HeaderFile
0017 #define _math_PSO_HeaderFile
0018 
0019 #include <math_MultipleVarFunction.hxx>
0020 #include <math_Vector.hxx>
0021 
0022 class math_PSOParticlesPool;
0023 
0024 //! In this class implemented variation of Particle Swarm Optimization (PSO) method.
0025 //! A. Ismael F. Vaz, L. N. Vicente 
0026 //! "A particle swarm pattern search method for bound constrained global optimization"
0027 //!
0028 //! Algorithm description:
0029 //! Init Section:
0030 //! At start of computation a number of "particles" are placed in the search space.
0031 //! Each particle is assigned a random velocity.
0032 //!
0033 //! Computational loop:
0034 //! The particles are moved in cycle, simulating some "social" behavior, so that new position of
0035 //! a particle on each step depends not only on its velocity and previous path, but also on the
0036 //! position of the best particle in the pool and best obtained position for current particle.
0037 //! The velocity of the particles is decreased on each step, so that convergence is guaranteed.
0038 //!
0039 //! Algorithm output:
0040 //! Best point in param space (position of the best particle) and value of objective function.
0041 //!
0042 //! Pros:
0043 //! One of the fastest algorithms.
0044 //! Work over functions with a lot local extremums.
0045 //! Does not require calculation of derivatives of the functional.
0046 //!
0047 //! Cons:
0048 //! Convergence to global minimum not proved, which is a typical drawback for all stochastic algorithms.
0049 //! The result depends on random number generator.
0050 //!
0051 //! Warning: PSO is effective to walk into optimum surrounding, not to get strict optimum.
0052 //! Run local optimization from pso output point.
0053 //! Warning: In PSO used fixed seed in RNG, so results are reproducible.
0054 
0055 class math_PSO
0056 {
0057 public:
0058 
0059   /**
0060   * Constructor.
0061   *
0062   * @param theFunc defines the objective function. It should exist during all lifetime of class instance.
0063   * @param theLowBorder defines lower border of search space.
0064   * @param theUppBorder defines upper border of search space.
0065   * @param theSteps defines steps of regular grid, used for particle generation.
0066                     This parameter used to define stop condition (TerminalVelocity).
0067   * @param theNbParticles defines number of particles.
0068   * @param theNbIter defines maximum number of iterations.
0069   */
0070   Standard_EXPORT math_PSO(math_MultipleVarFunction* theFunc,
0071                            const math_Vector& theLowBorder,
0072                            const math_Vector& theUppBorder,
0073                            const math_Vector& theSteps,
0074                            const Standard_Integer theNbParticles = 32,
0075                            const Standard_Integer theNbIter = 100);
0076 
0077   //! Perform computations, particles array is constructed inside of this function.
0078   Standard_EXPORT void Perform(const math_Vector& theSteps,
0079                                Standard_Real& theValue,
0080                                math_Vector& theOutPnt,
0081                                const Standard_Integer theNbIter = 100);
0082 
0083   //! Perform computations with given particles array.
0084   Standard_EXPORT void Perform(math_PSOParticlesPool& theParticles,
0085                                Standard_Integer theNbParticles,
0086                                Standard_Real& theValue,
0087                                math_Vector& theOutPnt,
0088                                const Standard_Integer theNbIter = 100);
0089 
0090 private:
0091 
0092   void performPSOWithGivenParticles(math_PSOParticlesPool& theParticles,
0093                                     Standard_Integer theNbParticles,
0094                                     Standard_Real& theValue,
0095                                     math_Vector& theOutPnt,
0096                                     const Standard_Integer theNbIter = 100);
0097 
0098   math_MultipleVarFunction *myFunc;
0099   math_Vector myLowBorder; // Lower border.
0100   math_Vector myUppBorder; // Upper border.
0101   math_Vector mySteps; // steps used in PSO algorithm.
0102   Standard_Integer myN; // Dimension count.
0103   Standard_Integer myNbParticles; // Particles number.
0104   Standard_Integer myNbIter;
0105 };
0106 
0107 #endif