📄 gaobserving.h
字号:
#ifndef __GA_OBSERVING_H__
#define __GA_OBSERVING_H__
#include <list>
#include "..\CallConvention.h"
#include "..\ExportImport.h"
#include "..\Chromosome\GaChromosome.h"
#include "..\Common\GaStatistics.h"
#include "..\Threading\GaThreading.h"
namespace Algorithm
{
enum GaAlgorithmState;
class GaAlgorithm;
}
using namespace std;
using namespace Common;
using namespace Chromosome;
using namespace Algorithm;
namespace Observing
{
// Interface for observers of an genetic algorithm
class GaObserver
{
public:
// Virtual destructor
virtual ~GaObserver() { }
// Notifies the observer that new statistical information is available
virtual void GACALL StatisticUpdate(const GaStatistics& statistics,
const GaAlgorithm& algorithm)=0;
// Notifies observer that new best chromosome has found
virtual void GACALL NewBestChromosome(const GaChromosome& newChromosome,
const GaAlgorithm& algorithm)=0;
// Notifies observer that state of evolution (problem sloving) has changed.
virtual void GACALL EvolutionStateChanged(GaAlgorithmState newState,
const GaAlgorithm& algorithm)=0;
};// END INTERFACE DEFINITION GaObserver
// Adapter calss for GaObserver interface
class GaObserverAdapter : public GaObserver
{
public:
// Notifies the observer that new statistical information is available
virtual void GACALL StatisticUpdate(const GaStatistics& statistics,
const GaAlgorithm& algorithm) {};
// Notifies observer that new best chromosome has found
virtual void GACALL NewBestChromosome(const GaChromosome& newChromosome,
const GaAlgorithm& algorithm) {};
// Notifies observer that state of evolution (problem sloving) has changed.
virtual void GACALL EvolutionStateChanged(GaAlgorithmState newState,
const GaAlgorithm& algorithm) {};
};// END CLASS DEFINITION GaObserverAdapter
// Manages list of subscribed observer
class GaObserversList : public GaObserver
{
DEFINE_SYNC_CLASS
protected:
typedef list<GaObserver*> GaObserversListType;
// List of subscribed observers
GaObserversListType _observers;
public:
// Notifies the observer that new statistical information is available
DLL_EXPORT
virtual void GACALL StatisticUpdate(const GaStatistics& statistics,
const GaAlgorithm& algorithm);
// Notifies observer that new best chromosome has found
DLL_EXPORT
virtual void GACALL NewBestChromosome(const GaChromosome& newChromosome,
const GaAlgorithm& algorithm);
// Notifies observer that state of evolution (problem sloving) has changed.
DLL_EXPORT
virtual void GACALL EvolutionStateChanged(GaAlgorithmState newState,
const GaAlgorithm& algorithm);
// Subscribes observer
DLL_EXPORT
GaObserversList& GACALL operator +=(GaObserver& observer);
// Unsubscribes observer
DLL_EXPORT
GaObserversList& GACALL operator -=(GaObserver& observer);
// Returns the number of subscribed observers
DLL_EXPORT
int GACALL GetObserverCount() const;
};// END CLASS DEFINITION GaObserversList
} // Observing
#endif //__GA_OBSERVING_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -