Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 09:17:48

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_PSOParticlesPool_HeaderFile
0017 #define _math_PSOParticlesPool_HeaderFile
0018 
0019 #include <NCollection_Array1.hxx>
0020 
0021 //! Describes particle pool for using in PSO algorithm.
0022 //! Indexes:
0023 //! 0 <= aDimidx <= myDimensionCount - 1
0024 struct PSO_Particle
0025 {
0026   double* Position; // Data for pointers allocated within PSOParticlesPool instance.
0027   double* Velocity; // Not need to delete it manually.
0028   double* BestPosition;
0029   double  Distance;
0030   double  BestDistance;
0031 
0032   PSO_Particle()
0033   {
0034     Distance     = RealLast();
0035     BestDistance = RealLast();
0036     Position     = nullptr;
0037     Velocity     = nullptr;
0038     BestPosition = nullptr;
0039   }
0040 
0041   //! Compares the particles according to their distances.
0042   bool operator<(const PSO_Particle& thePnt) const { return Distance < thePnt.Distance; }
0043 };
0044 
0045 // Indexes:
0046 // 1 <= aParticleIdx <= myParticlesCount
0047 class math_PSOParticlesPool
0048 {
0049 public:
0050   Standard_EXPORT math_PSOParticlesPool(const int theParticlesCount, const int theDimensionCount);
0051 
0052   Standard_EXPORT PSO_Particle* GetParticle(const int theIdx);
0053 
0054   Standard_EXPORT PSO_Particle* GetBestParticle();
0055 
0056   Standard_EXPORT PSO_Particle* GetWorstParticle();
0057 
0058   Standard_EXPORT ~math_PSOParticlesPool();
0059 
0060 private:
0061   NCollection_Array1<PSO_Particle> myParticlesPool;
0062   NCollection_Array1<double>       myMemory; // Stores particles vector data.
0063   int                              myParticlesCount;
0064   int                              myDimensionCount;
0065 };
0066 
0067 #endif