The Fib multimedia system
Fib is a system for storing multimedia data (like images or films).
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
enviroment::cEnviroment Class Reference

#include <cEnviroment.h>

Inheritance diagram for enviroment::cEnviroment:
Collaboration diagram for enviroment::cEnviroment:

List of all members.

Public Member Functions

virtual ~cEnviroment ()
bool start ()
virtual bool run ()
virtual bool stop ()
virtual bool isRunning () const
unsigned long long getAlgorithmIdentifier ()
list< const cIndividualInfo * > getIndividualInfos (short iLive=0) const
const cIndividualInfogetIndividualInfo (const cIndividualIdentifier &identifier) const
const cIndividualInfogetBestIndividualInfo (unsigned long lNumber=1, short iLive=1) const
cIndividualgetIndividual () const
cIndividualgetIndividual (const cIndividualIdentifier &identifier) const
cIndividualgetBestIndividual (unsigned long lNumber=1) const
bool insertIndividual (const cIndividual *pInIndividual, const cOperation *pProducerOperation=NULL)
unsigned long getNumberOfIndividuals (short iLive=1)
unsigned int getNumberOfRunningOperations ()
unsigned long getNumberOfCalledOperations ()
double getCpuRunTime () const
time_t getLastStartTime () const
time_t getFirstStartTime () const
bool registerIndividualListener (clNewIndividualListener *individualListener)
bool unregisterIndividualListener (clNewIndividualListener *individualListener)
void operationStatusChange (cOperation *pOperation, bool isRunning)

Static Public Member Functions

static cEnviromentgetInstance ()
static bool setParameter (const cInitEnviroment *pInInit, const cObjectFitnessAlgorithm *pInObjectFitnessAlgorithm, const cEndConditionCheck *pInEndCondition=NULL, const cIndividualSelection *pInIndividualSelection=NULL, const cMaximumReached *pInMaximumIndividuals=NULL, const cSelectIndividualToDelete *pInSelectIndividualToDelete=NULL, const cOperatorFitnessAlgorithm *pInOperationFitnessAlgorithmus=NULL, const cChoosOperator *pInChoosOperator=NULL, const cResourceCheck *pInResourceCheck=NULL)
static const
cObjectFitnessAlgorithm
getFitnessAlgorithm ()
static const cInitEnviromentgetInitEnviroment ()
static const cEndConditionCheckgetEndConditionCheck ()
static const cIndividualSelectiongetIndividualSelection ()
static const cMaximumReachedgetMaximumReached ()
static const
cSelectIndividualToDelete
getSelectIndividualToDelete ()
static cOperatorFitnessAlgorithmgetOperatorFitnessAlgorithm ()
static const cChoosOperatorgetChoosOperator ()
static const cResourceCheckgetResourceCheck ()

Public Attributes

const std::string OPERATION_DOMAIN

Protected Member Functions

 cEnviroment ()
bool removeIndividual (const cIndividualIdentifier pInIndividual)

Static Protected Attributes

static long long lAlgorithmIdentifier
static cEnviromentpEnviroment
static pthread_t * pThreadEnviroment
static map
< cIndividualIdentifier,
cIndividualInformation > 
mapLivingIndividuals
static list< const
cIndividualInfo * > 
liLivingIndividualInfos
static bool bLiLivingIndividualInfosSorted
static map
< cIndividualIdentifier,
cIndividualInformation > 
mapDeadIndividuals
static list< const
cIndividualInfo * > 
liDeadIndividualInfos
static bool bLiDeadIndividualInfosSorted
static map< cOperation
*, cOperationInformation > 
mapRunningOperations
static list< cOperation * > liOperationsToDelete
static unsigned long long lNumberOfCalledOperations
static double dCpuRunTime
static time_t tmLastCpuRunTime
static time_t tmLastStartTime
static time_t tmFirstStartTime
static bool bParameterSet
static bool bIsRunning
static bool bStopFlag
static cInitEnviromentpInitEnviroment
static cObjectFitnessAlgorithmpObjectFitnessAlgorithm
static cEndConditionCheckpEndCondition
static cIndividualSelectionpIndividualSelection
static cMaximumReachedpMaximumIndividuals
static cSelectIndividualToDeletepSelectIndividualToDelete
static cOperatorFitnessAlgorithmpOperationFitnessAlgorithmus
static cChoosOperatorpChoosOperator
static cResourceCheckpResourceCheck
static set
< clNewIndividualListener * > 
setIndividualListener

