Generic GA instance. More...
#include <rinst.h>
Public Member Functions | |
RInst (size_t popsize, const RString &name, RDebug *debug=0) | |
virtual RCString | GetClassName (void) const |
void | SetMutationParams (size_t agemut, size_t agebestmut, size_t nbmut) |
void | SetVerify (bool verify) |
bool | GetVerify (void) const |
bool | MustOptimisation (void) const |
void | SetOptimisation (bool opti) |
cChromo * | GetBestChromosome (void) const |
void | SetSeed (int seed) |
int | GetSeed (void) const |
virtual void | Init (void) |
virtual void | AnalyzePop (void) |
virtual void | PostEvaluate (void) |
virtual void | RandomConstruct (void) |
virtual bool | StopCondition (void)=0 |
virtual void | PostRun (void) |
virtual void | DisplayInfos (void) |
virtual void | Crossover (void) |
virtual void | Mutation (void) |
virtual void | StrongMutation (void) |
virtual void | Inversion (void) |
void | Generation (void) |
virtual void | Run (void) |
virtual void | Verify (void) |
virtual void | HandlerNotFound (const RNotification ¬ification) |
long | RRand (long max) |
template<class T > | |
void | RandOrder (T *array, size_t size) |
virtual | ~RInst (void) |
Public Member Functions inherited from RObject | |
RObject (const RString &name=RString::Null) | |
int | Compare (const RObject &obj) const |
RString | GetName (void) const |
void | PostNotification (const hNotification handle) |
void | PostNotification (const RCString &name) |
void | PostNotification (const hNotification handle, T data) |
void | PostNotification (const RCString &name, T data) |
void | InsertObserver (tNotificationHandler handler, const hNotification handle, RObject *object) |
void | InsertObserver (tNotificationHandler handler, const RCString &name, RObject *object) |
void | InsertObserver (tNotificationHandler handler, const hNotification handle) |
void | InsertObserver (tNotificationHandler handler, const RCString &name) |
void | InsertObserver (tNotificationHandler handler, RObject *object) |
void | InsertObserver (tNotificationHandler handler) |
void | DeleteObserver (void) |
void | DeleteObserver (const hNotification handle, RObject *object) |
void | DeleteObserver (const RCString &name, RObject *object) |
hNotification | GetNotificationHandle (const RCString &name) const |
RCString | GetNotificationName (const hNotification handle) const |
virtual | ~RObject (void) |
Public Member Functions inherited from iRInst | |
size_t | GetPopSize (void) const |
size_t | GetGen (void) const |
size_t | GetAgeBest (void) const |
size_t | GetAgeBestPop (void) const |
virtual | ~iRInst (void) |
Static Public Member Functions | |
static int | sort_function_cChromosome (const void *a, const void *b) |
Public Attributes | |
RDebug * | Debug |
RRandom | Random |
cChromo ** | Chromosomes |
cChromo ** | Ranked |
cChromo * | BestChromosome |
cChromo * | BestInPop |
Static Public Attributes | |
static const char | instMaster =0 |
static const char | instSlave =1 |
static const char | instMultiProcess =2 |
static const char | instMultiComputers =4 |
static const char | instMultiEchos =8 |
Protected Attributes | |
cThreadData ** | thDatas |
bool | bRandomConstruct |
bool | VerifyGA |
bool | DoPostEvaluation |
bool | DoOptimisation |
Protected Attributes inherited from RObject | |
RString | Name |
Protected Attributes inherited from iRInst | |
size_t | PopSize |
size_t | Gen |
size_t | AgeBest |
size_t | AgeBestPop |
bool | Pause |
Private Attributes | |
cChromo ** | tmpChrom1 |
cChromo ** | tmpChrom2 |
size_t | NbCross |
size_t | FreqMutation |
size_t | FreqBestMutation |
size_t | NbMutations |
size_t | FreqInversion |
size_t | AgeNextMutation |
size_t | AgeNextBestMutation |
size_t | AgeNextInversion |
Additional Inherited Members | |
Protected Member Functions inherited from iRInst | |
iRInst (size_t popsize) | |
Detailed Description
template<class cInst, class cChromo, class cFit, class cThreadData>
class R::RInst< cInst, cChromo, cFit, cThreadData >
Generic GA instance.
Instance for the generic GA.
The instance emit several signals:
- PostNotification("RInst::Interact") : Possible interactions from the outside.
- PostNotification("RInst::Best",size_t) : The best chromosome has changed and the generation number is given as parameter.
- PostNotification("RInst::Generation",size_t) : A new generation has be done which number is passed as parameter.
Constructor & Destructor Documentation
Construct the instance.
- Parameters
-
popsize The size of the population. name Name of the genetic algorithm. debug Debugger.
|
virtual |
Destruct the instance.
Member Function Documentation
|
virtual |
Return the name of the class.
Reimplemented from RObject.
Reimplemented in RInstH< cInst, cChromo, cFit, cThreadData, cNode, cObj >.
void SetMutationParams | ( | size_t | agemut, |
size_t | agebestmut, | ||
size_t | nbmut | ||
) |
Set the parameters of the mutation operator.
- Parameters
-
agemut Number of generations between mutations. agebestmut Number of generations between mutations of the best chromosome. nbmut Number of mutations to do at each mutation operation.
void SetVerify | ( | bool | verify | ) |
Set if the verifications must be done.
- Parameters
-
verify Verify?
bool GetVerify | ( | void | ) | const |
See if the verifications are made by the GA.
bool MustOptimisation | ( | void | ) | const |
Look if a optimization is performed.
- Returns
- true or false.
void SetOptimisation | ( | bool | opti | ) |
Set if a optimization must be done or not. By default, the GA does optimization.
- Parameters
-
opti Perform optimization?
cChromo* GetBestChromosome | ( | void | ) | const |
- Returns
- the best chromosome.
void SetSeed | ( | int | seed | ) |
Set the seed value of the internal random number generator.
By default,the generator is always seeded with the same value, which means that the generated sequence is always the same. The GA will therefore always produce an identical result for the same problem. This is wanted most of the time (in particular for debugging purposes).
- Parameters
-
seed The seeded value.
int GetSeed | ( | void | ) | const |
Return the seed value of the internal random number generator.
|
virtual |
Initialization of the instance.
Reimplemented in RInst2D< cInst, cChromo, cFit, cThreadData, cInfo >, RInstSG< cInst, cChromo, cThreadData, cGroup, cObj >, RInstH< cInst, cChromo, cFit, cThreadData, cNode, cObj >, RInstG< cInst, cChromo, cFit, cThreadData, cGroup, cObj >, RInstG< cInst, cChromo, RFitnessNN, cThreadData, cGroup, cObj >, and RInstG< cInst, cChromo, RFitnessSG, cThreadData, cGroup, cObj >.
|
static |
This function is used to make a sort of the chromosomes based on their fitness where the best chromosomes are at the top.
- Parameters
-
a The first chromosome. b The second chromosome.
- Returns
- a-b
|
virtual |
Analyze the population to find the best chromosome of the population and to verify if the best chromosome ever calculated has to replaced. When needed, the chromosomes are evaluated.
Reimplemented in RInstG< cInst, cChromo, cFit, cThreadData, cGroup, cObj >, RInstG< cInst, cChromo, RFitnessNN, cThreadData, cGroup, cObj >, and RInstG< cInst, cChromo, RFitnessSG, cThreadData, cGroup, cObj >.
|
virtual |
Do some post evaluation treatment. It can be used to implement a multi-criteria approach like PROMETHEE to classify the chromosomes.
Reimplemented in RInstSG< cInst, cChromo, cThreadData, cGroup, cObj >, and RInstNN< cInst, cChromo, cThreadData, cGroup, cObj >.
|
virtual |
Random construction of the chromosomes.
- Returns
- The function returns true if all chromosomes are constructed.
Reimplemented in RInstG< cInst, cChromo, cFit, cThreadData, cGroup, cObj >, RInstG< cInst, cChromo, RFitnessNN, cThreadData, cGroup, cObj >, and RInstG< cInst, cChromo, RFitnessSG, cThreadData, cGroup, cObj >.
|
pure virtual |
This function determines if the GA must stop. It is called after each generation. This function is a pure one and has to be implement.
- Returns
- When the function returns true, the GA is stop.
Implemented in RInstSG< cInst, cChromo, cThreadData, cGroup, cObj >, and RInstNN< cInst, cChromo, cThreadData, cGroup, cObj >.
|
virtual |
This function can be used to do a treatment after the GA stops.
Reimplemented in RInstSG< cInst, cChromo, cThreadData, cGroup, cObj >, RInstNN< cInst, cChromo, cThreadData, cGroup, cObj >, and RInstH< cInst, cChromo, cFit, cThreadData, cNode, cObj >.
|
virtual |
This function can be used to display some information. It is called after each generation.
Reimplemented in RInstH< cInst, cChromo, cFit, cThreadData, cNode, cObj >.
|
virtual |
This function does the crossovers for a generation. Actually, the tournament strategy is implemented.
Reimplemented in RInstG< cInst, cChromo, cFit, cThreadData, cGroup, cObj >, RInstG< cInst, cChromo, RFitnessNN, cThreadData, cGroup, cObj >, and RInstG< cInst, cChromo, RFitnessSG, cThreadData, cGroup, cObj >.
|
virtual |
This function does the necessary mutations for a generation.
Reimplemented in RInstG< cInst, cChromo, cFit, cThreadData, cGroup, cObj >, RInstG< cInst, cChromo, RFitnessNN, cThreadData, cGroup, cObj >, and RInstG< cInst, cChromo, RFitnessSG, cThreadData, cGroup, cObj >.
|
virtual |
This function does the necessary mutation of the best solution ever computed.
|
virtual |
This function does the necessary inversions for a generation.
Reimplemented in RInstG< cInst, cChromo, cFit, cThreadData, cGroup, cObj >, RInstG< cInst, cChromo, RFitnessNN, cThreadData, cGroup, cObj >, and RInstG< cInst, cChromo, RFitnessSG, cThreadData, cGroup, cObj >.
void Generation | ( | void | ) |
This function does a generation.
|
virtual |
This functions runs the GA.
Implements iRInst.
|
virtual |
This functions verifies all the chromosomes after each generation.
|
virtual |
This is the handler that is called when an object does not find any handler for a send notification. By default, it prints the name of the message and the generation numbers.
- Parameters
-
notification Notification.
Reimplemented from RObject.
Reimplemented in RInstSG< cInst, cChromo, cThreadData, cGroup, cObj >, and RInstNN< cInst, cChromo, cThreadData, cGroup, cObj >.
long RRand | ( | long | max | ) |
Return a number in the interval [0,max[ using the current random generator.
- Parameters
-
max Variable used to calculate the number.
void RandOrder | ( | T * | array, |
size_t | size | ||
) |
Random the position of elements of a vector using the current random generator.
- Parameters
-
array A pointer to the array representing the vector. size The size of the vector.
Member Data Documentation
RDebug* Debug |
Pointer to a "debugger" holding information about the GA when it is running.
RRandom Random |
Random number generator
|
private |
Temporary data for internal use.
|
private |
Temporary data for internal use.
|
protected |
"Thread-dependent" data of the instance.
|
protected |
This variable is true if the random construction where done.
|
protected |
Set if the GA must verify the chromosomes during the different steps of the run.
|
protected |
Define if the post evaluation must be done.
|
protected |
Must an optimization be performed.
cChromo** Chromosomes |
The chromosomes.
cChromo** Ranked |
The chromosomes ranked by fitness.
cChromo* BestChromosome |
The best chromosome ever calculated.
cChromo* BestInPop |
The best chromosome in the population.
|
private |
Number of crossovers to be done in a generation.
|
private |
Frequency of mutation.
|
private |
Frequency of mutation of the best chromosome.
|
private |
Number of mutations to do at each mutation operation.
|
private |
Frequency of inversion.
|
private |
Number of generation left before next mutation.
|
private |
Number of generation left before mutation of the best chromosome.
|
private |
Number of generation left before next inversion.
|
static |
The instance is a master.
|
static |
The instance is a slave.
|
static |
The instance can use multi-processors.
|
static |
The instance can use slaves on other computers.
|
static |
The echo of the slaves is received by the master.