fuzzylite  6.0
A Fuzzy Logic Control Library in C++
fl::Rule Class Reference

The Rule class is a conditional statement that contributes to the control of an Engine. More...

#include <Rule.h>

Collaboration diagram for fl::Rule:

Public Member Functions

 Rule (const std::string &text="", scalar weight=1.0)
 
 Rule (const Rule &other)
 
Ruleoperator= (const Rule &other)
 
virtual ~Rule ()
 
virtual void setEnabled (bool enabled)
 Sets whether the rule is enabled. More...
 
virtual bool isEnabled () const
 Gets whether the rule is enabled. More...
 
virtual void setText (const std::string &text)
 Sets the text of the rule. More...
 
virtual std::string getText () const
 Gets the text of the rule. More...
 
virtual void setWeight (scalar weight)
 Sets the weight of the rule. More...
 
virtual scalar getWeight () const
 Gets the weight of the rule. More...
 
virtual void setAntecedent (Antecedent *antecedent)
 Sets the antecedent of the rule. More...
 
virtual AntecedentgetAntecedent () const
 Gets the antecedent of the rule. More...
 
virtual void setConsequent (Consequent *consequent)
 Sets the consequent of the rule. More...
 
virtual ConsequentgetConsequent () const
 Gets the consequent of the rule. More...
 
virtual void setActivationDegree (scalar activationDegree)
 Sets the activation degree of the rule. More...
 
virtual scalar getActivationDegree () const
 Gets the activation degree of the rule. More...
 
virtual scalar activateWith (const TNorm *conjunction, const SNorm *disjunction)
 Activates the rule by computing its activation degree using the given conjunction and disjunction operators. More...
 
virtual void deactivate ()
 Deactivates the rule. More...
 
virtual void trigger (const TNorm *implication)
 Triggers the rule's implication (if the rule is enabled) using the given implication operator and the underlying activation degree. More...
 
virtual bool isTriggered () const
 Indicates whether the rule's implication was triggered. More...
 
virtual std::string toString () const
 Returns a string representation of the rule in the FuzzyLite Language. More...
 
virtual bool isLoaded () const
 Indicates whether the rule is loaded. More...
 
virtual void unload ()
 Unloads the rule. More...
 
virtual void load (const Engine *engine)
 Loads the rule with the text from Rule::getText(), and uses the engine to identify and retrieve references to the input variables and output variables as required. More...
 
virtual void load (const std::string &rule, const Engine *engine)
 Loads the rule with the given text, and uses the engine to identify and retrieve references to the input variables and output variables as required. More...
 
virtual Ruleclone () const
 Creates a clone of the rule without the rule being loaded. More...
 
virtual Complexity complexityOfActivation (const TNorm *conjunction, const SNorm *disjunction) const
 Computes the estimated complexity of calculating the activation degree of the rule. More...
 
virtual Complexity complexityOfFiring (const TNorm *implication) const
 Computes the estimated complexity of firing the rule. More...
 
virtual Complexity complexity (const TNorm *conjunction, const SNorm *disjunction, const TNorm *implication) const
 Returns the estimated complexity of activating and firing the rule. More...
 

Static Public Member Functions

static Ruleparse (const std::string &rule, const Engine *engine)
 Parses and creates a new rule based on the text passed. More...
 
static std::string ifKeyword ()
 Returns a string representation of the if keyword in rules. More...
 
static std::string isKeyword ()
 Returns a string representation of the is keyword in rules. More...
 
static std::string thenKeyword ()
 Returns a string representation of the then keyword in rules. More...
 
static std::string andKeyword ()
 Returns a string representation of the and keyword in rules. More...
 
static std::string orKeyword ()
 Returns a string representation of the or keyword in rules. More...
 
static std::string withKeyword ()
 Returns a string representation of the with keyword in rules. More...
 

Detailed Description

The Rule class is a conditional statement that contributes to the control of an Engine.