Private Member Functions

void deleteNotRunningOperations ()

Static Private Member Functions

static void * stopOperation (void *inputArg)
static void * runTread (void *inputArg)
static void shortSleep ()

Detailed Description

Definition at line 118 of file cEnviroment.h.


Constructor & Destructor Documentation

enviroment::cEnviroment::cEnviroment ( )
protected

standardconstructor This is called in the getInstance() method.

virtual enviroment::cEnviroment::~cEnviroment ( )
virtual

destructor


Member Function Documentation

void enviroment::cEnviroment::deleteNotRunningOperations ( )
private

This method will delete all operations which are done (respectively stored in the

See also:
liOperationsToDelete ).
unsigned long long enviroment::cEnviroment::getAlgorithmIdentifier ( )
See also:
lAlgorithmIdentifier
Returns:
The identifier for the enviroment/ genetic algorithm.
cIndividual* enviroment::cEnviroment::getBestIndividual ( unsigned long  lNumber = 1) const

This method returns the lNumber'th best individual. Beware: You have to care for, that the returned individual gets deleted after usage.

Parameters:
lNumberthe number for the individual to return
Returns:
a pointer to the lNumber'th best individual or NULL, if non such exists
const cIndividualInfo* enviroment::cEnviroment::getBestIndividualInfo ( unsigned long  lNumber = 1,
short  iLive = 1 
) const

This method returns the information for the lNumber'th best individual.

Parameters:
lNumberthe number of the individual to return
iLivea number which indicate of which kind the individual should be, from which the information is to be returned; possible values: 0 : search the informations of all individuals in the enviroment, regardless if they are living or not 1 : search return the information just of living individuals -1: search return the information just of dead individuals else: an empty list is to be returned; reserved for future use, please don't use this
Returns:
a pointer to the information for the lNumber'th best individual or NULL, if non such exists
static const cChoosOperator* enviroment::cEnviroment::getChoosOperator ( )
static
Returns:
a pointer to the object for selecting a good operator or NULL, if non such exists;
See also:
pChoosOperator
double enviroment::cEnviroment::getCpuRunTime ( ) const
Returns:
the time in secounds the enviroment was running;
See also:
isRunning() gives back true for this time
static const cEndConditionCheck* enviroment::cEnviroment::getEndConditionCheck ( )
static
Returns:
a pointer to the object for checking the endcondition of the enviroment or NULL, if non such exists;
See also:
pEndCondition
time_t enviroment::cEnviroment::getFirstStartTime ( ) const
Returns:
the time the
See also:
start() method was called the first time for this enviroment or 0, if non such exists
static const cObjectFitnessAlgorithm* enviroment::cEnviroment::getFitnessAlgorithm ( )
static
Returns:
A pointer to the object for evaluing the fitness of individuals (respectively the objects they represents).
See also:
pObjectFitnessAlgorithm
cIndividual* enviroment::cEnviroment::getIndividual ( ) const

This method returns a good individual from the enviroment. The selection is done by the

See also:
pIndividualSelection object. Beware: You have to care for, that the returned individual gets deleted after usage.
pIndividualSelection
cIndividualSelection
Returns:
a pointer to a good individual
cIndividual* enviroment::cEnviroment::getIndividual ( const cIndividualIdentifier identifier) const

This method returns the the individual with the given identifier. Beware: You have to care for, that the returned individual gets deleted after usage.

Parameters:
identifierthe identifier for the individual which is to be returned
Returns:
a pointer to the individual with the given identifier or NULL, if non exists
const cIndividualInfo* enviroment::cEnviroment::getIndividualInfo ( const cIndividualIdentifier identifier) const

This method returns the information for the individual with the given identifier.

Parameters:
identifierthe identifier for the individual, for which the information is to be returned
Returns:
a pointer to the information for the individual with the given identifier or NULL, if non exists
list<const cIndividualInfo*> enviroment::cEnviroment::getIndividualInfos ( short  iLive = 0) const

