summaryrefslogtreecommitdiff
path: root/fuzzylite/fl/variable/Variable.h
diff options
context:
space:
mode:
Diffstat (limited to 'fuzzylite/fl/variable/Variable.h')
-rw-r--r--fuzzylite/fl/variable/Variable.h254
1 files changed, 228 insertions, 26 deletions
diff --git a/fuzzylite/fl/variable/Variable.h b/fuzzylite/fl/variable/Variable.h
index 61870af..47530c0 100644
--- a/fuzzylite/fl/variable/Variable.h
+++ b/fuzzylite/fl/variable/Variable.h
@@ -1,25 +1,17 @@
/*
- Author: Juan Rada-Vilela, Ph.D.
- Copyright (C) 2010-2014 FuzzyLite Limited
- All rights reserved
+ fuzzylite (R), a fuzzy logic control library in C++.
+ Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved.
+ Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com>
This file is part of fuzzylite.
fuzzylite is free software: you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the Free
- Software Foundation, either version 3 of the License, or (at your option)
- any later version.
+ the terms of the FuzzyLite License included with the software.
- fuzzylite is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with fuzzylite. If not, see <http://www.gnu.org/licenses/>.
-
- fuzzyliteâ„¢ is a trademark of FuzzyLite Limited.
+ You should have received a copy of the FuzzyLite License along with
+ fuzzylite. If not, see <http://www.fuzzylite.com/license/>.
+ fuzzylite is a registered trademark of FuzzyLite Limited.
*/
#ifndef FL_VARIABLE_H
@@ -35,62 +27,272 @@ namespace fl {
class Term;
+ /**
+ The Variable class is the base class for linguistic variables.
+
+ @author Juan Rada-Vilela, Ph.D.
+ @see InputVariable
+ @see OutputVariable
+ @see Term
+ @since 4.0
+ */
class FL_API Variable {
- private:
- void copyFrom(const Variable& source);
+ public:
+ /**
+ Indicates the type of the variable to avoid costly `dynamic_casts`
+ */
+ enum Type {
+ None,
+ Input,
+ Output
+ };
protected:
std::string _name;
+ std::string _description;
std::vector<Term*> _terms;
+ scalar _value;
scalar _minimum, _maximum;
bool _enabled;
+ bool _lockValueInRange;
+
+ private:
+ void copyFrom(const Variable& source);
public:
explicit Variable(const std::string& name = "",
scalar minimum = -fl::inf,
scalar maximum = fl::inf);
- Variable(const Variable& other);
+ explicit Variable(const Variable& other);
Variable& operator=(const Variable& other);
virtual ~Variable();
FL_DEFAULT_MOVE(Variable)
+ /**
+ Sets the name of the variable
+ @param name is the name of the variable
+ */
virtual void setName(const std::string& name);
+
+ /**
+ Gets the name of the variable
+ @return the name of the variable
+ */
virtual std::string getName() const;
+ /**
+ Gets the description of the variable
+ @return the description of the variable
+ */
+ virtual std::string getDescription() const;
+
+ /**
+ Sets the description of the variable
+ @param description is the description of the variable
+ */
+ virtual void setDescription(const std::string& description);
+
+ /**
+ Sets the value of the variable
+ @param value is the input value of an InputVariable, or the output
+ value of an OutputVariable
+ */
+ virtual void setValue(scalar value);
+
+ /**
+ Gets the value of the variable
+ @return the input value of an InputVariable, or the output value of
+ an OutputVariable
+ */
+ virtual scalar getValue() const;
+
+ /**
+ Sets the range of the variable between `[minimum, maximum]`
+ @param minimum is the minimum value in range
+ @param maximum is the maximum value in range
+ */
virtual void setRange(scalar minimum, scalar maximum);
+ /**
+ Gets the magnitude of the range of the variable
+ @return `maximum - minimum`
+ */
virtual scalar range() const;
+ /**
+ Sets the minimum value of the range of the variable
+ @param minimum is the minimum value of the range
+ */
virtual void setMinimum(scalar minimum);
+ /**
+ Gets the minimum value of the range of the variable
+ @return the minimum value of the range of the variable
+ */
virtual scalar getMinimum() const;
+ /**
+ Sets the maximum value of the range of the variable
+ @param maximum is the maximum value of the range
+ */
virtual void setMaximum(scalar maximum);
+ /**
+ Gets the maximum value of the range of the variable
+ @return the maximum value of the range of the variable
+ */
virtual scalar getMaximum() const;
+ /**
+ Sets whether the variable is enabled
+ @param enabled determines whether to enable the variable
+ */
virtual void setEnabled(bool enabled);
+ /**
+ Gets whether the variable is enabled
+ @return whether the variable is enabled
+ */
virtual bool isEnabled() const;
+ /**
+ Sets whether the variable locks the current value to the range of the
+ variable.
+
+ If enabled in an InputVariable @f$i@f$, the input value @f$x_i@f$
+ will be used when computing the Antecedent::activationDegree() as
+ long as @f$x_i \in [\mbox{min}, \mbox{max}]@f$. Else, for the case of
+ @f$x_i \not\in [\mbox{min}, \mbox{max}]@f$, the range values will be
+ used instead but without changing the input value @f$x_i@f$.
+
+ If enabled in an OutputVariable @f$j@f$, the output value @f$y_j@f$
+ will be overriden by the range values when @f$y_j \not\in
+ [\mbox{min}, \mbox{max}]@f$. See OutputVariable for more information.
+
+ @param lockValueInRange indicates whether to lock the value to the
+ range of the variable
+ */
+ virtual void setLockValueInRange(bool lockValueInRange);
+
+ /**
+ Gets whether the variable locks the current value to the
+ range of the variable
+
+ If enabled in an InputVariable @f$i@f$, the input value @f$x_i@f$
+ will be used when computing the Antecedent::activationDegree() as
+ long as @f$x_i \in [\mbox{min}, \mbox{max}]@f$. Else, for the case of
+ @f$x_i \not\in [\mbox{min}, \mbox{max}]@f$, the range values will be
+ used instead but without changing the input value @f$x_i@f$.
+
+ If enabled in an OutputVariable @f$j@f$, the output value @f$y_j@f$
+ will be overriden by the range values when @f$y_j \not\in
+ [\mbox{min}, \mbox{max}]@f$. See OutputVariable for more information.
+
+ @return whether the variable locks the current value to the range of
+ the variable
+ */
+ virtual bool isLockValueInRange() const;
+
+ /**
+ Computes the aggregated complexity of the underlying terms
+ @return the aggregated complexity of the underlying terms
+ */
+ virtual Complexity complexity() const;
+
+ /**
+ Evaluates the membership function of value @f$x@f$ for each
+ term @f$i@f$, resulting in a fuzzy value in the form
+ @f$\tilde{x}=\sum_i{\mu_i(x)/i}@f$
+ @param x is the value to fuzzify
+ @return the fuzzy value expressed as @f$\sum_i{\mu_i(x)/i}@f$
+ */
virtual std::string fuzzify(scalar x) const;
+
+ /**
+ Gets the term which has the highest membership function value for
+ @f$x@f$.
+ @param x is the value of interest
+ @param[out] yhighest is a pointer where the highest membership
+ function value will be stored
+ @return the term @f$i@f$ which maximimizes @f$\mu_i(x)@f$
+ */
virtual Term* highestMembership(scalar x, scalar* yhighest = fl::null) const;
+ /**
+ Returns the type of the variable
+ @return the type of the variable
+ */
+ virtual Type type() const;
+
+ /**
+ Gets a string representation of the variable in the FuzzyLite Language
+ @return a string representation of the variable in the FuzzyLite
+ Language
+ @see FllExporter
+ */
virtual std::string toString() const;
/**
- * Operations for iterable datatype _terms
+ Sorts the terms in ascending order according to their centroids
*/
virtual void sort();
+ /**
+ Adds a term to the variable
+ @param term is the term to add
+ */
virtual void addTerm(Term* term);
- virtual void insertTerm(Term* term, int index);
- virtual Term* getTerm(int index) const;
+ /**
+ Inserts the term in the variable
+ @param term is the term to insert
+ @param index is the index where the term will be inserted
+ */
+ virtual void insertTerm(Term* term, std::size_t index);
+ /**
+ Gets the term at the given index
+ @param index is the position of the term in the vector
+ @return the term at the given index
+ */
+ virtual Term* getTerm(std::size_t index) const;
+ /**
+ Gets the term of the given name.
+ @param name is the name of the term to retrieve
+ @return the term of the given name
+ @throws Exception if the term is not found
+ */
virtual Term* getTerm(const std::string& name) const;
+ /**
+ Gets whether a term of the given name has been added
+ @param name the name of the term
+ @return whether the term of the given name is found
+ */
virtual bool hasTerm(const std::string& name) const;
- virtual Term* removeTerm(int index);
- virtual int numberOfTerms() const;
+ /**
+ Removes the term at the given index
+ @param index the index of the term to remove
+ @return the removed term
+ */
+ virtual Term* removeTerm(std::size_t index);
+ /**
+ Gets the number of terms added to the variable
+ @return the number of terms in the variable
+ */
+ virtual std::size_t numberOfTerms() const;
+ /**
+ Sets the terms of the variable
+ @param terms is a vector of terms
+ */
virtual void setTerms(const std::vector<Term*>& terms);
+ /**
+ Gets an immutable vector of the terms
+ @return an immutable vector of terms
+ */
virtual const std::vector<Term*>& terms() const;
+ /**
+ Gets a mutable vector of the terms
+ @return a mutable vector of terms
+ */
virtual std::vector<Term*>& terms();
-
+ /**
+ Creates a clone of the variable
+ @return a clone of the variable
+ */
+ virtual Variable* clone() const;
};
-
}
-
#endif /* FL_VARIABLE_H */