The LearnSystem class generates scripts from RuleSet objects. More...
#include <LearnSystem.h>
Public Member Functions | |
LearnSystem () | |
Creates a new LearnSystem instance. | |
LearnSystem (double minweight, double maxweight) | |
Creates a new LearnSystem instance. | |
LearnSystem (RuleSet *ruleset) | |
Creates a new LearnSystem instance using an existing RuleSet. | |
LearnSystem (const LearnSystem &lsystem) | |
Creates a new LearnSystem instance from a LearnSystem. | |
virtual | ~LearnSystem () |
Destroys the LearnSystem. | |
RuleSet * | getRuleSet () const |
Gets the RuleSet used by the LearnSystem. | |
void | setRuleSet (RuleSet *ruleset) |
Sets the RuleSet to use by the LearnSystem. | |
unsigned int | getMaxTries () const |
Gets the amount of tries to select and add rules to the script to generate. | |
void | setMaxTries (unsigned int maxtries) |
Sets the amount of tries to select and add rules to the script to generate. | |
unsigned int | getMaxScriptSize () const |
Gets the maximum script size to generate. | |
void | setMaxScriptSize (unsigned int maxscriptsize) |
Sets the maximum script size to generate. | |
virtual std::string | createHeader () const |
Creates and returns the header information for the script to generate. | |
virtual std::string | createFooter () const |
Creates and returns the footer information for the script to generate. | |
virtual std::string | createRules (unsigned int maxrules) const |
Creates and returns the code of maxrules rules. | |
void | createScript (std::ostream &stream, unsigned int maxrules) |
Creates the complete script contents. | |
Protected Attributes | |
unsigned int | _maxtries |
The maximum number of tries to create script content from rules. | |
unsigned int | _maxscriptsize |
The maximum script size in bytes. | |
RuleSet * | _ruleset |
The RuleSet to take the rules from for generating the scripts. | |
The LearnSystem class generates scripts from RuleSet objects.
The LearnSystem class takes care of creating new scripts based on a predefined RuleSet. It does not evaluate the scripts nor modifies the rules written to them.
The procedure of creating scripts is done using three phases:
The header and footer are freely choosable. You can simple override or reassign the create_header() and create_footer() methods to let them return your required code.
Definition at line 35 of file LearnSystem.h.
dynrules::LearnSystem::LearnSystem | ( | ) |
Creates a new LearnSystem instance.
bad_alloc | Thrown, if the embedded RuleSet could not be allocated. |
Definition at line 16 of file LearnSystem.cpp.
dynrules::LearnSystem::LearnSystem | ( | double | minweight, |
double | maxweight | ||
) |
Creates a new LearnSystem instance.
minweight | The minimum weight limit for the embedded RuleSet. |
maxweight | The maximum weight limit for the embedded RuleSet. |
bad_alloc | Thrown, if the embedded RuleSet could not be allocated. |
char* | Thrown, if the embedded RuleSet could not be allocated. |
Definition at line 23 of file LearnSystem.cpp.
dynrules::LearnSystem::LearnSystem | ( | RuleSet * | ruleset | ) |
Creates a new LearnSystem instance using an existing RuleSet.
ruleset | The RuleSet to use. |
Definition at line 30 of file LearnSystem.cpp.
dynrules::LearnSystem::LearnSystem | ( | const LearnSystem & | lsystem | ) |
Creates a new LearnSystem instance from a LearnSystem.
Creates a new LearnSystem instance from a LearnSystem. The embedded RuleSet will be copied, not shared.
lsystem | The LearnSystem to create the instance from. |
bad_alloc | Thrown, if the embedded RuleSet could not be allocated. |
Definition at line 37 of file LearnSystem.cpp.
|
virtual |
Destroys the LearnSystem.
Destroys the LearnSystem and frees the memory hold by the embedded RuleSet.
Definition at line 44 of file LearnSystem.cpp.
|
virtual |
Creates and returns the footer information for the script to generate.
Creates the footer information to follow the rules within the script. The default implementation will return an empty string.
Definition at line 87 of file LearnSystem.cpp.
|
virtual |
Creates and returns the header information for the script to generate.
Creates the header information to precede the rules within the script. The default implementation will return an empty string.
Definition at line 81 of file LearnSystem.cpp.
|
virtual |
Creates and returns the code of maxrules rules.
Creates and returns the code of maxrules rules. The function uses the dynamic scripting algorithm as described by Pieter Spronck et al.
maxrules | The maximum amount of rule code to create. |
Definition at line 93 of file LearnSystem.cpp.
void dynrules::LearnSystem::createScript | ( | std::ostream & | stream, |
unsigned int | maxrules | ||
) |
Creates the complete script contents.
Creates the complete script contents, including the header, footer and rules information and passes them to the given stream.
Basically, this method does:
stream | The stream to pass the script code to. |
maxrules | The maximum amount of rule code to create. |
Definition at line 158 of file LearnSystem.cpp.
unsigned int dynrules::LearnSystem::getMaxScriptSize | ( | ) | const |
Gets the maximum script size to generate.
Definition at line 71 of file LearnSystem.cpp.
unsigned int dynrules::LearnSystem::getMaxTries | ( | ) | const |
Gets the amount of tries to select and add rules to the script to generate.
Definition at line 61 of file LearnSystem.cpp.
RuleSet * dynrules::LearnSystem::getRuleSet | ( | ) | const |
Gets the RuleSet used by the LearnSystem.
Definition at line 49 of file LearnSystem.cpp.
void dynrules::LearnSystem::setMaxScriptSize | ( | unsigned int | maxscriptsize | ) |
Sets the maximum script size to generate.
maxscriptsize | The maximum script size. |
Definition at line 76 of file LearnSystem.cpp.
void dynrules::LearnSystem::setMaxTries | ( | unsigned int | maxtries | ) |
Sets the amount of tries to select and add rules to the script to generate.
maxtries | The amount of tries to set. |
Definition at line 66 of file LearnSystem.cpp.
void dynrules::LearnSystem::setRuleSet | ( | RuleSet * | ruleset | ) |
Sets the RuleSet to use by the LearnSystem.
Sets the RuleSet to use by the LearnSystem without freeing the currently assigned one. This requires you to deallocate any previously used RuleSet manually:
ruleset | The RuleSet to use. |
Definition at line 54 of file LearnSystem.cpp.