0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / math / math_PSOParticlesPool.hxx
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_PSOParticlesPool_HeaderFile
17 #define _math_PSOParticlesPool_HeaderFile
18
19 #include <NCollection_Array1.hxx>
20
21 //! Describes particle pool for using in PSO algorithm.
22 //! Indexes:
23 //! 0 <= aDimidx <= myDimensionCount - 1
24 struct PSO_Particle
25 {
26   Standard_Real* Position; // Data for pointers allocated within PSOParticlesPool instance.
27   Standard_Real* Velocity; // Not need to delete it manually.
28   Standard_Real* BestPosition;
29   Standard_Real Distance;
30   Standard_Real BestDistance;
31
32   PSO_Particle()
33   {
34     Distance = RealLast();
35     BestDistance = RealLast();
36     Position = 0;
37     Velocity = 0;
38     BestPosition = 0;
39   }
40
41   //! Compares the particles according to their distances.
42   bool operator< (const PSO_Particle& thePnt) const
43   {
44     return Distance < thePnt.Distance;
45   }
46 };
47
48 // Indexes:
49 // 1 <= aParticleIdx <= myParticlesCount
50 class math_PSOParticlesPool
51 {
52 public:
53
54   Standard_EXPORT math_PSOParticlesPool(const Standard_Integer theParticlesCount,
55                                         const Standard_Integer theDimensionCount);
56
57   Standard_EXPORT PSO_Particle* GetParticle(const Standard_Integer theIdx);
58
59   Standard_EXPORT PSO_Particle* GetBestParticle();
60
61   Standard_EXPORT PSO_Particle* GetWorstParticle();
62
63   Standard_EXPORT ~math_PSOParticlesPool();
64
65 private:
66
67   NCollection_Array1<PSO_Particle> myParticlesPool;
68   NCollection_Array1<Standard_Real> myMemory; // Stores particles vector data.
69   Standard_Integer myParticlesCount;
70   Standard_Integer myDimensionCount;
71 };
72
73 #endif