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

The Variable class is the base class for linguistic variables. More...

#include <Variable.h>

Inheritance diagram for fl::Variable:
Collaboration diagram for fl::Variable:

Public Types

enum  Type { None, Input, Output }
 Indicates the type of the variable to avoid costly dynamic_casts More...
 

Public Member Functions

 Variable (const std::string &name="", scalar minimum=-fl::inf, scalar maximum=fl::inf)
 
 Variable (const Variable &other)
 
Variableoperator= (const Variable &other)
 
virtual ~Variable ()
 
virtual void setName (const std::string &name)
 Sets the name of the variable. More...
 
virtual std::string getName () const
 Gets the name of the variable. More...
 
virtual std::string getDescription () const
 Gets the description of the variable. More...
 
virtual void setDescription (const std::string &description)
 Sets the description of the variable. More...
 
virtual void setValue (scalar value)
 Sets the value of the variable. More...
 
virtual scalar getValue () const
 Gets the value of the variable. More...
 
virtual void setRange (scalar minimum, scalar maximum)
 Sets the range of the variable between [minimum, maximum] More...
 
virtual scalar range () const
 Gets the magnitude of the range of the variable. More...
 
virtual void setMinimum (scalar minimum)
 Sets the minimum value of the range of the variable. More...
 
virtual scalar getMinimum () const
 Gets the minimum value of the range of the variable. More...
 
virtual void setMaximum (scalar maximum)
 Sets the maximum value of the range of the variable. More...
 
virtual scalar getMaximum () const
 Gets the maximum value of the range of the variable. More...
 
virtual void setEnabled (bool enabled)
 Sets whether the variable is enabled. More...
 
virtual bool isEnabled () const
 Gets whether the variable is enabled. More...
 
virtual void setLockValueInRange (bool lockValueInRange)
 Sets whether the variable locks the current value to the range of the variable. More...
 
virtual bool isLockValueInRange () const
 Gets whether the variable locks the current value to the range of the variable. More...
 
virtual Complexity complexity () const
 Computes the aggregated complexity of the underlying terms. More...
 
virtual std::string fuzzify (scalar x) const
 Evaluates the membership function of value \(x\) for each term \(i\), resulting in a fuzzy value in the form \(\tilde{x}=\sum_i{\mu_i(x)/i}\). More...
 
virtual TermhighestMembership (scalar x, scalar *yhighest=fl::null) const
 Gets the term which has the highest membership function value for \(x\). More...
 
virtual Type type () const
 Returns the type of the variable. More...
 
virtual std::string toString () const
 Gets a string representation of the variable in the FuzzyLite Language. More...
 
virtual void sort ()
 Sorts the terms in ascending order according to their centroids. More...
 
virtual void addTerm (Term *term)
 Adds a term to the variable. More...
 
virtual void insertTerm (Term *term, std::size_t index)
 Inserts the term in the variable. More...
 
virtual TermgetTerm (std::size_t index) const
 Gets the term at the given index. More...
 
virtual TermgetTerm (const std::string &name) const
 Gets the term of the given name. More...
 
virtual bool hasTerm (const std::string &name) const
 Gets whether a term of the given name has been added. More...
 
virtual TermremoveTerm (std::size_t index)
 Removes the term at the given index. More...
 
virtual std::size_t numberOfTerms () const
 Gets the number of terms added to the variable. More...
 
virtual void setTerms (const std::vector< Term *> &terms)
 Sets the terms of the variable. More...
 
virtual const std::vector< Term * > & terms () const
 Gets an immutable vector of the terms. More...
 
virtual std::vector< Term * > & terms ()
 Gets a mutable vector of the terms. More...
 
virtual Variableclone () const
 Creates a clone of the variable. More...
 

Protected Attributes

std::string _name
 
std::string _description
 
std::vector< Term * > _terms
 
scalar _value
 
scalar _minimum
 
scalar _maximum
 
bool _enabled
 
bool _lockValueInRange
 

Detailed Description

The Variable class is the base class for linguistic variables.

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

Definition at line 39 of file Variable.h.

Member Enumeration Documentation

◆ Type

Indicates the type of the variable to avoid costly dynamic_casts

Enumerator
None 
Input 
Output 

Definition at line 45 of file Variable.h.

Constructor & Destructor Documentation

◆ Variable() [1/2]

