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

The Engine class is the core class of the library as it groups the necessary components of a fuzzy logic controller. More...

#include <Engine.h>

Collaboration diagram for fl::Engine:

Public Types

enum  Type {
  Mamdani, Larsen, TakagiSugeno, Tsukamoto,
  InverseTsukamoto, Hybrid, Unknown
}
 

Public Member Functions

 Engine (const std::string &name="")
 
 Engine (const Engine &other)
 
Engineoperator= (const Engine &other)
 
virtual ~Engine ()
 
virtual void configure (const std::string &conjunction, const std::string &disjunction, const std::string &implication, const std::string &aggregation, const std::string &defuzzifier, const std::string &activation)
 Configures the engine with the given operators. More...
 
virtual void configure (TNorm *conjunction, SNorm *disjunction, TNorm *implication, SNorm *aggregation, Defuzzifier *defuzzifier, Activation *activation)
 Configures the engine with clones of the given object operators, taking ownership of the objects. More...
 
virtual bool isReady (std::string *status=fl::null) const
 Indicates whether the engine has been configured correctly and is ready for operation. More...
 
virtual Complexity complexity () const
 Computes the estimated complexity of operation of the engine. More...
 
virtual void process ()
 Processes the engine in its current state as follows: (a) Clears the aggregated fuzzy output variables, (b) Activates the rule blocks, and (c) Defuzzifies the output variables. More...
 
virtual void restart ()
 Restarts the engine by setting the values of the input variables to fl::nan and clearing the output variables. More...
 
virtual void setName (const std::string &name)
 Sets the name of the engine. More...
 
virtual std::string getName () const
 Gets the name of the engine. More...
 
virtual void setDescription (const std::string &description)
 Sets the description of the engine. More...
 
virtual std::string getDescription () const
 Gets the description of the engine. More...
 
virtual void setInputValue (const std::string &name, scalar value)
 Sets the value of the given input variable. More...
 
virtual scalar getOutputValue (const std::string &name)
 Gets the value of the given output variable. More...
 
virtual std::string toString () const
 Returns a string representation of the engine in the FuzzyLite Language. More...
 
virtual Type type (std::string *name=fl::null, std::string *reason=fl::null) const
 Infers the type of the engine based on its current configuration. More...
 
virtual Engineclone () const
 Creates a clone of the engine. More...
 
virtual std::vector< Variable * > variables () const
 Returns a vector that contains the input variables followed by the output variables in the order of insertion. More...
 
virtual void addInputVariable (InputVariable *inputVariable)
 Adds the input variable. More...
 
virtual InputVariablesetInputVariable (InputVariable *inputVariable, std::size_t index)
 Sets the input variable at the given index. More...
 
virtual void insertInputVariable (InputVariable *inputVariable, std::size_t index)
 Inserts the input variable at the given index, shifting other variables one position to the right. More...
 
virtual InputVariablegetInputVariable (std::size_t index) const
 Gets the input variable at the given index. More...
 
virtual InputVariablegetInputVariable (const std::string &name) const
 Gets the input variable of the given name after iterating the input variables. More...
 
virtual InputVariableremoveInputVariable (std::size_t index)
 Removes the input variable at the given index (without deleting it) and shifts the remaining input variables one position to the left. More...
 
virtual InputVariableremoveInputVariable (const std::string &name)
 Removes the input variable of the given name (without deleting it) and shifts the remaining input variables one position to the left. More...
 
virtual bool hasInputVariable (const std::string &name) const
 Indicates whether an input variable of the given name is in the input variables. More...
 
virtual std::size_t numberOfInputVariables () const
 Returns the number of input variables added to the engine. More...
 
virtual const std::vector< InputVariable * > & inputVariables () const
 Returns an immutable vector of input variables. More...
 
virtual void setInputVariables (const std::vector< InputVariable *> &inputVariables)
 Sets the vector of input variables. More...
 