This method returns the information about individuals in the enviroment.

Parameters:
iLivea number which indicate of which kind the individuals should be, from which the information is to be returned; possible values: 0 : return the informations of all individuals in the enviroment, regardless if they are living or not 1 : return the information just of living individuals -1: return the information just of dead individuals else: an empty list is to be returned; reserved for future use, please don't use this
Returns:
a list with pointers to the information about the individuals
static const cIndividualSelection* enviroment::cEnviroment::getIndividualSelection ( )
static
Returns:
a pointer to the object for selecting a good individual or NULL, if non such exists;
See also:
pIndividualSelection
static const cInitEnviroment* enviroment::cEnviroment::getInitEnviroment ( )
static
Returns:
a pointer to the object for initializing the enviroment or NULL, if non such exists;
See also:
pInitEnviroment
static cEnviroment* enviroment::cEnviroment::getInstance ( )
static

This method returns a pointer to an instance of the enviroment/ genetic algorithm, if the parameters are set.

See also:
setParameter()
Returns:
pointer to an instance of the enviroment/ genetic algorithm, if the parameters are set, else NULL
time_t enviroment::cEnviroment::getLastStartTime ( ) const
Returns:
the time the
See also:
start() method was called the last time or 0, if non such exists
static const cMaximumReached* enviroment::cEnviroment::getMaximumReached ( )
static
Returns:
a pointer to the object for checking if individuals needs to be deleted befor adding new individuals or NULL, if non such exists;
See also:
pMaximumIndividuals
unsigned long enviroment::cEnviroment::getNumberOfCalledOperations ( )
Returns:
the number of operations executed /called by the enviroment
See also:
lNumberOfCalledOperations
unsigned long enviroment::cEnviroment::getNumberOfIndividuals ( short  iLive = 1)

This method returns the number of individuals in the enviroment.

Parameters:
iLivea number which indicate of which kind the individuals should be, which are counted; possible values: 0 : return the count of all individuals in the enviroment, regardless if they are living or not 1 : return the count just of living individuals -1: return the count just of dead individuals else: 0 is to be returned; reserved for future use, please don't use this
Returns:
the count of the individuals of the given type
unsigned int enviroment::cEnviroment::getNumberOfRunningOperations ( )
Returns:
the number of operations, which run at the time
static cOperatorFitnessAlgorithm* enviroment::cEnviroment::getOperatorFitnessAlgorithm ( )
static
Returns:
a pointer to the object for evaluing the fitness of operators of the enviroment and for handling them or NULL, if non such exists;
See also:
pOperationFitnessAlgorithmus
static const cResourceCheck* enviroment::cEnviroment::getResourceCheck ( )
static
Returns:
a pointer to the object for checking if more operators could be started or NULL, if non such exists;
See also:
pResourceCheck
static const cSelectIndividualToDelete* enviroment::cEnviroment::getSelectIndividualToDelete ( )
static
Returns:
a pointer to the object for selecting a bad individual or NULL, if non such exists;
See also:
pSelectIndividualToDelete
bool enviroment::cEnviroment::insertIndividual ( const cIndividual pInIndividual,
const cOperation pProducerOperation = NULL 
)

This method inserts a copy of the given living individual into the enviroment. The type of the individual has to be correct for this enviroment and the individual has to be correct for inserting.

Parameters:
pInIndividuala pointer to the individual to insert
pProducerOperationthe operation which produced the individual, if NULL (standardvalue) no operation gets credit for creating the individual
Returns:
true if the individual was inserted, else false
virtual bool enviroment::cEnviroment::isRunning ( ) const
virtual
See also:
start()
stop()
Returns:
true if the enviroment is running, else false
void enviroment::cEnviroment::operationStatusChange ( cOperation pOperation,
bool  isRunning 
)
virtual

This method is called, if the running status of the operation is changed.

See also:
cOperation::bIsRunning
cOperation::isRunning()
Parameters:
pOperationa pointer to the operation, which status has changed
isRunningthe new running status for the operation

Implements enviroment::ciOperationStatusChange.

bool enviroment::cEnviroment::registerIndividualListener ( clNewIndividualListener individualListener)

