summaryrefslogtreecommitdiff
path: root/fuzzylite/src/factory
diff options
context:
space:
mode:
Diffstat (limited to 'fuzzylite/src/factory')
-rw-r--r--fuzzylite/src/factory/CloningFactory.cpp135
-rw-r--r--fuzzylite/src/factory/ConstructionFactory.cpp114
-rw-r--r--fuzzylite/src/factory/DefuzzifierFactory.cpp78
-rw-r--r--fuzzylite/src/factory/FactoryManager.cpp127
-rw-r--r--fuzzylite/src/factory/FunctionFactory.cpp172
-rw-r--r--fuzzylite/src/factory/HedgeFactory.cpp51
-rw-r--r--fuzzylite/src/factory/SNormFactory.cpp55
-rw-r--r--fuzzylite/src/factory/TNormFactory.cpp53
-rw-r--r--fuzzylite/src/factory/TermFactory.cpp81
9 files changed, 866 insertions, 0 deletions
diff --git a/fuzzylite/src/factory/CloningFactory.cpp b/fuzzylite/src/factory/CloningFactory.cpp
new file mode 100644
index 0000000..b187171
--- /dev/null
+++ b/fuzzylite/src/factory/CloningFactory.cpp
@@ -0,0 +1,135 @@
+/*
+ Author: Juan Rada-Vilela, Ph.D.
+ Copyright (C) 2010-2014 FuzzyLite Limited
+ All rights reserved
+
+ 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.
+
+ 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.
+
+ */
+
+#include "fl/factory/CloningFactory.h"
+
+#include "fl/Exception.h"
+#include "fl/term/Function.h"
+
+namespace fl {
+
+ template<typename T>
+ CloningFactory<T>::CloningFactory(const std::string& name) : _name(name) {
+
+ }
+
+ template<typename T>
+ CloningFactory<T>::CloningFactory(const CloningFactory& other) {
+ typename std::map<std::string, T>::const_iterator it = other._objects.begin();
+ while (it != other._objects.end()) {
+ T clone = fl::null;
+ if (it->second) clone = it->second->clone();
+ this->_objects[it->first] = clone;
+ ++it;
+ }
+ }
+
+ template<typename T>
+ CloningFactory<T>& CloningFactory<T>::operator=(const CloningFactory& other) {
+ if (this != &other) {
+ typename std::map<std::string, T>::const_iterator it = this->_objects.begin();
+ while (it != this->_objects.end()) {
+ if (it->second) delete it->second;
+ ++it;
+ }
+ this->_objects.clear();
+
+ it = other._objects.begin();
+ while (it != other._objects.end()) {
+ T clone = fl::null;
+ if (it->second) clone = it->second->clone();
+ this->_objects[it->first] = clone;
+ ++it;
+ }
+ }
+ return *this;
+ }
+
+ template<typename T>
+ CloningFactory<T>::~CloningFactory() {
+ typename std::map<std::string, T>::const_iterator it = this->_objects.begin();
+ while (it != this->_objects.end()) {
+ if (it->second) delete it->second;
+ ++it;
+ }
+ }
+
+ template<typename T>
+ std::string CloningFactory<T>::name() const {
+ return this->_name;
+ }
+
+ template<typename T>
+ void CloningFactory<T>::registerObject(const std::string& key, T object) {
+ this->_objects[key] = object;
+ }
+
+ template<typename T>
+ void CloningFactory<T>::deregisterObject(const std::string& key) {
+ typename std::map<std::string, T>::iterator it = this->_objects.find(key);
+ if (it != this->_objects.end()) {
+ this->_objects.erase(it);
+ delete it->second;
+ }
+ }
+
+ template<typename T>
+ bool CloningFactory<T>::hasObject(const std::string& key) const {
+ typename std::map<std::string, T>::const_iterator it = this->_objects.find(key);
+ return (it != this->_objects.end());
+ }
+
+ template<typename T>
+ T CloningFactory<T>::getObject(const std::string& key) const {
+ typename std::map<std::string, T>::const_iterator it = this->_objects.find(key);
+ if (it != this->_objects.end()) {
+ if (it->second) return it->second;
+ }
+ return fl::null;
+ }
+
+ template<typename T>
+ T CloningFactory<T>::cloneObject(const std::string& key) const {
+ typename std::map<std::string, T>::const_iterator it = this->_objects.find(key);
+ if (it != this->_objects.end()) {
+ if (it->second) return it->second->clone();
+ return fl::null;
+ }
+ throw fl::Exception("[cloning error] " + _name + " object by name <" + key + "> not registered", FL_AT);
+ }
+
+ template<typename T>
+ std::vector<std::string> CloningFactory<T>::available() const {
+ std::vector<std::string> result;
+ typename std::map<std::string, T>::const_iterator it = this->_objects.begin();
+ while (it != this->_objects.end()) {
+ result.push_back(it->first);
+ }
+ return result;
+ }
+
+ template class fl::CloningFactory<fl::Function::Element*>;
+}
+
+
diff --git a/fuzzylite/src/factory/ConstructionFactory.cpp b/fuzzylite/src/factory/ConstructionFactory.cpp
new file mode 100644
index 0000000..b316e52
--- /dev/null
+++ b/fuzzylite/src/factory/ConstructionFactory.cpp
@@ -0,0 +1,114 @@
+/*
+ Author: Juan Rada-Vilela, Ph.D.
+ Copyright (C) 2010-2014 FuzzyLite Limited
+ All rights reserved
+
+ 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.
+
+ 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.
+
+ */
+
+#include "fl/factory/ConstructionFactory.h"
+
+#include "fl/Exception.h"
+#include "fl/defuzzifier/Defuzzifier.h"
+#include "fl/hedge/Hedge.h"
+#include "fl/norm/SNorm.h"
+#include "fl/norm/TNorm.h"
+#include "fl/term/Function.h"
+#include "fl/term/Term.h"
+
+
+
+namespace fl {
+
+ template <typename T>
+ ConstructionFactory<T>::ConstructionFactory(const std::string& name) : _name(name) {
+
+ }
+
+ template <typename T>
+ ConstructionFactory<T>::~ConstructionFactory() {
+ }
+
+ template<typename T>
+ std::string ConstructionFactory<T>::name() const {
+ return this->_name;
+ }
+
+ template <typename T>
+ void ConstructionFactory<T>::registerConstructor(const std::string& key, Constructor constructor) {
+ this->_constructors[key] = constructor;
+ }
+
+ template <typename T>
+ void ConstructionFactory<T>::deregisterConstructor(const std::string& key) {
+ typename std::map<std::string, Constructor>::iterator it = this->_constructors.find(key);
+ if (it != this->_constructors.end()) {
+ this->_constructors.erase(it);
+ }
+ }
+
+ template <typename T>
+ bool ConstructionFactory<T>::hasConstructor(const std::string& key) const {
+ typename std::map<std::string, Constructor>::const_iterator it = this->_constructors.find(key);
+ return (it != this->_constructors.end());
+ }
+
+ template <typename T>
+ typename ConstructionFactory<T>::Constructor ConstructionFactory<T>::getConstructor(const std::string& key) const {
+ typename std::map<std::string, Constructor>::const_iterator it = this->_constructors.find(key);
+ if (it != this->_constructors.end()) {
+ return it->second;
+ }
+ return fl::null;
+ }
+
+ template <typename T>
+ T ConstructionFactory<T>::constructObject(const std::string& key) const {
+ typename std::map<std::string, Constructor>::const_iterator it = this->_constructors.find(key);
+ if (it != this->_constructors.end()) {
+ if (it->second) {
+ return it->second();
+ }
+ return fl::null;
+ }
+ std::ostringstream ss;
+ ss << "[factory error] constructor of " + _name + " <" << key << "> not registered";
+ throw fl::Exception(ss.str(), FL_AT);
+ }
+
+ template <typename T>
+ std::vector<std::string> ConstructionFactory<T>::available() const {
+ std::vector<std::string> result;
+ typename std::map<std::string, Constructor>::const_iterator it = this->_constructors.begin();
+ while (it != this->_constructors.end()) {
+ result.push_back(it->first);
+ ++it;
+ }
+ return result;
+ }
+
+ template class ConstructionFactory<Defuzzifier*>;
+ template class ConstructionFactory<Hedge*>;
+ template class ConstructionFactory<SNorm*>;
+ template class ConstructionFactory<TNorm*>;
+ template class ConstructionFactory<Term*>;
+}
+
+
+
diff --git a/fuzzylite/src/factory/DefuzzifierFactory.cpp b/fuzzylite/src/factory/DefuzzifierFactory.cpp
new file mode 100644
index 0000000..8d89c2d
--- /dev/null
+++ b/fuzzylite/src/factory/DefuzzifierFactory.cpp
@@ -0,0 +1,78 @@
+/*
+ Author: Juan Rada-Vilela, Ph.D.
+ Copyright (C) 2010-2014 FuzzyLite Limited
+ All rights reserved
+
+ 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.
+
+ 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.
+
+ */
+
+#include "fl/factory/DefuzzifierFactory.h"
+
+#include "fl/defuzzifier/Bisector.h"
+#include "fl/defuzzifier/Centroid.h"
+#include "fl/defuzzifier/SmallestOfMaximum.h"
+#include "fl/defuzzifier/LargestOfMaximum.h"
+#include "fl/defuzzifier/MeanOfMaximum.h"
+#include "fl/defuzzifier/WeightedAverage.h"
+#include "fl/defuzzifier/WeightedSum.h"
+
+namespace fl {
+
+ DefuzzifierFactory::DefuzzifierFactory() : ConstructionFactory<Defuzzifier*>("Defuzzifier") {
+ registerConstructor("", fl::null);
+ registerConstructor(Bisector().className(), &(Bisector::constructor));
+ registerConstructor(Centroid().className(), &(Centroid::constructor));
+ registerConstructor(LargestOfMaximum().className(), &(LargestOfMaximum::constructor));
+ registerConstructor(MeanOfMaximum().className(), &(MeanOfMaximum::constructor));
+ registerConstructor(SmallestOfMaximum().className(), &(SmallestOfMaximum::constructor));
+ registerConstructor(WeightedAverage().className(), &(WeightedAverage::constructor));
+ registerConstructor(WeightedSum().className(), &(WeightedSum::constructor));
+ }
+
+ DefuzzifierFactory::~DefuzzifierFactory() {
+
+ }
+
+ Defuzzifier* DefuzzifierFactory::constructDefuzzifier(const std::string& key,
+ int resolution, WeightedDefuzzifier::Type type) const {
+ Defuzzifier* result = constructObject(key);
+ if (IntegralDefuzzifier * integralDefuzzifier = dynamic_cast<IntegralDefuzzifier*> (result)) {
+ integralDefuzzifier->setResolution(resolution);
+ } else if (WeightedDefuzzifier * weightedDefuzzifier = dynamic_cast<WeightedDefuzzifier*> (result)) {
+ weightedDefuzzifier->setType(type);
+ }
+ return result;
+ }
+
+ Defuzzifier* DefuzzifierFactory::constructDefuzzifier(const std::string& key, int resolution) const {
+ Defuzzifier* result = constructObject(key);
+ if (IntegralDefuzzifier * integralDefuzzifier = dynamic_cast<IntegralDefuzzifier*> (result)) {
+ integralDefuzzifier->setResolution(resolution);
+ }
+ return result;
+ }
+
+ Defuzzifier* DefuzzifierFactory::constructDefuzzifier(const std::string& key, WeightedDefuzzifier::Type type) {
+ Defuzzifier* result = constructObject(key);
+ if (WeightedDefuzzifier * weightedDefuzzifier = dynamic_cast<WeightedDefuzzifier*> (result)) {
+ weightedDefuzzifier->setType(type);
+ }
+ return result;
+ }
+}
diff --git a/fuzzylite/src/factory/FactoryManager.cpp b/fuzzylite/src/factory/FactoryManager.cpp
new file mode 100644
index 0000000..c2374dc
--- /dev/null
+++ b/fuzzylite/src/factory/FactoryManager.cpp
@@ -0,0 +1,127 @@
+/*
+ Author: Juan Rada-Vilela, Ph.D.
+ Copyright (C) 2010-2014 FuzzyLite Limited
+ All rights reserved
+
+ 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.
+
+ 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.
+
+ */
+
+#include "fl/factory/FactoryManager.h"
+
+#include "fl/factory/DefuzzifierFactory.h"
+#include "fl/factory/FunctionFactory.h"
+#include "fl/factory/HedgeFactory.h"
+#include "fl/factory/SNormFactory.h"
+#include "fl/factory/TermFactory.h"
+#include "fl/factory/TNormFactory.h"
+
+namespace fl {
+
+ FactoryManager FactoryManager::_instance;
+
+ FactoryManager* FactoryManager::instance() {
+ return &_instance;
+ }
+
+ FactoryManager::FactoryManager() :
+ _tnorm(new TNormFactory), _snorm(new SNormFactory), _defuzzifier(new DefuzzifierFactory),
+ _term(new TermFactory), _hedge(new HedgeFactory), _function(new FunctionFactory) {
+ }
+
+ FactoryManager::FactoryManager(TNormFactory* tnorm, SNormFactory* snorm,
+ DefuzzifierFactory* defuzzifier, TermFactory* term,
+ HedgeFactory* hedge, FunctionFactory* function) :
+ _tnorm(tnorm), _snorm(snorm), _defuzzifier(defuzzifier), _term(term), _hedge(hedge),
+ _function(function) {
+ }
+
+ FactoryManager::FactoryManager(const FactoryManager& other)
+ : _tnorm(fl::null), _snorm(fl::null), _defuzzifier(fl::null), _term(fl::null), _hedge(fl::null), _function(fl::null) {
+ if (other._tnorm.get()) this->_tnorm.reset(new TNormFactory(*other._tnorm.get()));
+ if (other._snorm.get()) this->_snorm.reset(new SNormFactory(*other._snorm.get()));
+ if (other._defuzzifier.get()) this->_defuzzifier.reset(new DefuzzifierFactory(*other._defuzzifier.get()));
+ if (other._term.get()) this->_term.reset(new TermFactory(*other._term.get()));
+ if (other._hedge.get()) this->_hedge.reset(new HedgeFactory(*other._hedge.get()));
+ if (other._function.get()) this->_function.reset(new FunctionFactory(*other._function.get()));
+ }
+
+ FactoryManager& FactoryManager::operator=(const FactoryManager& other) {
+ if (this != &other) {
+ if (other._tnorm.get()) this->_tnorm.reset(new TNormFactory(*other._tnorm.get()));
+ if (other._snorm.get()) this->_snorm.reset(new SNormFactory(*other._snorm.get()));
+ if (other._defuzzifier.get()) this->_defuzzifier.reset(new DefuzzifierFactory(*other._defuzzifier.get()));
+ if (other._term.get()) this->_term.reset(new TermFactory(*other._term.get()));
+ if (other._hedge.get()) this->_hedge.reset(new HedgeFactory(*other._hedge.get()));
+ if (other._function.get()) this->_function.reset(new FunctionFactory(*other._function.get()));
+ }
+ return *this;
+ }
+
+ FactoryManager::~FactoryManager() {
+ }
+
+ void FactoryManager::setTnorm(TNormFactory* tnorm) {
+ this->_tnorm.reset(tnorm);
+ }
+
+ TNormFactory* FactoryManager::tnorm() const {
+ return this->_tnorm.get();
+ }
+
+ void FactoryManager::setSnorm(SNormFactory* snorm) {
+ this->_snorm.reset(snorm);
+ }
+
+ SNormFactory* FactoryManager::snorm() const {
+ return this->_snorm.get();
+ }
+
+ void FactoryManager::setDefuzzifier(DefuzzifierFactory* defuzzifier) {
+ this->_defuzzifier.reset(defuzzifier);
+ }
+
+ DefuzzifierFactory* FactoryManager::defuzzifier() const {
+ return this->_defuzzifier.get();
+ }
+
+ void FactoryManager::setTerm(TermFactory* term) {
+ this->_term.reset(term);
+ }
+
+ TermFactory* FactoryManager::term() const {
+ return this->_term.get();
+ }
+
+ void FactoryManager::setHedge(HedgeFactory* hedge) {
+ this->_hedge.reset(hedge);
+ }
+
+ HedgeFactory* FactoryManager::hedge() const {
+ return this->_hedge.get();
+ }
+
+ void FactoryManager::setFunction(FunctionFactory* function) {
+ this->_function.reset(function);
+ }
+
+ FunctionFactory* FactoryManager::function() const {
+ return this->_function.get();
+ }
+
+}
diff --git a/fuzzylite/src/factory/FunctionFactory.cpp b/fuzzylite/src/factory/FunctionFactory.cpp
new file mode 100644
index 0000000..3c0718d
--- /dev/null
+++ b/fuzzylite/src/factory/FunctionFactory.cpp
@@ -0,0 +1,172 @@
+/*
+ Author: Juan Rada-Vilela, Ph.D.
+ Copyright (C) 2010-2014 FuzzyLite Limited
+ All rights reserved
+
+ 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.
+
+ 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.
+
+ */
+
+#include "fl/factory/FunctionFactory.h"
+
+#include "fl/rule/Rule.h"
+
+namespace fl {
+
+ FunctionFactory::FunctionFactory() : CloningFactory<Function::Element*>("Function::Element") {
+ registerOperators();
+ registerFunctions();
+ }
+
+ FunctionFactory::~FunctionFactory() {
+
+ }
+
+ void FunctionFactory::registerOperators() {
+ //OPERATORS:
+ int p = 100;
+ //First order: not, negate:
+ registerObject("!", new Function::Element("!", "Logical NOT",
+ Function::Element::OPERATOR, &(fl::Op::logicalNot), p, 1)); //logical not
+ registerObject("~", new Function::Element("~", "Negation",
+ Function::Element::OPERATOR, &(fl::Op::negate), p, 1)); // ~ negates a number
+
+ p -= 10;
+ //Second order: power
+ registerObject("^", new Function::Element("^", "Power",
+ Function::Element::OPERATOR, &(std::pow), p, 1));
+
+ p -= 10;
+ //Third order: multiplication, division, modulo
+ registerObject("*", new Function::Element("*", "Multiplication",
+ Function::Element::OPERATOR, &(fl::Op::multiply), p));
+ registerObject("/", new Function::Element("/", "Division",
+ Function::Element::OPERATOR, &(fl::Op::divide), p));
+ registerObject("%", new Function::Element("%", "Modulo",
+ Function::Element::OPERATOR, &(fl::Op::modulo), p));
+
+ p -= 10;
+ //Fourth order: addition, subtraction
+ registerObject("+", new Function::Element("+", "Addition",
+ Function::Element::OPERATOR, &(fl::Op::add), p));
+ registerObject("-", new Function::Element("-", "Subtraction",
+ Function::Element::OPERATOR, &(fl::Op::subtract), p));
+
+ //Fifth order: logical and, logical or
+ p -= 10; //Logical AND
+ registerObject(fl::Rule::andKeyword(), new Function::Element(fl::Rule::andKeyword(), "Logical AND",
+ Function::Element::OPERATOR, &(fl::Op::logicalAnd), p));
+ p -= 10; //Logical OR
+ registerObject(fl::Rule::orKeyword(), new Function::Element(fl::Rule::orKeyword(), "Logical OR",
+ Function::Element::OPERATOR, &(fl::Op::logicalOr), p));
+ }
+
+ void FunctionFactory::registerFunctions() {
+ //FUNCTIONS
+ registerObject("gt", new Function::Element("gt", "Greater than (>)",
+ Function::Element::FUNCTION, &(fl::Op::gt)));
+ registerObject("ge", new Function::Element("ge", "Greater than or equal to (>=)",
+ Function::Element::FUNCTION, &(fl::Op::ge)));
+ registerObject("eq", new Function::Element("eq", "Equal to (==)",
+ Function::Element::FUNCTION, &(fl::Op::eq)));
+ registerObject("neq", new Function::Element("neq", "Not equal to (!=)",
+ Function::Element::FUNCTION, &(fl::Op::neq)));
+ registerObject("le", new Function::Element("le", "Less than or equal to (<=)",
+ Function::Element::FUNCTION, &(fl::Op::le)));
+ registerObject("lt", new Function::Element("lt", "Less than (<)",
+ Function::Element::FUNCTION, &(fl::Op::lt)));
+
+ registerObject("acos", new Function::Element("acos", "Inverse cosine",
+ Function::Element::FUNCTION, &(std::acos)));
+ registerObject("asin", new Function::Element("asin", "Inverse sine",
+ Function::Element::FUNCTION, &(std::asin)));
+ registerObject("atan", new Function::Element("atan", "Inverse tangent",
+ Function::Element::FUNCTION, &(std::atan)));
+
+ registerObject("ceil", new Function::Element("ceil", "Ceiling",
+ Function::Element::FUNCTION, &(std::ceil)));
+ registerObject("cos", new Function::Element("cos", "Cosine",
+ Function::Element::FUNCTION, &(std::cos)));
+ registerObject("cosh", new Function::Element("cosh", "Hyperbolic cosine",
+ Function::Element::FUNCTION, &(std::cosh)));
+ registerObject("exp", new Function::Element("exp", "Exponential",
+ Function::Element::FUNCTION, &(std::exp)));
+ registerObject("fabs", new Function::Element("fabs", "Absolute",
+ Function::Element::FUNCTION, &(std::fabs)));
+ registerObject("floor", new Function::Element("floor", "Floor",
+ Function::Element::FUNCTION, &(std::floor)));
+ registerObject("log", new Function::Element("log", "Natural logarithm",
+ Function::Element::FUNCTION, &(std::log)));
+ registerObject("log10", new Function::Element("log10", "Common logarithm",
+ Function::Element::FUNCTION, &(std::log10)));
+ registerObject("round", new Function::Element("round", "Round",
+ Function::Element::FUNCTION, &(fl::Op::round)));
+ registerObject("sin", new Function::Element("sin", "Sine",
+ Function::Element::FUNCTION, &(std::sin)));
+ registerObject("sinh", new Function::Element("sinh", "Hyperbolic sine",
+ Function::Element::FUNCTION, &(std::sinh)));
+ registerObject("sqrt", new Function::Element("sqrt", "Square root",
+ Function::Element::FUNCTION, &(std::sqrt)));
+ registerObject("tan", new Function::Element("tan", "Tangent",
+ Function::Element::FUNCTION, &(std::tan)));
+ registerObject("tanh", new Function::Element("tanh", "Hyperbolic tangent",
+ Function::Element::FUNCTION, &(std::tanh)));
+
+#if defined(FL_UNIX) && !defined(FL_USE_FLOAT)
+ //found in Unix when using double precision. not found in Windows.
+ registerObject("log1p", new Function::Element("log1p", "Natural logarithm plus one",
+ Function::Element::FUNCTION, &(log1p)));
+ registerObject("acosh", new Function::Element("acosh", "Inverse hyperbolic cosine",
+ Function::Element::FUNCTION, &(acosh)));
+ registerObject("asinh", new Function::Element("asinh", "Inverse hyperbolic sine",
+ Function::Element::FUNCTION, &(asinh)));
+ registerObject("atanh", new Function::Element("atanh", "Inverse hyperbolic tangent",
+ Function::Element::FUNCTION, &(atanh)));
+#endif
+
+ registerObject("pow", new Function::Element("pow", "Power",
+ Function::Element::FUNCTION, &(std::pow)));
+ registerObject("atan2", new Function::Element("atan2", "Inverse tangent (y,x)",
+ Function::Element::FUNCTION, &(std::atan2)));
+ registerObject("fmod", new Function::Element("fmod", "Floating-point remainder",
+ Function::Element::FUNCTION, &(std::fmod)));
+ }
+
+ std::vector<std::string> FunctionFactory::availableOperators() const {
+ std::vector<std::string> result;
+ std::map<std::string, Function::Element*>::const_iterator it = this->_objects.begin();
+ while (it != this->_objects.end()) {
+ if (it->second and it->second->type == Function::Element::OPERATOR)
+ result.push_back(it->first);
+ ++it;
+ }
+ return result;
+ }
+
+ std::vector<std::string> FunctionFactory::availableFunctions() const {
+ std::vector<std::string> result;
+ std::map<std::string, Function::Element*>::const_iterator it = this->_objects.begin();
+ while (it != this->_objects.end()) {
+ if (it->second and it->second->type == Function::Element::FUNCTION)
+ result.push_back(it->first);
+ ++it;
+ }
+ return result;
+ }
+
+}
diff --git a/fuzzylite/src/factory/HedgeFactory.cpp b/fuzzylite/src/factory/HedgeFactory.cpp
new file mode 100644
index 0000000..ea5f77a
--- /dev/null
+++ b/fuzzylite/src/factory/HedgeFactory.cpp
@@ -0,0 +1,51 @@
+/*
+ Author: Juan Rada-Vilela, Ph.D.
+ Copyright (C) 2010-2014 FuzzyLite Limited
+ All rights reserved
+
+ 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.
+
+ 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.
+
+ */
+
+#include "fl/factory/HedgeFactory.h"
+
+#include "fl/hedge/Any.h"
+#include "fl/hedge/Extremely.h"
+#include "fl/hedge/Not.h"
+#include "fl/hedge/Seldom.h"
+#include "fl/hedge/Somewhat.h"
+#include "fl/hedge/Very.h"
+
+
+namespace fl {
+
+ HedgeFactory::HedgeFactory() : ConstructionFactory<Hedge*>("Hedge") {
+ registerConstructor("", fl::null);
+ registerConstructor(Any().name(), &(Any::constructor));
+ registerConstructor(Extremely().name(), &(Extremely::constructor));
+ registerConstructor(Not().name(), &(Not::constructor));
+ registerConstructor(Seldom().name(), &(Seldom::constructor));
+ registerConstructor(Somewhat().name(), &(Somewhat::constructor));
+ registerConstructor(Very().name(), &(Very::constructor));
+ }
+
+ HedgeFactory::~HedgeFactory() {
+
+ }
+
+}
diff --git a/fuzzylite/src/factory/SNormFactory.cpp b/fuzzylite/src/factory/SNormFactory.cpp
new file mode 100644
index 0000000..6e42551
--- /dev/null
+++ b/fuzzylite/src/factory/SNormFactory.cpp
@@ -0,0 +1,55 @@
+/*
+ Author: Juan Rada-Vilela, Ph.D.
+ Copyright (C) 2010-2014 FuzzyLite Limited
+ All rights reserved
+
+ 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.
+
+ 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.
+
+ */
+
+#include "fl/factory/SNormFactory.h"
+
+#include "fl/norm/s/AlgebraicSum.h"
+#include "fl/norm/s/BoundedSum.h"
+#include "fl/norm/s/DrasticSum.h"
+#include "fl/norm/s/EinsteinSum.h"
+#include "fl/norm/s/HamacherSum.h"
+#include "fl/norm/s/Maximum.h"
+#include "fl/norm/s/NilpotentMaximum.h"
+#include "fl/norm/s/NormalizedSum.h"
+
+namespace fl {
+
+ SNormFactory::SNormFactory() : ConstructionFactory<SNorm*>("SNorm") {
+ registerConstructor("", fl::null);
+ registerConstructor(AlgebraicSum().className(), &(AlgebraicSum::constructor));
+ registerConstructor(BoundedSum().className(), &(BoundedSum::constructor));
+ registerConstructor(DrasticSum().className(), &(DrasticSum::constructor));
+ registerConstructor(EinsteinSum().className(), &(EinsteinSum::constructor));
+ registerConstructor(HamacherSum().className(), &(HamacherSum::constructor));
+ registerConstructor(Maximum().className(), &(Maximum::constructor));
+ registerConstructor(NilpotentMaximum().className(), &(NilpotentMaximum::constructor));
+ registerConstructor(NormalizedSum().className(), &(NormalizedSum::constructor));
+ }
+
+ SNormFactory::~SNormFactory() {
+
+ }
+
+
+}
diff --git a/fuzzylite/src/factory/TNormFactory.cpp b/fuzzylite/src/factory/TNormFactory.cpp
new file mode 100644
index 0000000..95628cc
--- /dev/null
+++ b/fuzzylite/src/factory/TNormFactory.cpp
@@ -0,0 +1,53 @@
+/*
+ Author: Juan Rada-Vilela, Ph.D.
+ Copyright (C) 2010-2014 FuzzyLite Limited
+ All rights reserved
+
+ 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.
+
+ 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.
+
+ */
+
+#include "fl/factory/TNormFactory.h"
+
+#include "fl/norm/t/AlgebraicProduct.h"
+#include "fl/norm/t/BoundedDifference.h"
+#include "fl/norm/t/DrasticProduct.h"
+#include "fl/norm/t/EinsteinProduct.h"
+#include "fl/norm/t/HamacherProduct.h"
+#include "fl/norm/t/Minimum.h"
+#include "fl/norm/t/NilpotentMinimum.h"
+
+namespace fl {
+
+ TNormFactory::TNormFactory() : ConstructionFactory<TNorm*>("TNorm") {
+ registerConstructor("", fl::null);
+ registerConstructor(AlgebraicProduct().className(), &(AlgebraicProduct::constructor));
+ registerConstructor(BoundedDifference().className(), &(BoundedDifference::constructor));
+ registerConstructor(DrasticProduct().className(), &(DrasticProduct::constructor));
+ registerConstructor(EinsteinProduct().className(), &(EinsteinProduct::constructor));
+ registerConstructor(HamacherProduct().className(), &(HamacherProduct::constructor));
+ registerConstructor(Minimum().className(), &(Minimum::constructor));
+ registerConstructor(NilpotentMinimum().className(), &(NilpotentMinimum::constructor));
+ }
+
+ TNormFactory::~TNormFactory() {
+
+ }
+
+
+}
diff --git a/fuzzylite/src/factory/TermFactory.cpp b/fuzzylite/src/factory/TermFactory.cpp
new file mode 100644
index 0000000..10f3c15
--- /dev/null
+++ b/fuzzylite/src/factory/TermFactory.cpp
@@ -0,0 +1,81 @@
+/*
+ Author: Juan Rada-Vilela, Ph.D.
+ Copyright (C) 2010-2014 FuzzyLite Limited
+ All rights reserved
+
+ 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.
+
+ 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.
+
+ */
+
+#include "fl/factory/TermFactory.h"
+
+#include "fl/Exception.h"
+#include "fl/term/Term.h"
+#include "fl/term/Bell.h"
+#include "fl/term/Concave.h"
+#include "fl/term/Constant.h"
+#include "fl/term/Cosine.h"
+#include "fl/term/Discrete.h"
+#include "fl/term/Function.h"
+#include "fl/term/Gaussian.h"
+#include "fl/term/GaussianProduct.h"
+#include "fl/term/Linear.h"
+#include "fl/term/PiShape.h"
+#include "fl/term/Ramp.h"
+#include "fl/term/Rectangle.h"
+#include "fl/term/SShape.h"
+#include "fl/term/Sigmoid.h"
+#include "fl/term/SigmoidDifference.h"
+#include "fl/term/SigmoidProduct.h"
+#include "fl/term/Spike.h"
+#include "fl/term/Trapezoid.h"
+#include "fl/term/Triangle.h"
+#include "fl/term/ZShape.h"
+
+namespace fl {
+
+ TermFactory::TermFactory() : ConstructionFactory<Term*>("Term") {
+ registerConstructor("", fl::null);
+ registerConstructor(Bell().className(), &(Bell::constructor));
+ registerConstructor(Concave().className(), &(Concave::constructor));
+ registerConstructor(Constant().className(), &(Constant::constructor));
+ registerConstructor(Cosine().className(), &(Cosine::constructor));
+ registerConstructor(Discrete().className(), &(Discrete::constructor));
+ registerConstructor(Function().className(), &(Function::constructor));
+ registerConstructor(Gaussian().className(), &(Gaussian::constructor));
+ registerConstructor(GaussianProduct().className(), &(GaussianProduct::constructor));
+ registerConstructor(Linear().className(), &(Linear::constructor));
+ registerConstructor(PiShape().className(), &(PiShape::constructor));
+ registerConstructor(Ramp().className(), &(Ramp::constructor));
+ registerConstructor(Rectangle().className(), &(Rectangle::constructor));
+ registerConstructor(SShape().className(), &(SShape::constructor));
+ registerConstructor(Sigmoid().className(), &(Sigmoid::constructor));
+ registerConstructor(SigmoidDifference().className(), &(SigmoidDifference::constructor));
+ registerConstructor(SigmoidProduct().className(), &(SigmoidProduct::constructor));
+ registerConstructor(Spike().className(), &(Spike::constructor));
+ registerConstructor(Trapezoid().className(), &(Trapezoid::constructor));
+ registerConstructor(Triangle().className(), &(Triangle::constructor));
+ registerConstructor(ZShape().className(), &(ZShape::constructor));
+ }
+
+ TermFactory::~TermFactory() {
+
+ }
+
+
+}