virtual std::vector< InputVariable * > & inputVariables ()
 Returns a mutable vector of input variables. More...
 
virtual void addOutputVariable (OutputVariable *outputVariable)
 Adds the output variable. More...
 
virtual OutputVariablesetOutputVariable (OutputVariable *outputVariable, std::size_t index)
 Sets the output variable at the given index. More...
 
virtual void insertOutputVariable (OutputVariable *outputVariable, std::size_t index)
 Inserts the output variable at the given index, shifting other variables one position to the right. More...
 
virtual OutputVariablegetOutputVariable (std::size_t index) const
 Gets the output variable at the given index. More...
 
virtual OutputVariablegetOutputVariable (const std::string &name) const
 Gets the output variable of the given name after iterating the output variables. More...
 
virtual bool hasOutputVariable (const std::string &name) const
 Indicates whether an output variable of the given name is in the output variables. More...
 
virtual OutputVariableremoveOutputVariable (std::size_t index)
 Removes the output variable at the given index (without deleting it) and shifts the remaining output variables one position to the left. More...
 
virtual OutputVariableremoveOutputVariable (const std::string &name)
 Removes the output variable of the given name (without deleting it) and shifts the remaining output variables one position to the left. More...
 
virtual std::size_t numberOfOutputVariables () const
 Returns the number of output variables added to the engine. More...
 
virtual const std::vector< OutputVariable * > & outputVariables () const
 Returns an immutable vector of output variables. More...
 
virtual void setOutputVariables (const std::vector< OutputVariable *> &outputVariables)
 Sets the vector of output variables. More...
 
virtual std::vector< OutputVariable * > & outputVariables ()
 Returns a mutable vector of output variables. More...
 
virtual void addRuleBlock (RuleBlock *ruleBlock)
 Adds the rule block. More...
 
virtual RuleBlocksetRuleBlock (RuleBlock *ruleBlock, std::size_t index)
 Sets the rule block at the given index. More...
 
virtual void insertRuleBlock (RuleBlock *ruleBlock, std::size_t index)
 Inserts the rule block at the given index, shifting other blocks one position to the right. More...
 
virtual RuleBlockgetRuleBlock (std::size_t index) const
 Gets the rule block at the given index. More...
 
virtual RuleBlockgetRuleBlock (const std::string &name) const
 Gets the rule block of the given name after iterating the rule blocks. More...
 
virtual bool hasRuleBlock (const std::string &name) const
 Indicates whether an rule block of the given name is in the rule blocks. More...
 
virtual RuleBlockremoveRuleBlock (std::size_t index)
 Removes the rule block at the given index (without deleting it) and shifts the remaining rule blocks one position to the left. More...
 
virtual RuleBlockremoveRuleBlock (const std::string &name)
 Removes the rule block of the given name (without deleting it) and shifts the remaining rule blocks one position to the left. More...
 
virtual std::size_t numberOfRuleBlocks () const
 Returns the number of rule blocks added to the engine. More...
 
virtual const std::vector< RuleBlock * > & ruleBlocks () const
 Returns an immutable vector of rule blocks. More...
 
virtual void setRuleBlocks (const std::vector< RuleBlock *> &ruleBlocks)
 Sets the vector of rule blocks. More...
 
virtual std::vector< RuleBlock * > & ruleBlocks ()
 Returns a mutable vector of rule blocks. More...
 

Protected Member Functions

void updateReferences () const
 

Detailed Description

The Engine class is the core class of the library as it groups the necessary components of a fuzzy logic controller.

Author
Juan Rada-Vilela, Ph.D.
See also
InputVariable
OutputVariable
RuleBlock
Since
4.0

Definition at line 49 of file Engine.h.

Member Enumeration Documentation

◆ Type

Enumerator
Mamdani 

Mamdani: When the output variables have IntegralDefuzzifiers.

Larsen 

Larsen: When Mamdani and AlgebraicProduct is the implication operator of the rule blocks.