This method adds the given individual listener object to the set of individual listener objects. Listeners of the set gets notified if new indeviduals wher inserted into the enviroment or old wher deleted.

See also:
unregisterIndividualListener()
setIndividualListener
clNewIndividualListener
Parameters:
individualListenera pointer to the individual listener object to add to the set of individual listeners
Returns:
true if the individual listener was added, else false
bool enviroment::cEnviroment::removeIndividual ( const cIndividualIdentifier  pInIndividual)
protected

This method removes the given individual from the enviroment and delets it.

Parameters:
pInIndividuala pointer to the individual to delete
Returns:
true if the given individual was deleted, else false
virtual bool enviroment::cEnviroment::run ( )
virtual

This method runs the enviroment. It will wait till the enviroment is ended befor returning. This method will do the work of the enviroment.

See also:
start()
stop()
setIsRunning()
Returns:
true if the operation was started
static void* enviroment::cEnviroment::runTread ( void *  inputArg)
staticprivate

This method runs the enviroment for a tread. It will wait till the operation is ended befor returning. It will simply call run().

See also:
run()
start()
stop()
static bool enviroment::cEnviroment::setParameter ( const cInitEnviroment pInInit,
const cObjectFitnessAlgorithm pInObjectFitnessAlgorithm,
const cEndConditionCheck pInEndCondition = NULL,
const cIndividualSelection pInIndividualSelection = NULL,
const cMaximumReached pInMaximumIndividuals = NULL,
const cSelectIndividualToDelete pInSelectIndividualToDelete = NULL,
const cOperatorFitnessAlgorithm pInOperationFitnessAlgorithmus = NULL,
const cChoosOperator pInChoosOperator = NULL,
const cResourceCheck pInResourceCheck = NULL 
)
static

This method sets the parameters for the enviroment. You can't create an instance of the enviroment, if the parameters aren't set correctly. All parameters are copied for the use in the enviroment.

See also:
bParameterSet
getInstance()
Parameters:
pInInitA pointer to the object for initializing the enviroment. If NULL the initializing object isn't changed.
See also:
pInitEnviroment
Parameters:
pInObjectFitnessAlgorithmA pointer to the object for evaluing the fitness of individuals (respectively the objects they represents). If NULL the object for evaluing the fitnes isn't changed. Make sure this object /algorithm has an original individual set, else setParameter() will return false.
See also:
pObjectFitnessAlgorithm
Parameters:
pInEndConditionA pointer to the object for checking the endcondition of the enviroment. If Null (standardvalue) and no object for checking the endcondition exists an cEndConditionCheck object is taken to be the endcondition, else, if an object for checking the endcondition exists, it isn't changed.
See also:
pEndCondition and
cEndConditionCheck
Parameters:
pInIndividualSelectionA pointer to the object for selecting a good individual. If Null (standardvalue) and no object for selecting a good individual exists an
See also:
pInIndividualSelectionWeel object is taken for selection, else, if an object for selecting a good individual exists, it isn't changed.
pIndividualSelection
Parameters:
pInMaximumIndividualsA pointer to the object for checking if individuals needs to be deleted befor adding new individuals. If Null (standardvalue) and no object for checking the maximal individuals exists an
See also:
cMaximumReached object is taken for checking if the maximum number of individuals wher reached, else, if an object for checking the maximum number of individuals exists, it isn't changed.
pMaximumIndividuals
Parameters:
pInSelectIndividualToDeleteA pointer to the object for selecting a bad individual. If Null (standardvalue) and no object for selecting a bad individual exists an
See also:
cSelectIndividualToDeleteWeel object is taken for selection, else, if an object for selecting a bad individual exists, it isn't changed.
pSelectIndividualToDelete
Parameters:
pInOperationFitnessAlgorithmusA pointer to the object for evaluing the fitness of operators of the enviroment and for handling them. If Null (standardvalue) and no object for evaluing the fitness of operators exists an
See also:
cOperatorFitnessAlgorithmBasic object is taken for handling the operators, else, if an object for evaluing the fitness of the operators exists, it isn't changed.
pOperationFitnessAlgorithmus
Parameters:
pInChoosOperatorA pointer to the object for selecting a good operator. If Null (standardvalue) and no object for selecting a good operator exists an
See also:
cChoosOperator object is taken for for selecting an operator, else, if an object for choosing good operator exists, it isn't changed.
pChoosOperator
Parameters:
pInResourceCheckA pointer to the object for checking if more operators could be started. If Null (standardvalue) and no object for checking if more operators could be started exists an
See also:
cResourceCheck object is taken for the check, else, if an object for checking if more operators could be started exists, it isn't changed.
pResourceCheck
Returns:
if all parameter could be set true, else false; if true was returned,
See also:
getInstance() will return a enviroment instance, elso it will return NULL
static void enviroment::cEnviroment::shortSleep ( )
staticprivate