Each rule consists of an Antecedent and a Consequent, each of which comprises propositions in the form variable is term. The propositions in the Antecedent can be connected by the conjunctive and or the disjunctive or, both of which are fuzzy logic operators (TNorm and SNorm, respectively). Differently, the propositions in the Consequent are independent from each other and are separated with a symbolic and. The Term in any proposition can be preceded by a Hedge that modifies its membership function to model cases such as Very, Somewhat, Seldom and Not. Additionally, the contribution of a rule to the control of the engine can be determined by its weight \(w \in [0.0, 1.0]\), which is equal to 1.0 if omitted. The structure of a rule is the following: if (antecedent) then (consequent) [with weight]. The structures of the antecedent and the consequent are:

if variable is [hedge]* term [(and|or) variable is [hedge]* term]*

then variable is [hedge]* term [and variable is [hedge]* term]* [with w]?

where elements in brackets are optional, elements in parentheses are compulsory, *-marked elements may appear zero or more times, and ?-marked elements may appear once or not at all.

Author
Juan Rada-Vilela, Ph.D.
See also
Antecedent
Consequent
Hedge
RuleBlock
Since
4.0

Definition at line 66 of file Rule.h.

Constructor & Destructor Documentation

◆ Rule() [1/2]

fl::Rule::Rule ( const std::string &  text = "",
scalar  weight = 1.0 
)
explicit

◆ Rule() [2/2]

fl::Rule::Rule ( const Rule other)

◆ ~Rule()

virtual fl::Rule::~Rule ( )
virtual

Member Function Documentation

◆ activateWith()

virtual scalar fl::Rule::activateWith ( const TNorm conjunction,
const SNorm disjunction 
)
virtual

Activates the rule by computing its activation degree using the given conjunction and disjunction operators.

Parameters
conjunctionis the conjunction operator
disjunctionis the disjunction operator
Returns
the activation degree of the rule

◆ andKeyword()

static std::string fl::Rule::andKeyword ( )
inlinestatic

Returns a string representation of the and keyword in rules.

Returns
a string representation of the and keyword in rules

Definition at line 254 of file Rule.h.

◆ clone()

virtual Rule* fl::Rule::clone ( ) const
virtual

Creates a clone of the rule without the rule being loaded.

Returns
a clone of the rule without the rule being loaded

◆ complexity()

virtual Complexity fl::Rule::complexity ( const TNorm conjunction,
const SNorm disjunction,
const TNorm implication 
) const
virtual

Returns the estimated complexity of activating and firing the rule.

Parameters
conjunctionis the conjunction operator
disjunctionis the disjunction operator
implicationis the implication operator
Returns
the estimated complexity of activating and firing the rule

◆ complexityOfActivation()

virtual Complexity fl::Rule::complexityOfActivation ( const TNorm conjunction,
const SNorm disjunction 
) const
virtual

Computes the estimated complexity of calculating the activation degree of the rule.

Parameters
conjunctionis the conjunction operator
disjunctionis the disjunction operator
Returns
the estimated complexity of calculating the activation degree of the rule

◆ complexityOfFiring()

virtual Complexity fl::Rule::complexityOfFiring ( const TNorm implication) const
virtual

Computes the estimated complexity of firing the rule.

Parameters
implicationis the implication operator
Returns
the estimated complexity of firing the rule

◆ deactivate()

virtual void fl::Rule::deactivate ( )
virtual

Deactivates the rule.

◆ getActivationDegree()

virtual scalar fl::Rule::getActivationDegree ( ) const
virtual

Gets the activation degree of the rule.

Returns
the activation degree of the rule

◆ getAntecedent()

virtual Antecedent* fl::Rule::getAntecedent ( ) const
virtual

Gets the antecedent of the rule.

Returns
the antecedent of the rule

◆ getConsequent()

virtual Consequent* fl::Rule::getConsequent ( ) const
virtual

Gets the consequent of the rule.

Returns
the consequent of the rule

◆ getText()

virtual std::string fl::Rule::getText ( ) const
virtual

Gets the text of the rule.

Returns
the text of the rule

◆ getWeight()

virtual scalar fl::Rule::getWeight ( ) const
virtual

Gets the weight of the rule.

Returns
the weight of the rule

◆ ifKeyword()

static std::string fl::Rule::ifKeyword ( )
inlinestatic

Returns a string representation of the if keyword in rules.

