0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / math / math_PSOParticlesPool.cxx
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 #include <math_PSOParticlesPool.hxx>
17 #include <algorithm>
18
19
20 //=======================================================================
21 //function : math_PSOParticlesPool
22 //purpose  : Constructor
23 //=======================================================================
24 math_PSOParticlesPool::math_PSOParticlesPool(const Standard_Integer theParticlesCount,
25                                              const Standard_Integer theDimensionCount)
26 : myParticlesPool(1, theParticlesCount),
27   myMemory(0, theParticlesCount * (theDimensionCount  // Position
28                                  + theDimensionCount  // Velocity
29                                  + theDimensionCount) // BestPosition
30                                  - 1) 
31 {
32   myParticlesCount = theParticlesCount;
33   myDimensionCount = theDimensionCount;
34
35   // Pointers adjusting.
36   Standard_Integer aParIdx, aShiftIdx;
37   for(aParIdx = 1; aParIdx <= myParticlesCount; ++aParIdx)
38   {
39     aShiftIdx = (theDimensionCount * 3) * (aParIdx - 1);
40     myParticlesPool(aParIdx).Position     = &myMemory(aShiftIdx);
41     myParticlesPool(aParIdx).Velocity     = &myMemory(aShiftIdx + theDimensionCount);
42     myParticlesPool(aParIdx).BestPosition = &myMemory(aShiftIdx + 2 * theDimensionCount);
43   }
44 }
45
46 //=======================================================================
47 //function : ~math_PSOParticlesPool
48 //purpose  : Destructor
49 //=======================================================================
50 math_PSOParticlesPool::~math_PSOParticlesPool()
51 {
52 }
53
54 //=======================================================================
55 //function : GetParticle
56 //purpose  : 
57 //=======================================================================
58 PSO_Particle* math_PSOParticlesPool::GetParticle(const Standard_Integer theIdx)
59 {
60   return &myParticlesPool(theIdx);
61 }
62
63 //=======================================================================
64 //function : GetBestParticle
65 //purpose  : 
66 //=======================================================================
67 PSO_Particle* math_PSOParticlesPool::GetBestParticle()
68 {
69   return &*std::min_element(myParticlesPool.begin(), myParticlesPool.end());
70 }
71
72 //=======================================================================
73 //function : GetWorstParticle
74 //purpose  : 
75 //=======================================================================
76 PSO_Particle* math_PSOParticlesPool::GetWorstParticle()
77 {
78   return &*std::max_element(myParticlesPool.begin(), myParticlesPool.end());
79 }