This function sleeps for a short period.

bool enviroment::cEnviroment::start ( )

This method starts the enviroment and returns, without waiting that the enviroment halts. The method run() will do the work of the enviroment. So overwrite the method run() if you wan't to change the behavour of the enviroment and not this method.

See also:
run()
stop()
isRunning()
Returns:
true if the enviroment was started, else false
virtual bool enviroment::cEnviroment::stop ( )
virtual

This method stops the enviroment and returns when it halted.

See also:
run()
start()
isRunning()
Returns:
true if the enviroment was stoped, else false
static void* enviroment::cEnviroment::stopOperation ( void *  inputArg)
staticprivate

This method stop the operation for a tread. It will wait till the operation is stoped befor returning.

See also:
stop()
Parameters:
inputArga pointer to the operation to stop
bool enviroment::cEnviroment::unregisterIndividualListener ( clNewIndividualListener individualListener)

This method removes the given individual listener object from the set of individual listener objects. Listeners of the set gets notified if new indeviduals wher inserted into the enviroment or old wher deleted.

See also:
registerIndividualListener()
setIndividualListener
clNewIndividualListener
Parameters:
individualListenera pointer to the individual listener object to removes from the set of individual listeners
Returns:
true if the individual listener was removed, else false

Member Data Documentation

bool enviroment::cEnviroment::bIsRunning
staticprotected

If true the enviroment is running, else not.

Definition at line 233 of file cEnviroment.h.

bool enviroment::cEnviroment::bLiDeadIndividualInfosSorted
staticprotected

If true the list with the living individuals is sorted, else not.

Definition at line 181 of file cEnviroment.h.

bool enviroment::cEnviroment::bLiLivingIndividualInfosSorted
staticprotected

If true the list with the living individuals is sorted, else not.

Definition at line 161 of file cEnviroment.h.

bool enviroment::cEnviroment::bParameterSet
staticprotected

If true the parameter for the enviroment are set, else not.

Definition at line 228 of file cEnviroment.h.

bool enviroment::cEnviroment::bStopFlag
staticprotected

If true the enviroment should be stoped, else not.

Definition at line 238 of file cEnviroment.h.

double enviroment::cEnviroment::dCpuRunTime
staticprotected

The time in secounds the enviroment was running. (

See also:
isRunning() gives back true for this time)

Definition at line 204 of file cEnviroment.h.

long long enviroment::cEnviroment::lAlgorithmIdentifier
staticprotected

The identifier for the enviroment/ genetic algorithm. It should be unique for every enviroment, even on different computers.

Definition at line 125 of file cEnviroment.h.

list<const cIndividualInfo*> enviroment::cEnviroment::liDeadIndividualInfos
staticprotected

A list with pointers to the informations of the dead individuals in the enviroment. This list will allways be sorted with the best individuals (fitness) at the front.

Definition at line 176 of file cEnviroment.h.

list<const cIndividualInfo*> enviroment::cEnviroment::liLivingIndividualInfos
staticprotected

A list with pointers to the informations of the living individuals in the enviroment.

Definition at line 156 of file cEnviroment.h.

list<cOperation*> enviroment::cEnviroment::liOperationsToDelete
staticprotected

A list with the operations which are done and can be deleted.

Definition at line 192 of file cEnviroment.h.

unsigned long long enviroment::cEnviroment::lNumberOfCalledOperations
staticprotected

The number of operations executed/ called by the enviroment.

Definition at line 197 of file cEnviroment.h.

