dynrules
 All Classes Functions Variables
Public Member Functions | Protected Attributes | List of all members
dynrules::RuleSet Class Reference

A container class for managing Rule objects and their weights. More...

#include <RuleSet.h>

Public Member Functions

 RuleSet ()
 Creates a new RuleSet instance.
 
 RuleSet (double minweight, double maxweight)
 Creates a new RuleSet instance.
 
virtual ~RuleSet ()
 Destroys the RuleSet.
 
double getMinWeight () const
 Gets the minimum weight for the individual rules.
 
void setMinWeight (double minweight)
 Sets the minimum weight for the individual rules.
 
double getMaxWeight () const
 Gets the maximum weight for the individual rules.
 
void setMaxWeight (double maxweight)
 Sets the maximum weight for the individual rules.
 
double getWeight () const
 Gets the current weight of all Rule objects.
 
std::vector< Rule * > getRules () const
 Gets the Rule objects hold by the RuleSet.
 
void addRule (Rule *rule)
 Adds a Rule to the RuleSet.
 
bool removeRule (Rule *rule)
 Removes a Rule from the RuleSet.
 
Rulefind (int id)
 Find and return the Rule with the matching id.
 
void clear ()
 Removes all Rule objects from the RuleSet.
 
void updateWeights (void *fitness)
 Updates the weights of all contained Rules objects.
 
virtual double calculateAdjustment (void *fitness)
 Calculates the reward or penalty for the active rules.
 
virtual void distributeRemainder (double remainder)
 Distributes the remainder of the weight differences.
 

Protected Attributes

double _minweight
 The minimum weight an individual Rule can have.
 
double _maxweight
 The minimum weight an individual Rule can have.
 
double _weight
 The current weight of all Rule objects.
 
std::vector< Rule * > _rules
 The list of Rule objects currently hold by the RuleSet.
 

Detailed Description

A container class for managing Rule objects and their weights.

Definition at line 20 of file RuleSet.h.

Constructor & Destructor Documentation

dynrules::RuleSet::RuleSet ( double  minweight,
double  maxweight 
)

Creates a new RuleSet instance.

Parameters
minweightThe minimum weight for the individual rules.
maxweightThe maximum weight for the individual rules.
Exceptions
invalid_argumentThrown, if minweight is greater than the set maxweight.

Definition at line 23 of file RuleSet.cpp.

Member Function Documentation

void dynrules::RuleSet::addRule ( Rule rule)

Adds a Rule to the RuleSet.

Parameters
ruleThe Rule to add.
Exceptions
invalid_argumentThrown, if the passed argument is NULL.

Definition at line 73 of file RuleSet.cpp.

double dynrules::RuleSet::calculateAdjustment ( void *  fitness)
virtual

Calculates the reward or penalty for the active rules.

Calculates the reward or penalty, each of the activated rules recives. fitness hereby can be used as measure of the performance or whatever is suitable in the implementation.

Parameters
fitnessThe measure of the overall fitness.

Definition at line 189 of file RuleSet.cpp.

void dynrules::RuleSet::distributeRemainder ( double  remainder)
virtual

Distributes the remainder of the weight differences.

Distributes the remainder of the weight differences between the last weights and current weights.

Parameters
remainderThe remainder to distribute.

Definition at line 194 of file RuleSet.cpp.

Rule * dynrules::RuleSet::find ( int  id)

Find and return the Rule with the matching id.

Parameters
idThe id of the Rule to find.
Returns
The Rule or 0, if no such Rule exists.

Definition at line 109 of file RuleSet.cpp.

double dynrules::RuleSet::getMaxWeight ( ) const

Gets the maximum weight for the individual rules.

Returns
The maximum weight.

Definition at line 51 of file RuleSet.cpp.

double dynrules::RuleSet::getMinWeight ( ) const

Gets the minimum weight for the individual rules.

Returns
The minimum weight.

Definition at line 39 of file RuleSet.cpp.

std::vector< Rule * > dynrules::RuleSet::getRules ( ) const

Gets the Rule objects hold by the RuleSet.

Returns
A std::vector containing the Rule objects.

Definition at line 68 of file RuleSet.cpp.

double dynrules::RuleSet::getWeight ( ) const

Gets the current weight of all Rule objects.

Returns
The weight of all Rule objects hold by the RuleSet.

Definition at line 63 of file RuleSet.cpp.

bool dynrules::RuleSet::removeRule ( Rule rule)

Removes a Rule from the RuleSet.

Removes a Rule from the RuleSet. This will use the standard equality check for the Rule (x == y), and does not check whether the instances are identical.

Parameters
ruleThe Rule to remove.
Returns
true, if the Rule could be removed successfully, false, if not found or rule is 0.

Definition at line 86 of file RuleSet.cpp.

void dynrules::RuleSet::setMaxWeight ( double  maxweight)

Sets the maximum weight for the individual rules.

Parameters
maxweightThe maximum weight to use.
Exceptions
invalid_argumentThrown, if maxweight is smaller than the set minweight.

Definition at line 56 of file RuleSet.cpp.

void dynrules::RuleSet::setMinWeight ( double  minweight)

Sets the minimum weight for the individual rules.

Parameters
minweightThe minimum weight to use.
Exceptions
invalid_argumentThrown, if minweight is greater than the set maxweight.

Definition at line 44 of file RuleSet.cpp.

void dynrules::RuleSet::updateWeights ( void *  fitness)

Updates the weights of all contained Rules objects.

Updates the weights of all contained Rule objects based on Pieter Spronck's dynamic scripting algorithm.

Parameters
fitnessThe measure of the overall fitness of the performance or whatever is suitable in the concrete RuleSet::calculateAdjustment() implementation.

Definition at line 124 of file RuleSet.cpp.


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