TakagiSugeno 

TakagiSugeno: When output variables have WeightedDefuzzifiers of type TakagiSugeno and the output variables have Constant, Linear, or Function terms.

Tsukamoto 

Tsukamoto: When output variables have WeightedDefuzzifiers of type Tsukamoto and the output variables only have monotonic terms (Concave, Ramp, Sigmoid, SShape, and ZShape)

InverseTsukamoto 

InverseTsukamoto: When output variables have WeightedDefuzzifiers of type TakagiSugeno and the output variables do not only have Constant, Linear or Function terms.

Hybrid 

Hybrid: When output variables have different defuzzifiers.

Unknown 

Unknown: When output variables have no defuzzifiers.

Definition at line 189 of file Engine.h.

Constructor & Destructor Documentation

◆ Engine() [1/2]

fl::Engine::Engine ( const std::string &  name = "")
explicit

◆ Engine() [2/2]

fl::Engine::Engine ( const Engine other)

◆ ~Engine()

virtual fl::Engine::~Engine ( )
virtual

Member Function Documentation

◆ addInputVariable()

virtual void fl::Engine::addInputVariable ( InputVariable inputVariable)
virtual

Adds the input variable.

Parameters
inputVariableis the input variable

◆ addOutputVariable()

virtual void fl::Engine::addOutputVariable ( OutputVariable outputVariable)
virtual

Adds the output variable.

Parameters
outputVariableis the output variable

◆ addRuleBlock()

virtual void fl::Engine::addRuleBlock ( RuleBlock ruleBlock)
virtual

Adds the rule block.

Parameters
ruleBlockis the rule block

◆ clone()

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

Creates a clone of the engine.

Returns
a clone of the engine

◆ complexity()

virtual Complexity fl::Engine::complexity ( ) const
virtual

Computes the estimated complexity of operation of the engine.

Returns
the estimated complexity of operation of the engine

◆ configure() [1/2]

virtual void fl::Engine::configure ( const std::string &  conjunction,
const std::string &  disjunction,
const std::string &  implication,
const std::string &  aggregation,
const std::string &  defuzzifier,
const std::string &  activation 
)
virtual

Configures the engine with the given operators.

Parameters
conjunctionis a TNorm registered in the TNormFactory
disjunctionis an SNorm registered in the SNormFactory
implicationis an TNorm registered in the TNormFactory
aggregationis an SNorm registered in the SNormFactory
defuzzifieris a defuzzifier registered in the DefuzzifierFactory
activationis an activation method registered in the ActivationFactory

◆ configure() [2/2]

virtual void fl::Engine::configure ( TNorm conjunction,
SNorm disjunction,
TNorm implication,
SNorm aggregation,
Defuzzifier defuzzifier,
Activation activation 
)
virtual

Configures the engine with clones of the given object operators, taking ownership of the objects.

Parameters
conjunctionis the operator to process the propositions joined by and in the antecedent of the rules
disjunctionis the operator to process the propositions joined by or in the antecedent of the rules
implicationis the operator to modify the consequents of the rules based on the activation degree of the antecedents of the rules
aggregationis the operator to aggregate the resulting implications of the rules
defuzzifieris the operator to transform the aggregated implications into a single scalar value
activationis the activation method to activate and fire the rule blocks

◆ getDescription()

virtual std::string fl::Engine::getDescription ( ) const
virtual

Gets the description of the engine.

Returns
the description of the engine

◆ getInputVariable() [1/2]

virtual InputVariable* fl::Engine::getInputVariable ( std::size_t  index) const
virtual

Gets the input variable at the given index.

Parameters
indexis the given index
Returns
the input variable at the given index

◆ getInputVariable() [2/2]

virtual InputVariable* fl::Engine::getInputVariable ( const std::string &  name) const
virtual

Gets the input variable of the given name after iterating the input variables.

The cost of this method is O(n), where n is the number of input variables in the engine. For performance, please get the variables by index.