map< cIndividualIdentifier, cIndividualInformation > enviroment::cEnviroment::mapDeadIndividuals
staticprotected

The container for the dead individuals in the enviroment. This field is for better internal handling of individuals.

initialize with: mapDeadIndividuals( compIndividualFitness )

Definition at line 169 of file cEnviroment.h.

map<cIndividualIdentifier, cIndividualInformation > enviroment::cEnviroment::mapLivingIndividuals
staticprotected

The container for the living individuals in the enviroment. This field is for better internal handling of individuals.

initialize with: mapLivingIndividuals( compIndividualFitness )

Definition at line 150 of file cEnviroment.h.

map< cOperation * , cOperationInformation > enviroment::cEnviroment::mapRunningOperations
staticprotected

A map with the information for the running operations and the information for them.

Definition at line 187 of file cEnviroment.h.

const std::string enviroment::cEnviroment::OPERATION_DOMAIN

The type of individuals on which the enviroment will run.

Definition at line 316 of file cEnviroment.h.

cChoosOperator* enviroment::cEnviroment::pChoosOperator
staticprotected

A pointer to the object for selecting a good operator.

Definition at line 283 of file cEnviroment.h.

cEndConditionCheck* enviroment::cEnviroment::pEndCondition
staticprotected

A pointer to the object for checking the endcondition of the enviroment.

Definition at line 256 of file cEnviroment.h.

cEnviroment* enviroment::cEnviroment::pEnviroment
staticprotected

A pointer to the enviroment instance.

Definition at line 130 of file cEnviroment.h.

cIndividualSelection* enviroment::cEnviroment::pIndividualSelection
staticprotected

A pointer to the object for selecting a good individual.

Definition at line 261 of file cEnviroment.h.

cInitEnviroment* enviroment::cEnviroment::pInitEnviroment
staticprotected

A pointer to the object for initializing the enviroment.

Definition at line 244 of file cEnviroment.h.

cMaximumReached* enviroment::cEnviroment::pMaximumIndividuals
staticprotected

A pointer to the object for checking if individuals needs to be deleted befor adding new individuals.

Definition at line 267 of file cEnviroment.h.

cObjectFitnessAlgorithm* enviroment::cEnviroment::pObjectFitnessAlgorithm
staticprotected

A pointer to the object for evaluing the fitness of individuals respectively the objects they represents.

Definition at line 250 of file cEnviroment.h.

cOperatorFitnessAlgorithm* enviroment::cEnviroment::pOperationFitnessAlgorithmus
staticprotected

A pointer to the object for evaluing the fitness of operators of the enviroment and for handling them.

Definition at line 278 of file cEnviroment.h.

cResourceCheck* enviroment::cEnviroment::pResourceCheck
staticprotected

A pointer to the object for checking, if more operators could be started.

Definition at line 289 of file cEnviroment.h.

cSelectIndividualToDelete* enviroment::cEnviroment::pSelectIndividualToDelete
staticprotected

A pointer to the object for selecting a bad individual.

Definition at line 272 of file cEnviroment.h.

pthread_t* enviroment::cEnviroment::pThreadEnviroment
staticprotected

The tread for running the enviroment.

See also:
start()
stop()
run()

Definition at line 141 of file cEnviroment.h.

set<clNewIndividualListener *> enviroment::cEnviroment::setIndividualListener
staticprotected

This set contains pointers to all objects, which want's to be notified, if new indeviduals wher inserted into the enviroment or old wher deleted.

See also:
clNewIndividualListener

Definition at line 297 of file cEnviroment.h.

time_t enviroment::cEnviroment::tmFirstStartTime
staticprotected

The time the

See also:
start() method was called the first time for this enviroment instance.

Definition at line 222 of file cEnviroment.h.

time_t enviroment::cEnviroment::tmLastCpuRunTime
staticprotected

The time the the cpu time was evalued the last time. This variable is for evaluing the cpu time while the enviroemnt runs.

Definition at line 210 of file cEnviroment.h.

time_t enviroment::cEnviroment::tmLastStartTime
staticprotected

The time the

See also:
start() method was called the last time.

Definition at line 216 of file cEnviroment.h.


The documentation for this class was generated from the following file: