LibCudaOptimize  1.0
PSO_Optimizer.h
Go to the documentation of this file.
00001 //*************************************************************************//
00002 //                                                                         //
00003 //  LibCudaOptimize                                                        //
00004 //  Copyright (C) 2012 Ibislab, University of Parma                        //
00005 //  Authors: Youssef S.G. Nashed, Roberto Ugolotti                         //
00006 //                                                                         //
00007 //  You should have received a copy of the GNU General Public License      //
00008 //  along with this program.  If not, see <http://www.gnu.org/licenses/>   //
00009 //                                                                         //
00010 //*************************************************************************//
00011 
00012 #ifndef PSO_Optimizer_H
00013 #define PSO_Optimizer_H
00014 
00015 #include "IOptimizer.h"
00016 #include "IOptimizer.cuh"
00017 
00020 /*open the namespace
00021   this code should be after all the #include lines and before the first line of the code in each file.
00022   by Hamid. 23/07/2012*/
00023 #ifdef LIBCUDAOPTIMIZE_NAMESPACE
00024 OPEN_NAMESPACE
00025 #endif
00026 
00028 typedef enum 
00029 {
00030   LBEST,                
00031   GBEST,                
00032   STAR,                 
00033   RANDOM,               
00034   VON_NEUMANN   
00035 } TOPOLOGY;
00036 
00040 class PSO_Optimizer :
00041         public virtual IOptimizer
00042 {
00043 protected:
00044 
00045 #ifndef PRIVATE_DOXYGEN
00046 
00047         SolutionSet m_bestSolutionSet;
00049         float* m_dVelocities;
00050 
00051         uint32_t* m_dLocalBestIDs;
00052         uint32_t* m_dUpdate;
00053 
00054         //PSO parameters
00056         float m_W;
00058         float m_C1;
00060         float m_C2;
00061         
00062         TOPOLOGY m_Topology;
00063 #endif //private doxygen
00064         virtual void initSolutions(dim3,dim3);
00065         virtual void fitnessEvaluation(dim3,dim3,bool first=false);
00066         virtual void step(dim3,dim3);
00067         virtual void update(dim3,dim3,bool first=false);
00068         virtual void findBest();
00069 
00070 public:
00072         PSO_Optimizer(EvalFuncPtr fPtr=NULL, unsigned int dn=PROBLEM_DIMENSIONS, unsigned int sn=NUM_SETS, unsigned int pn=NUM_SOLUTIONS);
00073         virtual ~PSO_Optimizer();
00074         
00075         virtual bool init();
00076         virtual void free();
00077 
00079         void setInertia(float w)                                {m_W = w;}
00081         void setC1(float c1)                                    {m_C1 = c1;}
00083         void setC2(float c2)                                    {m_C2 = c2;}
00091         void setTopology (TOPOLOGY topology)    {m_Topology=topology;}
00092 
00093         float* getBestSolution()                                                        {return m_bestSolutionSet.getHostBestPositions();}
00094         float* getBestSolution(unsigned int sid)                        {checkSetNumber(sid); return m_bestSolutionSet.getHostBestPositions(sid);}
00095         float* getBestFitnesses()                                                       {return m_bestSolutionSet.getHostBestFitnesses();}
00096         float  getBestFitness(unsigned int sid)                         {checkSetNumber(sid); return m_bestSolutionSet.getHostBestFitnesses(sid);}
00097 
00098 };
00099 
00100 /*close the namespace
00101   this code should be at the end of the file
00102   by Hamid. 23/07/2012*/
00103 #ifdef LIBCUDAOPTIMIZE_NAMESPACE
00104 CLOSE_NAMESPACE
00105 #endif
00106 
00107 #endif
 All Classes Files Functions Variables Enumerations Enumerator Defines