Parameters
nameis the name of the input variable
Returns
input variable of the given name
Exceptions
fl::Exceptionif there is no variable with the given name

◆ getName()

virtual std::string fl::Engine::getName ( ) const
virtual

Gets the name of the engine.

Returns
the name of the engine

◆ getOutputValue()

virtual scalar fl::Engine::getOutputValue ( const std::string &  name)
virtual

Gets the value of the given output variable.

The cost of this method is O(n), where n is the number of output variables in the engine. For performance, please get the variables by index.

Parameters
nameis the name of the output variable
Returns
the value of the given output variable

◆ getOutputVariable() [1/2]

virtual OutputVariable* fl::Engine::getOutputVariable ( std::size_t  index) const
virtual

Gets the output variable at the given index.

Parameters
indexis the given index
Returns
the output variable at the given index

◆ getOutputVariable() [2/2]

virtual OutputVariable* fl::Engine::getOutputVariable ( const std::string &  name) const
virtual

Gets the output variable of the given name after iterating the output variables.

The cost of this method is O(n), where n is the number of output variables in the engine. For performance, please get the variables by index.

Parameters
nameis the name of the output variable
Returns
output variable of the given name
Exceptions
fl::Exceptionif there is no variable with the given name

◆ getRuleBlock() [1/2]

virtual RuleBlock* fl::Engine::getRuleBlock ( std::size_t  index) const
virtual

Gets the rule block at the given index.

Parameters
indexis the given index
Returns
the rule block at the given index

◆ getRuleBlock() [2/2]

virtual RuleBlock* fl::Engine::getRuleBlock ( const std::string &  name) const
virtual

Gets the rule block of the given name after iterating the rule blocks.

The cost of this method is O(n), where n is the number of rule blocks in the engine. For performance, please get the rule blocks by index.

Parameters
nameis the name of the rule block
Returns
rule block of the given name
Exceptions
fl::Exceptionif there is no block with the given name

◆ hasInputVariable()

virtual bool fl::Engine::hasInputVariable ( const std::string &  name) const
virtual

Indicates whether an input variable of the given name is in the input variables.

Parameters
nameis the name of the input variable
Returns
whether an input variable is registered with the given name

◆ hasOutputVariable()

virtual bool fl::Engine::hasOutputVariable ( const std::string &  name) const
virtual

Indicates whether an output variable of the given name is in the output variables.

Parameters
nameis the name of the output variable
Returns
whether an output variable is registered with the given name

◆ hasRuleBlock()

virtual bool fl::Engine::hasRuleBlock ( const std::string &  name) const
virtual

Indicates whether an rule block of the given name is in the rule blocks.

Parameters
nameis the name of the rule block
Returns
whether an rule block of the given name is in the rule blocks

◆ inputVariables() [1/2]

virtual const std::vector<InputVariable*>& fl::Engine::inputVariables ( ) const
virtual

Returns an immutable vector of input variables.

Returns
an immutable vector of input variables

◆ inputVariables() [2/2]

virtual std::vector<InputVariable*>& fl::Engine::inputVariables ( )
virtual

Returns a mutable vector of input variables.

Returns
a mutable vector of input variables

◆ insertInputVariable()

virtual void fl::Engine::insertInputVariable ( InputVariable inputVariable,
std::size_t  index 
)
virtual

Inserts the input variable at the given index, shifting other variables one position to the right.

Parameters
inputVariableis the input variable to insert
indexis the index at which the input variable is to be inserted

◆ insertOutputVariable()

virtual void fl::Engine::insertOutputVariable ( OutputVariable outputVariable,
std::size_t  index 
)
virtual

Inserts the output variable at the given index, shifting other variables one position to the right.

Parameters
outputVariableis the output variable to insert
indexis the index at which the output variable is to be inserted

◆ insertRuleBlock()

virtual void fl::Engine::insertRuleBlock ( RuleBlock ruleBlock,
std::size_t  index 
)
virtual