fl::Variable::Variable ( const std::string &  name = "",
scalar  minimum = -fl::inf,
scalar  maximum = fl::inf 
)
explicit

◆ Variable() [2/2]

fl::Variable::Variable ( const Variable other)
explicit

◆ ~Variable()

virtual fl::Variable::~Variable ( )
virtual

Member Function Documentation

◆ addTerm()

virtual void fl::Variable::addTerm ( Term term)
virtual

Adds a term to the variable.

Parameters
termis the term to add

◆ clone()

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

Creates a clone of the variable.

Returns
a clone of the variable

Reimplemented in fl::OutputVariable, and fl::InputVariable.

◆ complexity()

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

Computes the aggregated complexity of the underlying terms.

Returns
the aggregated complexity of the underlying terms

◆ fuzzify()

virtual std::string fl::Variable::fuzzify ( scalar  x) const
virtual

Evaluates the membership function of value \(x\) for each term \(i\), resulting in a fuzzy value in the form \(\tilde{x}=\sum_i{\mu_i(x)/i}\).

Parameters
xis the value to fuzzify
Returns
the fuzzy value expressed as \(\sum_i{\mu_i(x)/i}\)

◆ getDescription()

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

Gets the description of the variable.

Returns
the description of the variable

◆ getMaximum()

virtual scalar fl::Variable::getMaximum ( ) const
virtual

Gets the maximum value of the range of the variable.

Returns
the maximum value of the range of the variable

◆ getMinimum()

virtual scalar fl::Variable::getMinimum ( ) const
virtual

Gets the minimum value of the range of the variable.

Returns
the minimum value of the range of the variable

◆ getName()

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

Gets the name of the variable.

Returns
the name of the variable

◆ getTerm() [1/2]

virtual Term* fl::Variable::getTerm ( std::size_t  index) const
virtual

Gets the term at the given index.

Parameters
indexis the position of the term in the vector
Returns
the term at the given index

◆ getTerm() [2/2]

virtual Term* fl::Variable::getTerm ( const std::string &  name) const
virtual

Gets the term of the given name.

Parameters
nameis the name of the term to retrieve
Returns
the term of the given name
Exceptions
Exceptionif the term is not found

◆ getValue()

virtual scalar fl::Variable::getValue ( ) const
virtual

Gets the value of the variable.

Returns
the input value of an InputVariable, or the output value of an OutputVariable

◆ hasTerm()

virtual bool fl::Variable::hasTerm ( const std::string &  name) const
virtual

Gets whether a term of the given name has been added.

Parameters
namethe name of the term
Returns
whether the term of the given name is found

◆ highestMembership()

virtual Term* fl::Variable::highestMembership ( scalar  x,
scalar yhighest = fl::null 
) const
virtual

Gets the term which has the highest membership function value for \(x\).

Parameters
xis the value of interest
[out]yhighestis a pointer where the highest membership function value will be stored
Returns
the term \(i\) which maximimizes \(\mu_i(x)\)

◆ insertTerm()

virtual void fl::Variable::insertTerm ( Term term,
std::size_t  index 
)
virtual

Inserts the term in the variable.

Parameters
termis the term to insert
indexis the index where the term will be inserted

◆ isEnabled()

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

Gets whether the variable is enabled.

Returns
whether the variable is enabled

◆ isLockValueInRange()

virtual bool fl::Variable::isLockValueInRange ( ) const
virtual

Gets whether the variable locks the current value to the range of the variable.

If enabled in an InputVariable \(i\), the input value \(x_i\) will be used when computing the Antecedent::activationDegree() as long as \(x_i \in [\mbox{min}, \mbox{max}]\). Else, for the case of \(x_i \not\in [\mbox{min}, \mbox{max}]\), the range values will be used instead but without changing the input value \(x_i\).

If enabled in an OutputVariable \(j\), the output value \(y_j\) will be overriden by the range values when \(y_j \not\in [\mbox{min}, \mbox{max}]\). See OutputVariable for more information.

Returns
whether the variable locks the current value to the range of the variable

◆ numberOfTerms()

virtual std::size_t fl::Variable::numberOfTerms ( ) const
virtual

Gets the number of terms added to the variable.

Returns
the number of terms in the variable

◆ operator=()

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

◆ range()

virtual scalar fl::Variable::range ( ) const
virtual

