Generic Grouping Heuristic class. More...

#include <rgroupingheuristic.h>

Inheritance diagram for RGroupingHeuristic< cGroup, cObj, cGroups >:
[legend]
Collaboration diagram for RGroupingHeuristic< cGroup, cObj, cGroups >:
[legend]

Public Member Functions

 RGroupingHeuristic (const RString &n, RRandom &r, RCursor< cObj > objs, RDebug *debug=0)
 
const RString GetName (void) const
 
virtual void Init (cGroups *groups)
 
virtual void BuildOrder (void)
 
virtual cGroup * FindGroup (cObj *obj)=0
 
void Run (cGroups *groups)
 
virtual void PostRun (void)
 
bool IsEnd (void)
 
size_t GetNbObjsOk (void)
 
long RRand (long max)
 
template<class T >
void RandOrder (T *arr, size_t size)
 
virtual ~RGroupingHeuristic (void)
 

Protected Attributes

RString Name
 
RRandomRandom
 
RCursor< cObj > Objs
 
size_t NbObjs
 
size_t NbObjsOk
 
cGroups * Groups
 
cObj ** Order
 
RDebugDebug
 

Detailed Description

template<class cGroup, class cObj, class cGroups>
class R::RGroupingHeuristic< cGroup, cObj, cGroups >

Generic Grouping Heuristic class.

The RGroupingHeuristic class provides an abstract class for grouping heuristics.

Constructor & Destructor Documentation

RGroupingHeuristic ( const RString n,
RRandom r,
RCursor< cObj >  objs,
RDebug debug = 0 
)

Construct the grouping heuristic.

Parameters
nName of the heuristic.
rThe random generator to use.
objsPointer to the objects.
debugDebugger.
virtual ~RGroupingHeuristic ( void  )
virtual

Destruct the grouping heuristic.

Member Function Documentation

const RString GetName ( void  ) const

Get the name of the heuristic.

Returns
Pointer to a C String.
virtual void Init ( cGroups *  groups)
virtual

Initialize the heuristic.

Parameters
groupsPointer to the groups.

Reimplemented in RHeuristicNN< cGroup, cObj, cGroups >, and RHeuristicSG< cGroup, cObj, cGroups >.

virtual void BuildOrder ( void  )
virtual

Build the order in which the objects that are not assigned must be grouped. By default, the methods treats them in random order.

The array Order must be filled with the pointer to the objects to treat in the correct order and the variable NbObjs must be set with the correct number of objects to treat.

virtual cGroup* FindGroup ( cObj *  obj)
pure virtual

Find a group for the next object.

Parameters
objObject.

Implemented in RHeuristicNN< cGroup, cObj, cGroups >, RHeuristicSG< cGroup, cObj, cGroups >, and RFirstFitHeuristic< cGroup, cObj, cGroups >.

void Run ( cGroups *  groups)

Run the heuristic.

Parameters
groupsPointer to the groups.
virtual void PostRun ( void  )
virtual

Do some operations after the run.

Reimplemented in RHeuristicNN< cGroup, cObj, cGroups >, and RHeuristicSG< cGroup, cObj, cGroups >.

bool IsEnd ( void  )

Return true if all the objects are grouped.

size_t GetNbObjsOk ( void  )

Return the number of objects grouped.

long RRand ( long  max)

Return a number in the interval [0,max[ using the current random generator.

Parameters
maxVariable used to calculate the number.
void RandOrder ( T *  arr,
size_t  size 
)

Random the position of elements of a vector using the current random generator.

Parameters
arrA pointer to the array representing the vector.
sizeThe size of the vector.

Member Data Documentation

RString Name
protected

Name of the heuristic.

RRandom& Random
protected

The random number generator to use.

RCursor<cObj> Objs
protected

Objects to be grouped.

size_t NbObjs
protected

Number of objects to be grouped.

size_t NbObjsOk
protected

Number of objects already grouped.

cGroups* Groups
protected

Groups.

cObj** Order
protected

Order in which the objects are to be treated.

RDebug* Debug
protected

Pointer to a "debugger" holding information about the GA when it is running.