dynrules
Public Member Functions | Protected Attributes

dynrules::LearnSystem Class Reference

The LearnSystem class generates scripts from RuleSet objects. More...

#include <LearnSystem.h>

List of all members.

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.
RuleSetgetRuleSet () 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.

Detailed Description

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.


Constructor & Destructor Documentation

dynrules::LearnSystem::LearnSystem ( )

Creates a new LearnSystem instance.

Exceptions:
bad_allocThrown, 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.

Parameters:
minweightThe minimum weight limit for the embedded RuleSet.
maxweightThe maximum weight limit for the embedded RuleSet.
Exceptions:
bad_allocThrown, 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.

Parameters:
rulesetThe 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.

Parameters:
lsystemThe LearnSystem to create the instance from.
Exceptions:
bad_allocThrown, if the embedded RuleSet could not be allocated.

Definition at line 37 of file LearnSystem.cpp.

dynrules::LearnSystem::~LearnSystem ( ) [virtual]

Destroys the LearnSystem.

Destroys the LearnSystem and frees the memory hold by the embedded RuleSet.

Definition at line 44 of file LearnSystem.cpp.


Member Function Documentation

std::string dynrules::LearnSystem::createFooter ( ) const [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.

Returns:
The string containing the footer information.

Definition at line 87 of file LearnSystem.cpp.

std::string dynrules::LearnSystem::createHeader ( ) const [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.

Returns:
The string containing the header information.

Definition at line 81 of file LearnSystem.cpp.

std::string dynrules::LearnSystem::createRules ( unsigned int  maxrules) const [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.

Parameters:
maxrulesThe maximum amount of rule code to create.
Returns:
The string containing the rule code.

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 << createHeader ();
   stream << createRules (maxrules);
   stream << createFooter ();
Parameters:
streamThe stream to pass the script code to.
maxrulesThe maximum amount of rule code to create.

Definition at line 157 of file LearnSystem.cpp.

unsigned int dynrules::LearnSystem::getMaxScriptSize ( ) const

Gets the maximum script size to generate.

Returns:
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.

Returns:
The amount of tries.

Definition at line 61 of file LearnSystem.cpp.

RuleSet * dynrules::LearnSystem::getRuleSet ( ) const

Gets the RuleSet used by the LearnSystem.

Returns:
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.

Parameters:
maxscriptsizeThe 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.

Parameters:
maxtriesThe 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 *tmp = lsystem.getRuleSet();
   lsystem.setRuleSet(new_ruleset_to_use);
   delete tmp;
Parameters:
rulesetThe RuleSet to use.

Definition at line 54 of file LearnSystem.cpp.


The documentation for this class was generated from the following files:
 All Classes Functions Variables