Gets the magnitude of the range of the variable.

Returns
maximum - minimum

◆ removeTerm()

virtual Term* fl::Variable::removeTerm ( std::size_t  index)
virtual

Removes the term at the given index.

Parameters
indexthe index of the term to remove
Returns
the removed term

◆ setDescription()

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

Sets the description of the variable.

Parameters
descriptionis the description of the variable

◆ setEnabled()

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

Sets whether the variable is enabled.

Parameters
enableddetermines whether to enable the variable

◆ setLockValueInRange()

virtual void fl::Variable::setLockValueInRange ( bool  lockValueInRange)
virtual

Sets whether the variable locks the current value to the range of the variable.

If enabled in an InputVariable \(i\), the input value \(x_i\) will be used when computing the Antecedent::activationDegree() as long as \(x_i \in [\mbox{min}, \mbox{max}]\). Else, for the case of \(x_i \not\in [\mbox{min}, \mbox{max}]\), the range values will be used instead but without changing the input value \(x_i\).

If enabled in an OutputVariable \(j\), the output value \(y_j\) will be overriden by the range values when \(y_j \not\in [\mbox{min}, \mbox{max}]\). See OutputVariable for more information.

Parameters
lockValueInRangeindicates whether to lock the value to the range of the variable

◆ setMaximum()

virtual void fl::Variable::setMaximum ( scalar  maximum)
virtual

Sets the maximum value of the range of the variable.

Parameters
maximumis the maximum value of the range

Reimplemented in fl::OutputVariable.

◆ setMinimum()

virtual void fl::Variable::setMinimum ( scalar  minimum)
virtual

Sets the minimum value of the range of the variable.

Parameters
minimumis the minimum value of the range

Reimplemented in fl::OutputVariable.

◆ setName()

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

Sets the name of the variable.

Parameters
nameis the name of the variable

Reimplemented in fl::OutputVariable.

◆ setRange()

virtual void fl::Variable::setRange ( scalar  minimum,
scalar  maximum 
)
virtual

Sets the range of the variable between [minimum, maximum]

Parameters
minimumis the minimum value in range
maximumis the maximum value in range

◆ setTerms()

virtual void fl::Variable::setTerms ( const std::vector< Term *> &  terms)
virtual

Sets the terms of the variable.

Parameters
termsis a vector of terms

◆ setValue()

virtual void fl::Variable::setValue ( scalar  value)
virtual

Sets the value of the variable.

Parameters
valueis the input value of an InputVariable, or the output value of an OutputVariable

◆ sort()

virtual void fl::Variable::sort ( )
virtual

Sorts the terms in ascending order according to their centroids.

◆ terms() [1/2]

virtual const std::vector<Term*>& fl::Variable::terms ( ) const
virtual

Gets an immutable vector of the terms.

Returns
an immutable vector of terms

◆ terms() [2/2]

virtual std::vector<Term*>& fl::Variable::terms ( )
virtual

Gets a mutable vector of the terms.

Returns
a mutable vector of terms

◆ toString()

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

Gets a string representation of the variable in the FuzzyLite Language.

Returns
a string representation of the variable in the FuzzyLite Language
See also
FllExporter

Reimplemented in fl::OutputVariable, and fl::InputVariable.

◆ type()

virtual Type fl::Variable::type ( ) const
virtual

Returns the type of the variable.

Returns
the type of the variable

Reimplemented in fl::OutputVariable, and fl::InputVariable.

Member Data Documentation

◆ _description

std::string fl::Variable::_description
protected

Definition at line 52 of file Variable.h.

◆ _enabled

bool fl::Variable::_enabled
protected

Definition at line 56 of file Variable.h.

◆ _lockValueInRange

bool fl::Variable::_lockValueInRange
protected

Definition at line 57 of file Variable.h.

◆ _maximum

scalar fl::Variable::_maximum
protected

Definition at line 55 of file Variable.h.

◆ _minimum

scalar fl::Variable::_minimum
protected

Definition at line 55 of file Variable.h.

◆ _name

std::string fl::Variable::_name
protected

Definition at line 51 of file Variable.h.

◆ _terms

std::vector<Term*> fl::Variable::_terms
protected

Definition at line 53 of file Variable.h.

◆ _value

scalar fl::Variable::_value
protected

Definition at line 54 of file Variable.h.


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