Inserts the rule block at the given index, shifting other blocks one position to the right.

Parameters
ruleBlockis the rule block to insert
indexis the index at which the rule block is to be inserted

◆ isReady()

virtual bool fl::Engine::isReady ( std::string *  status = fl::null) const
virtual

Indicates whether the engine has been configured correctly and is ready for operation.

In more advanced engines, the result of this method should be taken as a suggestion and not as a prerequisite to operate the engine.

Parameters
status(if not null) contains the configuration errors of the engine
Returns
whether the engine is ready to operate

◆ numberOfInputVariables()

virtual std::size_t fl::Engine::numberOfInputVariables ( ) const
virtual

Returns the number of input variables added to the engine.

Returns
the number of input variables added to the engine

◆ numberOfOutputVariables()

virtual std::size_t fl::Engine::numberOfOutputVariables ( ) const
virtual

Returns the number of output variables added to the engine.

Returns
the number of output variables added to the engine

◆ numberOfRuleBlocks()

virtual std::size_t fl::Engine::numberOfRuleBlocks ( ) const
virtual

Returns the number of rule blocks added to the engine.

Returns
the number of rule blocks added to the engine

◆ operator=()

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

◆ outputVariables() [1/2]

virtual const std::vector<OutputVariable*>& fl::Engine::outputVariables ( ) const
virtual

Returns an immutable vector of output variables.

Returns
an immutable vector of output variables

◆ outputVariables() [2/2]

virtual std::vector<OutputVariable*>& fl::Engine::outputVariables ( )
virtual

Returns a mutable vector of output variables.

Returns
a mutable vector of output variables

◆ process()

virtual void fl::Engine::process ( )
virtual

Processes the engine in its current state as follows: (a) Clears the aggregated fuzzy output variables, (b) Activates the rule blocks, and (c) Defuzzifies the output variables.

See also
Aggregated::clear()
RuleBlock::activate()
OutputVariable::defuzzify()

◆ removeInputVariable() [1/2]

virtual InputVariable* fl::Engine::removeInputVariable ( std::size_t  index)
virtual

Removes the input variable at the given index (without deleting it) and shifts the remaining input variables one position to the left.

Parameters
indexis the given index
Returns
the input variable at the given index

◆ removeInputVariable() [2/2]

virtual InputVariable* fl::Engine::removeInputVariable ( const std::string &  name)
virtual

Removes the input variable of the given name (without deleting it) and shifts the remaining input variables one position to the left.

Parameters
nameis the name of the input variable
Returns
the input variable of the given name
Exceptions
fl::Exceptionif there is no variable with the given name

◆ removeOutputVariable() [1/2]

virtual OutputVariable* fl::Engine::removeOutputVariable ( std::size_t  index)
virtual

Removes the output variable at the given index (without deleting it) and shifts the remaining output variables one position to the left.

Parameters
indexis the given index
Returns
the output variable at the given index

◆ removeOutputVariable() [2/2]

virtual OutputVariable* fl::Engine::removeOutputVariable ( const std::string &  name)
virtual

Removes the output variable of the given name (without deleting it) and shifts the remaining output variables one position to the left.

Parameters
nameis the name of the output variable
Returns
the output variable of the given name
Exceptions
fl::Exceptionif there is no variable with the given name

◆ removeRuleBlock() [1/2]

virtual RuleBlock* fl::Engine::removeRuleBlock ( std::size_t  index)
virtual

Removes the rule block at the given index (without deleting it) and shifts the remaining rule blocks one position to the left.

Parameters
indexis the given index
Returns
the rule block at the given index

◆ removeRuleBlock() [2/2]

virtual RuleBlock* fl::Engine::removeRuleBlock ( const std::string &  name)
virtual

Removes the rule block of the given name (without deleting it) and shifts the remaining rule blocks one position to the left.