Returns
a string representation of the if keyword in rules

Definition at line 230 of file Rule.h.

◆ isEnabled()

virtual bool fl::Rule::isEnabled ( ) const
virtual

Gets whether the rule is enabled.

An enabled rule will be fired, whereas a disabled rule will not.

Returns
whether the rule is enabled

◆ isKeyword()

static std::string fl::Rule::isKeyword ( )
inlinestatic

Returns a string representation of the is keyword in rules.

Returns
a string representation of the is keyword in rules

Definition at line 238 of file Rule.h.

◆ isLoaded()

virtual bool fl::Rule::isLoaded ( ) const
virtual

Indicates whether the rule is loaded.

Returns
whether the rule is loaded

◆ isTriggered()

virtual bool fl::Rule::isTriggered ( ) const
virtual

Indicates whether the rule's implication was triggered.

Returns
whether the rule's implication was triggered

◆ load() [1/2]

virtual void fl::Rule::load ( const Engine engine)
virtual

Loads the rule with the text from Rule::getText(), and uses the engine to identify and retrieve references to the input variables and output variables as required.

Parameters
engineis the engine from which the rule is part of

◆ load() [2/2]

virtual void fl::Rule::load ( const std::string &  rule,
const Engine engine 
)
virtual

Loads the rule with the given text, and uses the engine to identify and retrieve references to the input variables and output variables as required.

Parameters
ruleis the rule in text
engineis the engine from which the rule is part of

◆ operator=()

Rule& fl::Rule::operator= ( const Rule other)

◆ orKeyword()

static std::string fl::Rule::orKeyword ( )
inlinestatic

Returns a string representation of the or keyword in rules.

Returns
a string representation of the or keyword in rules

Definition at line 262 of file Rule.h.

◆ parse()

static Rule* fl::Rule::parse ( const std::string &  rule,
const Engine engine 
)
static

Parses and creates a new rule based on the text passed.

Parameters
ruleis the rule in text
engineis the engine from which the rule is part of
Returns
a new rule parsed from the given text

◆ setActivationDegree()

virtual void fl::Rule::setActivationDegree ( scalar  activationDegree)
virtual

Sets the activation degree of the rule.

Parameters
activationDegreeis the activation degree of the rule

◆ setAntecedent()

virtual void fl::Rule::setAntecedent ( Antecedent antecedent)
virtual

Sets the antecedent of the rule.

Parameters
antecedentis the antecedent of the rule

◆ setConsequent()

virtual void fl::Rule::setConsequent ( Consequent consequent)
virtual

Sets the consequent of the rule.

Parameters
consequentthe consequent of the rule

◆ setEnabled()

virtual void fl::Rule::setEnabled ( bool  enabled)
virtual

Sets whether the rule is enabled.

An enabled rule will be fired, whereas a disabled rule will not.

Parameters
enableddetermines whether the rule is enabled

◆ setText()

virtual void fl::Rule::setText ( const std::string &  text)
virtual

Sets the text of the rule.

Parameters
textis the text of the rule

◆ setWeight()

virtual void fl::Rule::setWeight ( scalar  weight)
virtual

Sets the weight of the rule.

Parameters
weightis the weight of the rule

◆ thenKeyword()

static std::string fl::Rule::thenKeyword ( )
inlinestatic

Returns a string representation of the then keyword in rules.

Returns
a string representation of the then keyword in rules

Definition at line 246 of file Rule.h.

◆ toString()

virtual std::string fl::Rule::toString ( ) const
virtual

Returns a string representation of the rule in the FuzzyLite Language.

Returns
a string representation of the rule in the FuzzyLite Language

◆ trigger()

virtual void fl::Rule::trigger ( const TNorm implication)
virtual

Triggers the rule's implication (if the rule is enabled) using the given implication operator and the underlying activation degree.

Parameters
implicationis the implication operator

◆ unload()

virtual void fl::Rule::unload ( )
virtual

Unloads the rule.

◆ withKeyword()

static std::string fl::Rule::withKeyword ( )
inlinestatic

Returns a string representation of the with keyword in rules.

Returns
a string representation of the with keyword in rules

Definition at line 270 of file Rule.h.


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