dynrules
|
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. | |
Rule * | find (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. |
A container class for managing Rule objects and their weights.
dynrules::RuleSet::RuleSet | ( | double | minweight, |
double | maxweight | ||
) |
Creates a new RuleSet instance.
minweight | The minimum weight for the individual rules. |
maxweight | The maximum weight for the individual rules. |
invalid_argument | Thrown, if minweight is greater than the set maxweight. |
Definition at line 23 of file RuleSet.cpp.
void dynrules::RuleSet::addRule | ( | Rule * | rule | ) |
rule | The Rule to add. |
invalid_argument | Thrown, 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.
fitness | The 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.
remainder | The remainder to distribute. |
Definition at line 194 of file RuleSet.cpp.
Rule * dynrules::RuleSet::find | ( | int | id | ) |
double dynrules::RuleSet::getMaxWeight | ( | ) | const |
Gets the maximum weight for the individual rules.
Definition at line 51 of file RuleSet.cpp.
double dynrules::RuleSet::getMinWeight | ( | ) | const |
Gets the minimum weight for the individual rules.
Definition at line 39 of file RuleSet.cpp.
std::vector< Rule * > dynrules::RuleSet::getRules | ( | ) | const |
Gets the Rule objects hold by the RuleSet.
Definition at line 68 of file RuleSet.cpp.
double dynrules::RuleSet::getWeight | ( | ) | const |
Gets the current weight of all Rule objects.
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.
rule | The Rule to remove. |
Definition at line 86 of file RuleSet.cpp.
void dynrules::RuleSet::setMaxWeight | ( | double | maxweight | ) |
Sets the maximum weight for the individual rules.
maxweight | The maximum weight to use. |
invalid_argument | Thrown, 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.
minweight | The minimum weight to use. |
invalid_argument | Thrown, 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.
fitness | The 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.