Parameters
nameis the name of the rule block
Returns
the rule block of the given name
Exceptions
fl::Exceptionif there is no rule block with the given name

◆ restart()

virtual void fl::Engine::restart ( )
virtual

Restarts the engine by setting the values of the input variables to fl::nan and clearing the output variables.

See also
Variable::setValue()
OutputVariable::clear()

◆ ruleBlocks() [1/2]

virtual const std::vector<RuleBlock*>& fl::Engine::ruleBlocks ( ) const
virtual

Returns an immutable vector of rule blocks.

Returns
an immutable vector of rule blocks

◆ ruleBlocks() [2/2]

virtual std::vector<RuleBlock*>& fl::Engine::ruleBlocks ( )
virtual

Returns a mutable vector of rule blocks.

Returns
a mutable vector of rule blocks

◆ setDescription()

virtual void fl::Engine::setDescription ( const std::string &  description)
virtual

Sets the description of the engine.

Parameters
descriptionis the description of the engine

◆ setInputValue()

virtual void fl::Engine::setInputValue ( const std::string &  name,
scalar  value 
)
virtual

Sets the value of the given input variable.

The cost of this method is O(n), where n is the number of input variables in the engine. For performance, please get the variables by index.

Parameters
nameis the name of the input variable
valueis the value for the input variable

◆ setInputVariable()

virtual InputVariable* fl::Engine::setInputVariable ( InputVariable inputVariable,
std::size_t  index 
)
virtual

Sets the input variable at the given index.

Parameters
inputVariableis the input variable to set
indexis the index at which the input variable is to be stored
Returns
the input variable previously stored at the given index

◆ setInputVariables()

virtual void fl::Engine::setInputVariables ( const std::vector< InputVariable *> &  inputVariables)
virtual

Sets the vector of input variables.

Parameters
inputVariablesis the vector of input variables

◆ setName()

virtual void fl::Engine::setName ( const std::string &  name)
virtual

Sets the name of the engine.

Parameters
nameis the name of the engine

◆ setOutputVariable()

virtual OutputVariable* fl::Engine::setOutputVariable ( OutputVariable outputVariable,
std::size_t  index 
)
virtual

Sets the output variable at the given index.

Parameters
outputVariableis the output variable to set
indexis the index at which the output variable is to be stored
Returns
the output variable previously stored at the given index

◆ setOutputVariables()

virtual void fl::Engine::setOutputVariables ( const std::vector< OutputVariable *> &  outputVariables)
virtual

Sets the vector of output variables.

Parameters
outputVariablesis the vector of output variables

◆ setRuleBlock()

virtual RuleBlock* fl::Engine::setRuleBlock ( RuleBlock ruleBlock,
std::size_t  index 
)
virtual

Sets the rule block at the given index.

Parameters
ruleBlockis the rule block to set
indexis the index at which the rule block is to be stored
Returns
the rule block previously stored at the given index

◆ setRuleBlocks()

virtual void fl::Engine::setRuleBlocks ( const std::vector< RuleBlock *> &  ruleBlocks)
virtual

Sets the vector of rule blocks.

Parameters
ruleBlocksis the vector of rule blocks

◆ toString()

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

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

Returns
a string representation of the engine in the FuzzyLite Language

◆ type()

virtual Type fl::Engine::type ( std::string *  name = fl::null,
std::string *  reason = fl::null 
) const
virtual

Infers the type of the engine based on its current configuration.

Parameters
namestores a string representation of the engine type (if the pointer passed is not fl::null)
reasonstores a string representation explaining the reasons for the inferred type (if the pointer passed is not fl::null)
Returns
the inferred type of the engine based on its current configuration

◆ updateReferences()

void fl::Engine::updateReferences ( ) const
protected

◆ variables()

virtual std::vector<Variable*> fl::Engine::variables ( ) const
virtual

Returns a vector that contains the input variables followed by the output variables in the order of insertion.

Returns
a vector that contains the input variables followed by the output variables in the order of insertion

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