1
0
mirror of https://github.com/andre-wojtowicz/torcs-client-fuzzy-cpp synced 2024-11-29 16:00:27 +01:00

Added project files

This commit is contained in:
Andrzej Wójtowicz 2016-03-18 13:04:29 +01:00
parent 0676a44741
commit a5c2d5fee7
111 changed files with 8292 additions and 0 deletions

90
dep/fl/Console.h Normal file
View File

@ -0,0 +1,90 @@
/*
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.
*/
#ifndef FL_CONSOLE_H
#define FL_CONSOLE_H
#include "fl/fuzzylite.h"
#include <map>
#include <string>
#include <vector>
namespace fl {
class Engine;
class FL_API Console {
public:
struct Option {
std::string key, value, description;
explicit Option(const std::string& key = "", const std::string& value = "", const std::string& description = "") :
key(key), value(value), description(description) {
}
};
static const std::string KW_INPUT_FILE;
static const std::string KW_INPUT_FORMAT;
static const std::string KW_OUTPUT_FILE;
static const std::string KW_OUTPUT_FORMAT;
static const std::string KW_EXAMPLE;
static const std::string KW_DECIMALS;
static const std::string KW_DATA_INPUT;
static const std::string KW_DATA_MAXIMUM;
static const std::string KW_DATA_EXPORT_HEADER;
static const std::string KW_DATA_EXPORT_INPUTS;
static Engine* mamdani();
static Engine* takagiSugeno();
protected:
static std::map<std::string, std::string> parse(int argc, char** argv);
static void process(const std::map<std::string, std::string>& options);
static void process(const std::string& input, std::ostream& writer,
const std::string& inputFormat, const std::string& outputFormat,
const std::map<std::string, std::string>& options);
static int readCharacter();
static void interactive(std::ostream& writer, Engine* engine);
static std::string interactiveHelp();
static void exportAllExamples(const std::string& from, const std::string& to);
static void exportAllExamples(const std::string& from, const std::string& to, const std::string& path);
#ifdef FL_CPP11
static void benchmarkExamples(const std::string& path, int runs);
#endif
public:
static std::string usage();
static std::vector<Option> availableOptions();
static int main(int argc, char** argv);
};
}
#endif /* FL_CONSOLE_H */

152
dep/fl/Engine.h Normal file
View File

@ -0,0 +1,152 @@
/*
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.
*/
#ifndef FL_ENGINE_H
#define FL_ENGINE_H
#include "fl/fuzzylite.h"
#include "fl/defuzzifier/IntegralDefuzzifier.h"
#include <string>
#include <vector>
namespace fl {
class InputVariable;
class OutputVariable;
class Variable;
class RuleBlock;
class Hedge;
class TNorm;
class SNorm;
class Defuzzifier;
class FL_API Engine {
private:
void copyFrom(const Engine& source);
protected:
std::string _name;
std::vector<InputVariable*> _inputVariables;
std::vector<OutputVariable*> _outputVariables;
std::vector<RuleBlock*> _ruleblocks;
void updateReferences() const;
public:
explicit Engine(const std::string& name = "");
Engine(const Engine& other);
Engine& operator=(const Engine& other);
virtual ~Engine();
FL_DEFAULT_MOVE(Engine)
//TODO: remove int resolution in v6.0
virtual void configure(const std::string& conjunctionT,
const std::string& disjunctionS,
const std::string& activationT,
const std::string& accumulationS,
const std::string& defuzzifier,
int resolution = IntegralDefuzzifier::defaultResolution());
virtual void configure(TNorm* conjunction, SNorm* disjunction,
TNorm* activation, SNorm* accumulation,
Defuzzifier* defuzzifier);
virtual bool isReady(std::string* status = fl::null) const;
virtual void process();
virtual void restart();
virtual void setName(const std::string& name);
virtual std::string getName() const;
virtual void setInputValue(const std::string& name, scalar value);
virtual scalar getOutputValue(const std::string& name);
virtual std::string toString() const;
enum Type {
Mamdani, Larsen, TakagiSugeno,
Tsukamoto, InverseTsukamoto, Hybrid, Unknown
};
virtual Type type(std::string* name = fl::null, std::string* reason = fl::null) const;
virtual Engine* clone() const;
virtual std::vector<Variable*> variables() const;
/**
* Operations for iterable datatype _inputVariables
*/
virtual void addInputVariable(InputVariable* inputVariable);
virtual InputVariable* setInputVariable(InputVariable* inputVariable, int index);
virtual void insertInputVariable(InputVariable* inputVariable, int index);
virtual InputVariable* getInputVariable(int index) const;
virtual InputVariable* getInputVariable(const std::string& name) const;
virtual InputVariable* removeInputVariable(int index);
virtual InputVariable* removeInputVariable(const std::string& name);
virtual bool hasInputVariable(const std::string& name) const;
virtual int numberOfInputVariables() const;
virtual const std::vector<InputVariable*>& inputVariables() const;
virtual void setInputVariables(const std::vector<InputVariable*>& inputVariables);
virtual std::vector<InputVariable*>& inputVariables();
/**
* Operations for iterable datatype _outputVariables
*/
virtual void addOutputVariable(OutputVariable* outputVariable);
virtual OutputVariable* setOutputVariable(OutputVariable* outputVariable, int index);
virtual void insertOutputVariable(OutputVariable* outputVariable, int index);
virtual OutputVariable* getOutputVariable(int index) const;
virtual OutputVariable* getOutputVariable(const std::string& name) const;
virtual bool hasOutputVariable(const std::string& name) const;
virtual OutputVariable* removeOutputVariable(int index);
virtual OutputVariable* removeOutputVariable(const std::string& name);
virtual int numberOfOutputVariables() const;
virtual const std::vector<OutputVariable*>& outputVariables() const;
virtual void setOutputVariables(const std::vector<OutputVariable*>& outputVariables);
virtual std::vector<OutputVariable*>& outputVariables();
/**
* Operations for iterable datatype _ruleblocks
*/
virtual void addRuleBlock(RuleBlock* ruleblock);
virtual RuleBlock* setRuleBlock(RuleBlock* ruleBlock, int index);
virtual void insertRuleBlock(RuleBlock* ruleblock, int index);
virtual RuleBlock* getRuleBlock(int index) const;
virtual RuleBlock* getRuleBlock(const std::string& name) const;
virtual bool hasRuleBlock(const std::string& name) const;
virtual RuleBlock* removeRuleBlock(int index);
virtual RuleBlock* removeRuleBlock(const std::string& name);
virtual int numberOfRuleBlocks() const;
virtual const std::vector<RuleBlock*>& ruleBlocks() const;
virtual void setRuleBlocks(const std::vector<RuleBlock*>& ruleBlocks);
virtual std::vector<RuleBlock*>& ruleBlocks();
};
}
#endif /* FL_ENGINE_H */

66
dep/fl/Exception.h Normal file
View File

@ -0,0 +1,66 @@
/*
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.
*/
#ifndef FL_EXCEPTION_H
#define FL_EXCEPTION_H
#include "fl/fuzzylite.h"
#include <exception>
#include <string>
#include <vector>
namespace fl {
class FL_API Exception : public std::exception {
protected:
std::string _what;
public:
explicit Exception(const std::string& what);
Exception(const std::string& what, const std::string& file, int line,
const std::string& function);
virtual ~Exception() FL_INOEXCEPT FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Exception)
virtual void setWhat(const std::string& what);
virtual std::string getWhat() const;
virtual const char* what() const FL_INOEXCEPT FL_IOVERRIDE;
virtual void append(const std::string& whatElse);
virtual void append(const std::string& file, int line, const std::string& function);
virtual void append(const std::string& whatElse,
const std::string& file, int line, const std::string& function);
static std::string btCallStack();
static void signalHandler(int signal);
static void convertToException(int signal);
static void terminate();
static void catchException(const std::exception& exception);
};
}
#endif /* FL_EXCEPTION_H */

131
dep/fl/Headers.h Normal file
View File

@ -0,0 +1,131 @@
/*
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.
*/
#ifndef FL_HEADERS_H
#define FL_HEADERS_H
#include "fl/fuzzylite.h"
#include "fl/Console.h"
#include "fl/Engine.h"
#include "fl/Exception.h"
#include "fl/defuzzifier/Bisector.h"
#include "fl/defuzzifier/Centroid.h"
#include "fl/defuzzifier/Defuzzifier.h"
#include "fl/defuzzifier/IntegralDefuzzifier.h"
#include "fl/defuzzifier/SmallestOfMaximum.h"
#include "fl/defuzzifier/LargestOfMaximum.h"
#include "fl/defuzzifier/MeanOfMaximum.h"
#include "fl/defuzzifier/WeightedAverage.h"
#include "fl/defuzzifier/WeightedDefuzzifier.h"
#include "fl/defuzzifier/WeightedSum.h"
#include "fl/factory/CloningFactory.h"
#include "fl/factory/ConstructionFactory.h"
#include "fl/factory/FactoryManager.h"
#include "fl/factory/FunctionFactory.h"
#include "fl/factory/DefuzzifierFactory.h"
#include "fl/factory/HedgeFactory.h"
#include "fl/factory/SNormFactory.h"
#include "fl/factory/TNormFactory.h"
#include "fl/factory/TermFactory.h"
#include "fl/imex/CppExporter.h"
#include "fl/imex/FclImporter.h"
#include "fl/imex/FclExporter.h"
#include "fl/imex/FisImporter.h"
#include "fl/imex/FisExporter.h"
#include "fl/imex/FldExporter.h"
#include "fl/imex/FllImporter.h"
#include "fl/imex/FllExporter.h"
#include "fl/imex/JavaExporter.h"
#include "fl/hedge/Any.h"
#include "fl/hedge/Extremely.h"
#include "fl/hedge/Hedge.h"
#include "fl/hedge/Not.h"
#include "fl/hedge/Seldom.h"
#include "fl/hedge/Somewhat.h"
#include "fl/hedge/Very.h"
#include "fl/Operation.h"
#include "fl/norm/Norm.h"
#include "fl/norm/SNorm.h"
#include "fl/norm/TNorm.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"
#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"
#include "fl/rule/Antecedent.h"
#include "fl/rule/Consequent.h"
#include "fl/rule/Rule.h"
#include "fl/rule/RuleBlock.h"
#include "fl/rule/Expression.h"
#include "fl/term/Accumulated.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/Term.h"
#include "fl/term/Activated.h"
#include "fl/term/Trapezoid.h"
#include "fl/term/Triangle.h"
#include "fl/term/ZShape.h"
#include "fl/variable/InputVariable.h"
#include "fl/variable/OutputVariable.h"
#include "fl/variable/Variable.h"
#endif /* FL_HEADERS_H */

144
dep/fl/Operation.h Normal file
View File

@ -0,0 +1,144 @@
/*
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.
*/
#ifndef FL_OPERATION_H
#define FL_OPERATION_H
#include "fl/fuzzylite.h"
#include "fl/Exception.h"
#include <string>
#include <vector>
namespace fl {
class FL_API Operation {
public:
template <typename T>
static T min(T a, T b);
template <typename T>
static T max(T a, T b);
template <typename T>
static T bound(T x, T min, T max);
template <typename T>
static bool in(T x, T min, T max, bool geq = true, bool leq = true);
template <typename T>
static bool isInf(T x);
template <typename T>
static bool isNaN(T x);
template <typename T>
static bool isFinite(T x);
//Is less than
static bool isLt(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
static bool isLE(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
static bool isEq(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
static bool isGt(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
static bool isGE(scalar a, scalar b, scalar macheps = fl::fuzzylite::macheps());
static scalar scale(scalar x, scalar fromMin, scalar fromMax,
scalar toMin, scalar toMax, bool bounded = false);
static scalar add(scalar a, scalar b);
static scalar subtract(scalar a, scalar b);
static scalar multiply(scalar a, scalar b);
static scalar divide(scalar a, scalar b);
static scalar modulo(scalar a, scalar b);
static scalar logicalAnd(scalar a, scalar b);
static scalar logicalOr(scalar a, scalar b);
static scalar logicalNot(scalar a);
static scalar negate(scalar a);
static scalar round(scalar x);
//greater than
static scalar gt(scalar a, scalar b);
//greater than or equal to
static scalar ge(scalar a, scalar b);
//equal to
static scalar eq(scalar a, scalar b);
//not equal to
static scalar neq(scalar a, scalar b);
//less than or equal to
static scalar le(scalar a, scalar b);
//less than
static scalar lt(scalar a, scalar b);
static bool increment(std::vector<int>& x, std::vector<int>& min, std::vector<int>& max);
static bool increment(std::vector<int>& x, int position, std::vector<int>& min, std::vector<int>& max);
static double mean(const std::vector<scalar>& x);
static double variance(const std::vector<scalar>& x);
static double variance(const std::vector<scalar>& x, scalar mean);
static double standardDeviation(const std::vector<scalar>& x);
static double standardDeviation(const std::vector<scalar>& x, scalar mean);
static std::string validName(const std::string& name);
static int isValidForName(int character);
static std::string findReplace(const std::string& str, const std::string& find,
const std::string& replace, bool replaceAll = true);
static std::vector<std::string> split(const std::string& str,
const std::string& delimiter = " ", bool ignoreEmpty = true);
static std::string trim(const std::string& text);
static std::string format(const std::string& text, int matchesChar(int),
const std::string& replacement = "");
//Intentionally results in a compiler error in C++11, or linker error in C++98
//in order to avoid the deprecated usage of this method from version 4.0
static scalar toScalar(const std::string& x, bool quiet,
scalar alternative = fl::nan) FL_IDELETE;
static scalar toScalar(const std::string& x); //throws fl::Exception
static scalar toScalar(const std::string& x, scalar alternative) FL_INOEXCEPT;
static bool isNumeric(const std::string& x);
template <typename T>
static std::string str(T x, int decimals = fuzzylite::decimals());
template <typename T>
static std::string join(const std::vector<T>& x, const std::string& separator);
template <typename T>
static std::string join(int items, const std::string& separator, T first, ...);
};
typedef Operation Op;
}
#endif /* FL_OPERATION_H */

View File

@ -0,0 +1,49 @@
/*
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.
*/
#ifndef FL_BISECTOR_H
#define FL_BISECTOR_H
#include "fl/defuzzifier/IntegralDefuzzifier.h"
namespace fl {
class FL_API Bisector : public IntegralDefuzzifier {
public:
explicit Bisector(int resolution = defaultResolution());
virtual ~Bisector() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Bisector)
virtual std::string className() const FL_IOVERRIDE;
virtual scalar defuzzify(const Term* term,
scalar minimum, scalar maximum) const FL_IOVERRIDE;
virtual Bisector* clone() const FL_IOVERRIDE;
static Defuzzifier* constructor();
};
}
#endif /* FL_BISECTOR_H */

View File

@ -0,0 +1,47 @@
/*
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.
*/
#ifndef FL_CENTROID_H
#define FL_CENTROID_H
#include "fl/defuzzifier/IntegralDefuzzifier.h"
namespace fl {
class FL_API Centroid : public IntegralDefuzzifier {
public:
explicit Centroid(int resolution = defaultResolution());
virtual ~Centroid() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Centroid)
virtual std::string className() const FL_IOVERRIDE;
virtual scalar defuzzify(const Term* term,
scalar minimum, scalar maximum) const FL_IOVERRIDE;
virtual Centroid* clone() const FL_IOVERRIDE;
static Defuzzifier* constructor();
};
}
#endif /* FL_CENTROID_H */

View File

@ -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.
*/
//TODO Check http://en.wikipedia.org/wiki/Defuzzification for other defuzzifiers.
#ifndef FL_DEFUZZIFIER_H
#define FL_DEFUZZIFIER_H
#include "fl/fuzzylite.h"
#include <string>
namespace fl {
class Term;
class FL_API Defuzzifier {
public:
Defuzzifier() {
}
virtual ~Defuzzifier() {
}
FL_DEFAULT_COPY_AND_MOVE(Defuzzifier)
virtual std::string className() const = 0;
virtual Defuzzifier* clone() const = 0;
virtual scalar defuzzify(const Term* term, scalar minimum, scalar maximum) const = 0;
};
}
#endif /* FL_DEFUZZIFIER_H */

View File

@ -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.
*/
#ifndef FL_INTEGRALDEFUZZIFIER_H
#define FL_INTEGRALDEFUZZIFIER_H
#include "fl/defuzzifier/Defuzzifier.h"
namespace fl {
//TODO: check http://en.wikipedia.org/wiki/Adaptive_quadrature
class FL_API IntegralDefuzzifier : public Defuzzifier {
protected:
static int _defaultResolution;
int _resolution;
public:
static void setDefaultResolution(int defaultResolution);
static int defaultResolution();
explicit IntegralDefuzzifier(int resolution = defaultResolution());
virtual ~IntegralDefuzzifier() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(IntegralDefuzzifier)
virtual void setResolution(int resolution);
virtual int getResolution() const;
};
}
#endif /* INTEGRALDEFUZZIFIER_H */

View File

@ -0,0 +1,47 @@
/*
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.
*/
#ifndef FL_LARGESTOFMAXIMUM_H
#define FL_LARGESTOFMAXIMUM_H
#include "fl/defuzzifier/IntegralDefuzzifier.h"
namespace fl {
class FL_API LargestOfMaximum : public IntegralDefuzzifier {
public:
explicit LargestOfMaximum(int resolution = defaultResolution());
virtual ~LargestOfMaximum() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(LargestOfMaximum)
virtual std::string className() const FL_IOVERRIDE;
virtual scalar defuzzify(const Term* term,
scalar minimum, scalar maximum) const FL_IOVERRIDE;
virtual LargestOfMaximum* clone() const FL_IOVERRIDE;
static Defuzzifier* constructor();
};
}
#endif /* FL_LARGESTOFMAXIMUM_H */

View File

@ -0,0 +1,48 @@
/*
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.
*/
#ifndef FL_MEANOFMAXIMUM_H
#define FL_MEANOFMAXIMUM_H
#include "fl/defuzzifier/IntegralDefuzzifier.h"
namespace fl {
class FL_API MeanOfMaximum : public IntegralDefuzzifier {
public:
explicit MeanOfMaximum(int resolution = defaultResolution());
virtual ~MeanOfMaximum() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(MeanOfMaximum)
virtual std::string className() const FL_IOVERRIDE;
virtual scalar defuzzify(const Term* term,
scalar minimum, scalar maximum) const FL_IOVERRIDE;
virtual MeanOfMaximum* clone() const FL_IOVERRIDE;
static Defuzzifier* constructor();
};
}
#endif /* FL_MEANOFMAXIMUM_H */

View File

@ -0,0 +1,48 @@
/*
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.
*/
#ifndef FL_SMALLESTOFMAXIMUM_H
#define FL_SMALLESTOFMAXIMUM_H
#include "fl/defuzzifier/IntegralDefuzzifier.h"
namespace fl {
class FL_API SmallestOfMaximum : public IntegralDefuzzifier {
public:
explicit SmallestOfMaximum(int resolution = defaultResolution());
virtual ~SmallestOfMaximum() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(SmallestOfMaximum)
virtual std::string className() const FL_IOVERRIDE;
virtual scalar defuzzify(const Term* term,
scalar minimum, scalar maximum) const FL_IOVERRIDE;
virtual SmallestOfMaximum* clone() const FL_IOVERRIDE;
static Defuzzifier* constructor();
};
}
#endif /* FL_SMALLESTOFMAXIMUM_H */

View File

@ -0,0 +1,50 @@
/*
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.
*/
#ifndef FL_WEIGHTEDAVERAGE_H
#define FL_WEIGHTEDAVERAGE_H
#include "fl/defuzzifier/WeightedDefuzzifier.h"
namespace fl {
class Activated;
class FL_API WeightedAverage : public WeightedDefuzzifier {
public:
explicit WeightedAverage(Type type = Automatic);
explicit WeightedAverage(const std::string& type);
virtual ~WeightedAverage() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(WeightedAverage)
virtual std::string className() const FL_IOVERRIDE;
virtual scalar defuzzify(const Term* term,
scalar minimum, scalar maximum) const FL_IOVERRIDE;
virtual WeightedAverage* clone() const FL_IOVERRIDE;
static Defuzzifier* constructor();
};
}
#endif /* FL_WEIGHTEDAVERAGE_H */

View File

@ -0,0 +1,63 @@
/*
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.
*/
#ifndef FL_WEIGHTEDDEFUZZIFIER_H
#define FL_WEIGHTEDDEFUZZIFIER_H
#include "fl/defuzzifier/Defuzzifier.h"
namespace fl {
class Activated;
class FL_API WeightedDefuzzifier : public Defuzzifier {
public:
enum Type {
Automatic, TakagiSugeno, Tsukamoto
};
static std::string typeName(Type);
explicit WeightedDefuzzifier(Type type = Automatic);
explicit WeightedDefuzzifier(const std::string& type);
virtual ~WeightedDefuzzifier() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(WeightedDefuzzifier)
virtual void setType(Type type);
virtual Type getType() const;
virtual std::string getTypeName() const;
virtual Type inferType(const Term* term) const;
virtual bool isMonotonic(const Term* term) const;
virtual scalar tsukamoto(const Term* monotonic, scalar activationDegree,
scalar minimum, scalar maximum) const;
protected:
Type _type;
};
}
#endif /* FL_WEIGHTEDDEFUZZIFIER_H */

View File

@ -0,0 +1,50 @@
/*
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.
*/
#ifndef FL_WEIGHTEDSUM_H
#define FL_WEIGHTEDSUM_H
#include "fl/defuzzifier/WeightedDefuzzifier.h"
namespace fl {
class FL_API WeightedSum : public WeightedDefuzzifier {
public:
explicit WeightedSum(Type type = Automatic);
explicit WeightedSum(const std::string& type);
virtual ~WeightedSum() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(WeightedSum)
virtual std::string className() const FL_IOVERRIDE;
virtual scalar defuzzify(const Term* term,
scalar minimum, scalar maximum) const FL_IOVERRIDE;
virtual WeightedSum* clone() const FL_IOVERRIDE;
static Defuzzifier* constructor();
};
}
#endif /* FL_WEIGHTEDSUM_H */

View File

@ -0,0 +1,62 @@
/*
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.
*/
#ifndef FL_CLONINGFACTORY_H
#define FL_CLONINGFACTORY_H
#include "fl/fuzzylite.h"
#include <map>
#include <string>
#include <vector>
namespace fl {
template <typename T>
class FL_API CloningFactory {
protected:
std::string _name;
std::map<std::string, T> _objects;
public:
explicit CloningFactory(const std::string& name = "");
CloningFactory(const CloningFactory& other);
CloningFactory& operator=(const CloningFactory& other);
virtual ~CloningFactory();
FL_DEFAULT_MOVE(CloningFactory)
virtual std::string name() const;
virtual void registerObject(const std::string& key, T object);
virtual void deregisterObject(const std::string& key);
virtual bool hasObject(const std::string& key) const;
virtual T getObject(const std::string& key) const;
virtual T cloneObject(const std::string& key) const;
virtual std::vector<std::string> available() const;
};
}
#endif /* FL_CLONINGFACTORY_H */

View File

@ -0,0 +1,64 @@
/*
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.
*/
#ifndef FL_FACTORY_H
#define FL_FACTORY_H
#include "fl/fuzzylite.h"
#include <map>
#include <string>
#include <vector>
namespace fl {
template <typename T>
class FL_API ConstructionFactory {
public:
typedef T(*Constructor)();
protected:
std::string _name;
std::map<std::string, Constructor> _constructors;
public:
explicit ConstructionFactory(const std::string& name);
virtual ~ConstructionFactory();
FL_DEFAULT_COPY_AND_MOVE(ConstructionFactory)
virtual std::string name() const;
virtual void registerConstructor(const std::string& key, Constructor constructor);
virtual void deregisterConstructor(const std::string& key);
virtual bool hasConstructor(const std::string& key) const;
virtual Constructor getConstructor(const std::string& key) const;
virtual T constructObject(const std::string& key) const;
virtual std::vector<std::string> available() const;
};
}
#endif /* FL_FACTORY_H */

View File

@ -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.
*/
#ifndef FL_DEFUZZIFIERFACTORY_H
#define FL_DEFUZZIFIERFACTORY_H
#include "fl/factory/ConstructionFactory.h"
#include "fl/defuzzifier/Defuzzifier.h"
#include "fl/defuzzifier/IntegralDefuzzifier.h"
#include "fl/defuzzifier/WeightedDefuzzifier.h"
namespace fl {
class FL_API DefuzzifierFactory : public ConstructionFactory<Defuzzifier*> {
public:
DefuzzifierFactory();
virtual ~DefuzzifierFactory() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(DefuzzifierFactory)
virtual Defuzzifier* constructDefuzzifier(const std::string& key,
int resolution, WeightedDefuzzifier::Type) const;
virtual Defuzzifier* constructDefuzzifier(const std::string& key, int resolution) const;
virtual Defuzzifier* constructDefuzzifier(const std::string& key, WeightedDefuzzifier::Type type);
};
}
#endif /* DEFUZZIFIERFACTORY_H */

View File

@ -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.
*/
#ifndef FL_FACTORYMANAGER_H
#define FL_FACTORYMANAGER_H
#include "fl/fuzzylite.h"
namespace fl {
class TNormFactory;
class SNormFactory;
class DefuzzifierFactory;
class TermFactory;
class HedgeFactory;
class FunctionFactory;
class FL_API FactoryManager {
protected:
static FactoryManager _instance;
FL_unique_ptr<TNormFactory> _tnorm;
FL_unique_ptr<SNormFactory> _snorm;
FL_unique_ptr<DefuzzifierFactory> _defuzzifier;
FL_unique_ptr<TermFactory> _term;
FL_unique_ptr<HedgeFactory> _hedge;
FL_unique_ptr<FunctionFactory> _function;
FactoryManager();
FactoryManager(TNormFactory* tnorm, SNormFactory* snorm,
DefuzzifierFactory* defuzzifier, TermFactory* term,
HedgeFactory* hedge, FunctionFactory* function);
FactoryManager(const FactoryManager& other);
FactoryManager& operator=(const FactoryManager& other);
FL_DEFAULT_MOVE(FactoryManager)
virtual ~FactoryManager();
public:
static FactoryManager* instance();
virtual void setTnorm(TNormFactory* tnorm);
virtual TNormFactory* tnorm() const;
virtual void setSnorm(SNormFactory* snorm);
virtual SNormFactory* snorm() const;
virtual void setDefuzzifier(DefuzzifierFactory* defuzzifier);
virtual DefuzzifierFactory* defuzzifier() const;
virtual void setTerm(TermFactory* term);
virtual TermFactory* term() const;
virtual void setHedge(HedgeFactory* hedge);
virtual HedgeFactory* hedge() const;
virtual void setFunction(FunctionFactory* function);
virtual FunctionFactory* function() const;
};
}
#endif /* FL_FACTORYMANAGER_H */

View File

@ -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.
*/
#ifndef FL_FUNCTIONFACTORY_H
#define FL_FUNCTIONFACTORY_H
#include "fl/factory/CloningFactory.h"
#include "fl/term/Function.h"
namespace fl {
class FunctionFactory : public CloningFactory<Function::Element*> {
private:
void registerOperators();
void registerFunctions();
public:
FunctionFactory();
virtual ~FunctionFactory() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FunctionFactory)
virtual std::vector<std::string> availableOperators() const;
virtual std::vector<std::string> availableFunctions() const;
};
}
#endif /* FL_FUNCTIONFACTORY_H */

View File

@ -0,0 +1,42 @@
/*
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.
*/
#ifndef FL_HEDGEFACTORY_H
#define FL_HEDGEFACTORY_H
#include "fl/factory/ConstructionFactory.h"
#include "fl/hedge/Hedge.h"
namespace fl {
class FL_API HedgeFactory : public ConstructionFactory<Hedge*> {
public:
HedgeFactory();
virtual ~HedgeFactory() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(HedgeFactory)
};
}
#endif /* FL_HEDGEFACTORY_H */

View File

@ -0,0 +1,42 @@
/*
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.
*/
#ifndef FL_SNORMFACTORY_H
#define FL_SNORMFACTORY_H
#include "fl/factory/ConstructionFactory.h"
#include "fl/norm/SNorm.h"
namespace fl {
class FL_API SNormFactory : public ConstructionFactory<SNorm*> {
public:
SNormFactory();
virtual ~SNormFactory() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(SNormFactory)
};
}
#endif /* FL_SNORMFACTORY_H */

View File

@ -0,0 +1,42 @@
/*
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.
*/
#ifndef FL_TNORMFACTORY_H
#define FL_TNORMFACTORY_H
#include "fl/factory/ConstructionFactory.h"
#include "fl/norm/TNorm.h"
namespace fl {
class FL_API TNormFactory : public ConstructionFactory<TNorm*> {
public:
TNormFactory();
virtual ~TNormFactory() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(TNormFactory)
};
}
#endif /* FL_TNORMFACTORY_H */

View File

@ -0,0 +1,43 @@
/*
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.
*/
#ifndef FL_TERMFACTORY_H
#define FL_TERMFACTORY_H
#include "fl/factory/ConstructionFactory.h"
#include "fl/term/Term.h"
namespace fl {
class FL_API TermFactory : public ConstructionFactory<Term*> {
public:
TermFactory();
virtual ~TermFactory() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(TermFactory)
};
}
#endif /* FL_TERMFACTORY_H */

222
dep/fl/fuzzylite.h Normal file
View File

@ -0,0 +1,222 @@
/*
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.
*/
#ifndef FL_FUZZYLITE_H
#define FL_FUZZYLITE_H
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <limits>
#include <memory>
#ifndef FL_VERSION
#define FL_VERSION "?"
#endif
#ifndef FL_DATE
#define FL_DATE "?"
#endif
#ifndef FL_BUILD_PATH
#define FL_BUILD_PATH ""
#endif
#if defined(_WIN32) || defined(WIN32)
#define FL_WINDOWS
#endif
#if defined(unix) || defined(__unix__) || defined(__unix)
#define FL_UNIX
#endif
#ifdef __APPLE__
#define FL_APPLE
#endif
#define FL__FILE__ std::string(__FILE__).substr(std::string(FL_BUILD_PATH).size())
#define FL_LOG_PREFIX FL__FILE__ << " [" << __LINE__ << "]:"
#define FL_AT FL__FILE__, __LINE__, __FUNCTION__
#define FL_LOG(message) {if (fl::fuzzylite::logging()){std::cout << FL_LOG_PREFIX << message << std::endl;}}
#define FL_LOGP(message) {if (fl::fuzzylite::logging()){std::cout << message << std::endl;}}
#define FL_DEBUG_BEGIN if (fl::fuzzylite::debug()){
#define FL_DEBUG_END }
#define FL_DBG(message) FL_DEBUG_BEGIN\
std::cout << FL__FILE__ << "::" << __FUNCTION__ << "[" << __LINE__ << "]:" \
<< message << std::endl;\
FL_DEBUG_END
#ifdef FL_WINDOWS
#include <ciso646> //alternative operator spellings:
//#define and &&
//#define or ||
//#define not !
//#define bitand &
//#define bitor |
//TODO: Address warning 4251 by exporting members?
//http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html
#ifdef _MSC_VER
#pragma warning (disable:4251)
#endif
//fuzzylite as a shared library is exported
//Applications linking with fuzzylite as a shared library need to import
//fuzzylite as a static library does not export or import
//Applications linking with fuzzylite as a static library do not import
#if defined(FL_EXPORT_LIBRARY)
#define FL_API __declspec(dllexport)
#elif defined(FL_IMPORT_LIBRARY)
#define FL_API __declspec(dllimport)
#else
#define FL_API
#endif
#else
#define FL_API
#endif
namespace fl {
#ifdef FL_USE_FLOAT
typedef float scalar;
#else
typedef double scalar;
#endif
const scalar nan = std::numeric_limits<scalar>::quiet_NaN();
const scalar inf = std::numeric_limits<scalar>::infinity();
#ifdef FL_CPP11
//C++11 defines
//Pointers
const std::nullptr_t null = nullptr;
#define FL_unique_ptr std::unique_ptr
#define FL_move_ptr(x) std::move(x)
//Identifiers
#define FL_IOVERRIDE override
#define FL_IFINAL final
#define FL_IDEFAULT = default
#define FL_IDELETE = delete
#define FL_INOEXCEPT noexcept
//Constructors
#define FL_DEFAULT_COPY(Class) \
Class(const Class&) = default; \
Class& operator=(const Class&) = default;
#define FL_DEFAULT_MOVE(Class) \
Class(Class&&) = default; \
Class& operator=(Class&&) = default;
#define FL_DEFAULT_COPY_AND_MOVE(Class) \
Class(const Class&) = default; \
Class& operator=(const Class&) = default;\
Class(Class&&) = default; \
Class& operator=(Class&&) = default;
#define FL_DISABLE_COPY(Class) \
Class(const Class &) = delete;\
Class &operator=(const Class &) = delete;
#else
//C++98 defines
//Pointers
const long null = 0L;
#define FL_unique_ptr std::auto_ptr
#define FL_move_ptr(x) x
//Identifiers
#define FL_IOVERRIDE
#define FL_IFINAL
#define FL_IDEFAULT
#define FL_IDELETE
#define FL_INOEXCEPT throw()
//Constructors
#define FL_DEFAULT_COPY(Class)
#define FL_DEFAULT_MOVE(Class)
#define FL_DEFAULT_COPY_AND_MOVE(Class)
#define FL_DISABLE_COPY(Class) \
Class(const Class &);\
Class &operator=(const Class &);
#endif
}
namespace fl {
class FL_API fuzzylite {
protected:
static int _decimals;
static scalar _macheps;
static bool _debug;
static bool _logging;
public:
static std::string name();
static std::string fullname();
static std::string version();
static std::string longVersion();
static std::string license();
static std::string author();
static std::string company();
static std::string website();
static std::string date();
static std::string platform();
static std::string floatingPoint();
static bool debug();
static void setDebug(bool debug);
static int decimals();
static void setDecimals(int decimals);
static scalar macheps();
static void setMachEps(scalar macheps);
static bool logging();
static void setLogging(bool logging);
};
}
#endif /* FL_FUZZYLITE_H */

47
dep/fl/hedge/Any.h Normal file
View File

@ -0,0 +1,47 @@
/*
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.
*/
#ifndef FL_ANY_H
#define FL_ANY_H
#include "fl/hedge/Hedge.h"
namespace fl {
//Only this hedge has virtual methods due to its special case use.
class FL_API Any : public Hedge {
public:
Any();
virtual ~Any() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Any)
virtual std::string name() const FL_IOVERRIDE;
virtual scalar hedge(scalar x) const FL_IOVERRIDE;
virtual Any* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
}
#endif /* FL_ANY_H */

42
dep/fl/hedge/Extremely.h Normal file
View File

@ -0,0 +1,42 @@
/*
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.
*/
#ifndef FL_EXTREMELY_H
#define FL_EXTREMELY_H
#include "fl/hedge/Hedge.h"
namespace fl {
class FL_API Extremely : public Hedge {
public:
std::string name() const;
scalar hedge(scalar x) const;
Extremely* clone() const;
static Hedge* constructor();
};
}
#endif /* FL_EXTREMELY_H */

51
dep/fl/hedge/Hedge.h Normal file
View File

@ -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.
*/
#ifndef FL_HEDGE_H
#define FL_HEDGE_H
#include "fl/fuzzylite.h"
#include <string>
namespace fl {
class FL_API Hedge {
public:
Hedge() {
}
virtual ~Hedge() {
}
FL_DEFAULT_COPY_AND_MOVE(Hedge)
virtual std::string name() const = 0;
virtual scalar hedge(scalar x) const = 0;
virtual Hedge* clone() const = 0;
};
}
#endif /* FL_HEDGE_H */

42
dep/fl/hedge/Not.h Normal file
View File

@ -0,0 +1,42 @@
/*
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.
*/
#ifndef FL_NOT_H
#define FL_NOT_H
#include "fl/hedge/Hedge.h"
namespace fl {
class FL_API Not : public Hedge {
public:
std::string name() const FL_IOVERRIDE;
scalar hedge(scalar x) const FL_IOVERRIDE;
Not* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
}
#endif /* FL_NOT_H */

42
dep/fl/hedge/Seldom.h Normal file
View File

@ -0,0 +1,42 @@
/*
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.
*/
#ifndef FL_SELDOM_H
#define FL_SELDOM_H
#include "fl/hedge/Hedge.h"
namespace fl {
class FL_API Seldom : public Hedge {
public:
std::string name() const FL_IOVERRIDE;
scalar hedge(scalar x) const FL_IOVERRIDE;
Seldom* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
}
#endif /* FL_SELDOM_H */

42
dep/fl/hedge/Somewhat.h Normal file
View File

@ -0,0 +1,42 @@
/*
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.
*/
#ifndef FL_SOMEWHAT_H
#define FL_SOMEWHAT_H
#include "fl/hedge/Hedge.h"
namespace fl {
class FL_API Somewhat : public Hedge {
public:
std::string name() const FL_IOVERRIDE;
scalar hedge(scalar x) const FL_IOVERRIDE;
Somewhat* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
}
#endif /* FL_SOMEWHAT_H */

42
dep/fl/hedge/Very.h Normal file
View File

@ -0,0 +1,42 @@
/*
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.
*/
#ifndef FL_VERY_H
#define FL_VERY_H
#include "fl/hedge/Hedge.h"
namespace fl {
class FL_API Very : public Hedge {
public:
std::string name() const FL_IOVERRIDE;
scalar hedge(scalar x) const FL_IOVERRIDE;
Very* clone() const FL_IOVERRIDE;
static Hedge* constructor();
};
}
#endif /* FL_VERY_H */

70
dep/fl/imex/CppExporter.h Normal file
View File

@ -0,0 +1,70 @@
/*
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.
*/
#ifndef FL_CPPEXPORTER_H
#define FL_CPPEXPORTER_H
#include "fl/imex/Exporter.h"
namespace fl {
class Engine;
class InputVariable;
class OutputVariable;
class Term;
class RuleBlock;
class Norm;
class Defuzzifier;
class Hedge;
class FL_API CppExporter : public Exporter {
protected:
bool _prefixNamespace;
virtual std::string fl(const std::string& clazz) const;
public:
explicit CppExporter(bool prefixNamespace = false);
virtual ~CppExporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(CppExporter)
virtual std::string name() const FL_IOVERRIDE;
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
virtual void setPrefixNamespace(bool prefixNamespace);
virtual bool isPrefixNamespace() const;
virtual std::string toString(const InputVariable* inputVariable, const Engine* engine) const;
virtual std::string toString(const OutputVariable* outputVariable, const Engine* engine) const;
virtual std::string toString(const RuleBlock* ruleBlock, const Engine* engine) const;
virtual std::string toString(scalar value) const;
virtual std::string toString(const Hedge* hedge) const;
virtual std::string toString(const Term* term) const;
virtual std::string toString(const Norm* op) const;
virtual std::string toString(const Defuzzifier* defuzzifier) const;
virtual CppExporter* clone() const FL_IOVERRIDE;
};
}
#endif /* FL_CPPEXPORTER_H */

52
dep/fl/imex/Exporter.h Normal file
View File

@ -0,0 +1,52 @@
/*
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.
*/
#ifndef FL_EXPORTER_H
#define FL_EXPORTER_H
#include "fl/fuzzylite.h"
#include <string>
namespace fl {
class Engine;
class FL_API Exporter {
public:
Exporter();
virtual ~Exporter();
FL_DEFAULT_COPY_AND_MOVE(Exporter)
virtual std::string toString(const Engine* engine) const = 0;
virtual void toFile(const std::string& path, const Engine* engine) const;
virtual std::string name() const = 0;
virtual Exporter* clone() const = 0;
};
}
#endif /* FL_EXPORTER_H */

70
dep/fl/imex/FclExporter.h Normal file
View File

@ -0,0 +1,70 @@
/*
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.
*/
#ifndef FL_FCLEXPORTER_H
#define FL_FCLEXPORTER_H
#include "fl/imex/Exporter.h"
namespace fl {
class InputVariable;
class OutputVariable;
class RuleBlock;
class Norm;
class TNorm;
class SNorm;
class Defuzzifier;
class Term;
class FL_API FclExporter : public Exporter {
protected:
std::string _indent;
public:
explicit FclExporter(const std::string& indent = " ");
virtual ~FclExporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FclExporter)
virtual void setIndent(const std::string& indent);
virtual std::string getIndent() const;
virtual std::string name() const FL_IOVERRIDE;
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
virtual std::string toString(const InputVariable* variable) const;
virtual std::string toString(const OutputVariable* variable) const;
virtual std::string toString(const RuleBlock* ruleBlock) const;
virtual std::string toString(const Norm* norm) const;
virtual std::string toString(const TNorm* tnorm) const; //TODO: Delete in v6.0
virtual std::string toString(const SNorm* snorm) const; //TODO: Delete in v6.0
virtual std::string toString(const Defuzzifier* defuzzifier) const;
virtual std::string toString(const Term* term) const;
virtual FclExporter* clone() const FL_IOVERRIDE;
};
}
#endif /* FL_FCLEXPORTER_H */

74
dep/fl/imex/FclImporter.h Normal file
View File

@ -0,0 +1,74 @@
/*
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.
*/
#ifndef FL_FCLIMPORTER_H
#define FL_FCLIMPORTER_H
#include "fl/imex/Importer.h"
#include <string>
#include <utility>
#include <vector>
namespace fl {
class Norm;
class TNorm;
class SNorm;
class Term;
class Defuzzifier;
class FL_API FclImporter : public Importer {
public:
FclImporter();
virtual ~FclImporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FclImporter)
virtual std::string name() const FL_IOVERRIDE;
virtual Engine* fromString(const std::string& fcl) const FL_IOVERRIDE;
virtual FclImporter* clone() const FL_IOVERRIDE;
protected:
virtual void processBlock(const std::string& tag, const std::string& block, Engine* engine) const;
virtual void processVar(const std::string& var, const std::string& block, Engine* engine)const;
virtual void processFuzzify(const std::string& block, Engine* engine)const;
virtual void processDefuzzify(const std::string& block, Engine* engine)const;
virtual void processRuleBlock(const std::string& block, Engine* engine)const;
virtual TNorm* parseTNorm(const std::string& line) const;
virtual SNorm* parseSNorm(const std::string& line) const;
virtual Term* parseTerm(const std::string& line, const Engine* engine) const;
virtual Defuzzifier* parseDefuzzifier(const std::string& line) const;
virtual std::pair<scalar, bool> parseDefaultValue(const std::string& line) const;
virtual std::pair<scalar, scalar> parseRange(const std::string& line) const;
virtual std::pair<bool, bool> parseLocks(const std::string& line) const;
virtual bool parseEnabled(const std::string& line) const;
};
}
#endif /* FL_FCLIMPORTER_H */

74
dep/fl/imex/FisExporter.h Normal file
View File

@ -0,0 +1,74 @@
/*
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.
*/
#ifndef FL_FISEXPORTER_H
#define FL_FISEXPORTER_H
#include "fl/imex/Exporter.h"
#include <vector>
namespace fl {
class Norm;
class TNorm;
class SNorm;
class Defuzzifier;
class Term;
class Rule;
class Proposition;
class Variable;
class FL_API FisExporter : public Exporter {
protected:
virtual std::string translate(const std::vector<Proposition*>& propositions,
const std::vector<Variable*> variables) const;
public:
FisExporter();
virtual ~FisExporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FisExporter)
virtual std::string name() const FL_IOVERRIDE;
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
virtual std::string toString(const Norm* norm) const;
virtual std::string toString(const TNorm* tnorm) const; //TODO: delete in v6.0
virtual std::string toString(const SNorm* snorm) const; //TODO: delete in v6.0
virtual std::string toString(const Defuzzifier* defuzzifier) const;
virtual std::string toString(const Term* term) const;
virtual std::string exportSystem(const Engine* engine) const;
virtual std::string exportInputs(const Engine* engine) const;
virtual std::string exportOutputs(const Engine* engine) const;
virtual std::string exportRules(const Engine* engine) const;
virtual std::string exportRule(const Rule* rule, const Engine* engine) const;
virtual FisExporter* clone() const FL_IOVERRIDE;
};
}
#endif /* FL_FISEXPORTER_H */

79
dep/fl/imex/FisImporter.h Normal file
View File

@ -0,0 +1,79 @@
/*
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.
*/
#ifndef FL_FISIMPORTER_H
#define FL_FISIMPORTER_H
#include "fl/imex/Importer.h"
#include <utility>
#include <vector>
namespace fl {
class Norm;
class TNorm;
class SNorm;
class Term;
class Defuzzifier;
class Variable;
class FL_API FisImporter : public Importer {
public:
FisImporter();
virtual ~FisImporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FisImporter)
virtual std::string name() const FL_IOVERRIDE;
virtual Engine* fromString(const std::string& fcl) const FL_IOVERRIDE;
virtual FisImporter* clone() const FL_IOVERRIDE;
protected:
virtual void importSystem(const std::string& section, Engine* engine,
std::string& andMethod, std::string& orMethod,
std::string& impMethod, std::string& aggMethod,
std::string& defuzzMethod) const;
virtual void importInput(const std::string& section, Engine* engine) const;
virtual void importOutput(const std::string& section, Engine* engine) const;
virtual void importRules(const std::string& section, Engine* engine) const;
virtual std::string translateProposition(scalar code, Variable* variable) const;
//TODO: rename extract to translate in v6.0
virtual std::string extractTNorm(const std::string& tnorm) const;
virtual std::string extractSNorm(const std::string& tnorm) const;
virtual std::string extractDefuzzifier(const std::string& defuzzifier) const;
virtual Term* parseTerm(const std::string& line, const Engine* engine) const;
virtual Term* createInstance(const std::string& termClass, const std::string& name,
const std::vector<std::string>& params, const Engine* engine) const;
//TODO: rename to parseRange in v6.0
virtual std::pair<scalar, scalar> range(const std::string& range) const;
};
}
#endif /* FL_FISIMPORTER_H */

84
dep/fl/imex/FldExporter.h Normal file
View File

@ -0,0 +1,84 @@
/*
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.
*/
#ifndef FL_FLDEXPORTER_H
#define FL_FLDEXPORTER_H
#include "fl/imex/Exporter.h"
#include <vector>
namespace fl {
class Engine;
class InputVariable;
class OutputVariable;
class FL_API FldExporter : public Exporter {
protected:
std::string _separator;
bool _exportHeaders;
bool _exportInputValues;
bool _exportOutputValues;
public:
explicit FldExporter(const std::string& separator = " ");
virtual ~FldExporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FldExporter)
virtual std::string name() const FL_IOVERRIDE;
virtual void setSeparator(const std::string& separator);
virtual std::string getSeparator() const;
virtual void setExportHeader(bool exportHeaders);
virtual bool exportsHeader() const;
virtual void setExportInputValues(bool exportInputValues);
virtual bool exportsInputValues() const;
virtual void setExportOutputValues(bool exportOutputValues);
virtual bool exportsOutputValues() const;
virtual std::string header(const Engine* engine) const;
//WARNING: The engine will be const_casted in order to be processed!
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
virtual std::string toString(Engine* engine, int maximumNumberOfResults) const;
virtual std::string toString(Engine* engine, const std::string& inputData) const;
using Exporter::toFile;
virtual void toFile(const std::string& path, Engine* engine, int maximumNumberOfResults) const;
virtual void toFile(const std::string& path, Engine* engine, const std::string& inputData) const;
virtual std::vector<scalar> parse(const std::string& x) const;
void write(Engine* engine, std::ostream& writer, int maximumNumberOfResults) const;
void write(Engine* engine, std::ostream& writer, std::istream& reader) const;
void write(Engine* engine, std::ostream& writer, const std::vector<scalar>& inputValues) const;
virtual FldExporter* clone() const FL_IOVERRIDE;
};
}
#endif /* FL_FLDEXPORTER_H */

83
dep/fl/imex/FllExporter.h Normal file
View File

@ -0,0 +1,83 @@
/*
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.
*/
#ifndef FL_FLLEXPORTER_H
#define FL_FLLEXPORTER_H
#include "fl/imex/Exporter.h"
#include <vector>
namespace fl {
class Variable;
class InputVariable;
class OutputVariable;
class RuleBlock;
class Rule;
class Norm;
class Defuzzifier;
class Term;
class FL_API FllExporter : public Exporter {
protected:
std::string _indent;
std::string _separator;
public:
explicit FllExporter(const std::string& indent = " ", const std::string& separator = "\n");
virtual ~FllExporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FllExporter)
virtual std::string name() const FL_IOVERRIDE;
virtual void setIndent(const std::string& indent);
virtual std::string getIndent() const;
virtual void setSeparator(const std::string& separator);
virtual std::string getSeparator() const;
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
virtual std::string toString(const std::vector<Variable*>& variables) const;
virtual std::string toString(const std::vector<InputVariable*>& inputVariables) const;
virtual std::string toString(const std::vector<OutputVariable*>& outputVariables) const;
virtual std::string toString(const std::vector<RuleBlock*>& ruleBlocks) const;
virtual std::string toString(const Variable* variable) const;
virtual std::string toString(const InputVariable* inputVariable) const;
virtual std::string toString(const OutputVariable* outputVariable) const;
virtual std::string toString(const RuleBlock* ruleBlock) const;
virtual std::string toString(const Rule* rule) const;
virtual std::string toString(const Norm* norm) const;
virtual std::string toString(const Defuzzifier* defuzzifier) const;
virtual std::string toString(const Term* term) const;
virtual FllExporter* clone() const FL_IOVERRIDE;
};
}
#endif /* FL_FLLEXPORTER_H */

77
dep/fl/imex/FllImporter.h Normal file
View File

@ -0,0 +1,77 @@
/*
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.
*/
#ifndef FL_FLLIMPORTER_H
#define FL_FLLIMPORTER_H
#include "fl/imex/Importer.h"
#include <utility>
namespace fl {
class TNorm;
class SNorm;
class Term;
class Defuzzifier;
class FL_API FllImporter : public Importer {
protected:
std::string _separator;
public:
explicit FllImporter(const std::string& separator = "\n");
virtual ~FllImporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(FllImporter)
virtual void setSeparator(const std::string& separator);
virtual std::string getSeparator() const;
virtual std::string name() const FL_IOVERRIDE;
virtual Engine* fromString(const std::string& fll) const FL_IOVERRIDE;
virtual FllImporter* clone() const FL_IOVERRIDE;
protected:
virtual void process(const std::string& tag, const std::string& block, Engine* engine) const;
virtual void processInputVariable(const std::string& block, Engine* engine) const;
virtual void processOutputVariable(const std::string& block, Engine* engine) const;
virtual void processRuleBlock(const std::string& block, Engine* engine) const;
virtual TNorm* parseTNorm(const std::string& name) const;
virtual SNorm* parseSNorm(const std::string& name) const;
virtual Term* parseTerm(const std::string& text, Engine* engine) const;
virtual Defuzzifier* parseDefuzzifier(const std::string& line) const;
virtual std::pair<scalar, scalar> parseRange(const std::string& line) const;
virtual bool parseBoolean(const std::string& boolean) const;
virtual std::pair<std::string, std::string> parseKeyValue(const std::string& text,
char separator = ':') const;
virtual std::string clean(const std::string& line) const;
};
}
#endif /* FL_FLLIMPORTER_H */

52
dep/fl/imex/Importer.h Normal file
View File

@ -0,0 +1,52 @@
/*
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.
*/
#ifndef FL_IMPORTER_H
#define FL_IMPORTER_H
#include "fl/fuzzylite.h"
#include <string>
namespace fl {
class Engine;
class FL_API Importer {
public:
Importer();
virtual ~Importer();
FL_DEFAULT_COPY_AND_MOVE(Importer)
virtual Engine* fromString(const std::string& s) const = 0;
virtual Engine* fromFile(const std::string& path) const;
virtual std::string name() const = 0;
virtual Importer* clone() const = 0;
};
}
#endif /* IMPORTER_H */

View File

@ -0,0 +1,68 @@
/*
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.
*/
#ifndef FL_JAVAEXPORTER_H
#define FL_JAVAEXPORTER_H
#include "fl/imex/Exporter.h"
namespace fl {
class Engine;
class InputVariable;
class OutputVariable;
class RuleBlock;
class Term;
class Defuzzifier;
class Norm;
class SNorm;
class TNorm;
class FL_API JavaExporter : public Exporter {
public:
JavaExporter();
virtual ~JavaExporter() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(JavaExporter)
virtual std::string name() const FL_IOVERRIDE;
virtual std::string toString(const Engine* engine) const FL_IOVERRIDE;
virtual std::string toString(const InputVariable* inputVariable, const Engine* engine) const;
virtual std::string toString(const OutputVariable* outputVariable, const Engine* engine) const;
virtual std::string toString(const RuleBlock* ruleBlock, const Engine* engine) const;
virtual std::string toString(const Term* term) const;
virtual std::string toString(const Defuzzifier* defuzzifier) const;
virtual std::string toString(const Norm* norm) const;
virtual std::string toString(const SNorm* norm) const;//TODO: delete in v6.0
virtual std::string toString(const TNorm* norm) const;//TODO: delete in v6.0
virtual std::string toString(scalar value) const;
virtual JavaExporter* clone() const FL_IOVERRIDE;
};
}
#endif /* FL_JAVAEXPORTER_H */

55
dep/fl/norm/Norm.h Normal file
View File

@ -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.
*/
#ifndef FL_NORM_H
#define FL_NORM_H
#include "fl/fuzzylite.h"
#include "fl/Operation.h"
#include <string>
namespace fl {
class FL_API Norm {
public:
Norm() {
}
virtual ~Norm() {
}
FL_DEFAULT_COPY_AND_MOVE(Norm)
virtual std::string className() const = 0;
virtual scalar compute(scalar a, scalar b) const = 0;
virtual Norm* clone() const = 0;
};
}
#endif /* FL_NORM_H */

47
dep/fl/norm/SNorm.h Normal file
View File

@ -0,0 +1,47 @@
/*
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.
*/
#ifndef FL_SNORM_H
#define FL_SNORM_H
#include "fl/norm/Norm.h"
namespace fl {
class FL_API SNorm : public Norm {
public:
SNorm() {
}
virtual ~SNorm() FL_IOVERRIDE {
}
FL_DEFAULT_COPY_AND_MOVE(SNorm)
virtual SNorm* clone() const FL_IOVERRIDE = 0;
};
}
#endif /* FL_SNORM_H */

47
dep/fl/norm/TNorm.h Normal file
View File

@ -0,0 +1,47 @@
/*
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.
*/
#ifndef FL_TNORM_H
#define FL_TNORM_H
#include "fl/norm/Norm.h"
namespace fl {
class FL_API TNorm : public Norm {
public:
TNorm() {
}
virtual ~TNorm() FL_IOVERRIDE {
}
FL_DEFAULT_COPY_AND_MOVE(TNorm)
virtual TNorm* clone() const FL_IOVERRIDE = 0;
};
}
#endif /* TNORM_H */

View File

@ -0,0 +1,46 @@
/*
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.
*/
#ifndef FL_ALGEBRAICSUM_H
#define FL_ALGEBRAICSUM_H
#include "fl/norm/SNorm.h"
namespace fl {
class FL_API AlgebraicSum : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
AlgebraicSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
}
#endif /* FL_ALGEBRAICSUM_H */

View File

@ -0,0 +1,43 @@
/*
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.
*/
#ifndef FL_BOUNDEDSUM_H
#define FL_BOUNDEDSUM_H
#include "fl/norm/SNorm.h"
namespace fl {
class FL_API BoundedSum : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
BoundedSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
}
#endif /* FL_BOUNDEDSUM_H */

View File

@ -0,0 +1,43 @@
/*
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.
*/
#ifndef FL_DRASTICSUM_H
#define FL_DRASTICSUM_H
#include "fl/norm/SNorm.h"
namespace fl {
class FL_API DrasticSum : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
DrasticSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
}
#endif /* FL_DRASTICSUM_H */

View File

@ -0,0 +1,44 @@
/*
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.
*/
#ifndef FL_EINSTEINSUM_H
#define FL_EINSTEINSUM_H
#include "fl/norm/SNorm.h"
namespace fl {
class FL_API EinsteinSum : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
EinsteinSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
}
#endif /* FL_EINSTEINSUM_H */

View File

@ -0,0 +1,44 @@
/*
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.
*/
#ifndef FL_HAMACHERSUM_H
#define FL_HAMACHERSUM_H
#include "fl/norm/SNorm.h"
namespace fl {
class FL_API HamacherSum : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
HamacherSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
}
#endif /* FL_HAMACHERSUM_H */

45
dep/fl/norm/s/Maximum.h Normal file
View File

@ -0,0 +1,45 @@
/*
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.
*/
#ifndef FL_MAXIMUM_H
#define FL_MAXIMUM_H
#include "fl/norm/SNorm.h"
namespace fl {
class FL_API Maximum : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
Maximum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
}
#endif /* FL_MAXIMUM_H */

View File

@ -0,0 +1,43 @@
/*
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.
*/
#ifndef FL_NILPOTENTMAXIMUM_H
#define FL_NILPOTENTMAXIMUM_H
#include "fl/norm/SNorm.h"
namespace fl {
class FL_API NilpotentMaximum : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
NilpotentMaximum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
}
#endif /* FL_NILPOTENTMAXIMUM_H */

View File

@ -0,0 +1,44 @@
/*
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.
*/
#ifndef FL_NORMALIZEDSUM_H
#define FL_NORMALIZEDSUM_H
#include "fl/norm/SNorm.h"
namespace fl {
class FL_API NormalizedSum : public SNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
NormalizedSum* clone() const FL_IOVERRIDE;
static SNorm* constructor();
};
}
#endif /* FL_NORMALIZEDSUM_H */

View File

@ -0,0 +1,45 @@
/*
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.
*/
#ifndef FL_ALGEBRAICPRODUCT_H
#define FL_ALGEBRAICPRODUCT_H
#include "fl/norm/TNorm.h"
namespace fl {
class FL_API AlgebraicProduct : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
AlgebraicProduct* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
}
#endif /* FL_ALGEBRAICPRODUCT_H */

View File

@ -0,0 +1,44 @@
/*
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.
*/
#ifndef FL_BOUNDEDDIFFERENCE_H
#define FL_BOUNDEDDIFFERENCE_H
#include "fl/norm/TNorm.h"
namespace fl {
class FL_API BoundedDifference : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
BoundedDifference* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
}
#endif /* FL_BOUNDEDDIFFERENCE_H */

View File

@ -0,0 +1,45 @@
/*
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.
*/
#ifndef FL_DRASTICPRODUCT_H
#define FL_DRASTICPRODUCT_H
#include "fl/norm/TNorm.h"
namespace fl {
class FL_API DrasticProduct : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
DrasticProduct* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
}
#endif /* FL_DRASTICPRODUCT_H */

View File

@ -0,0 +1,45 @@
/*
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.
*/
#ifndef FL_EINSTEINPRODUCT_H
#define FL_EINSTEINPRODUCT_H
#include "fl/norm/TNorm.h"
namespace fl {
class FL_API EinsteinProduct : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
EinsteinProduct* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
}
#endif /* FL_EINSTEINPRODUCT_H */

View File

@ -0,0 +1,44 @@
/*
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.
*/
#ifndef FL_HAMACHERPRODUCT_H
#define FL_HAMACHERPRODUCT_H
#include "fl/norm/TNorm.h"
namespace fl {
class FL_API HamacherProduct : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
HamacherProduct* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
}
#endif /* FL_HAMACHERPRODUCT_H */

44
dep/fl/norm/t/Minimum.h Normal file
View File

@ -0,0 +1,44 @@
/*
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.
*/
#ifndef FL_MINIMUM_H
#define FL_MINIMUM_H
#include "fl/norm/TNorm.h"
namespace fl {
class FL_API Minimum : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
Minimum* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
}
#endif /* FL_MINIMUM_H */

View File

@ -0,0 +1,43 @@
/*
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.
*/
#ifndef FL_NILPOTENTMINIMUM_H
#define FL_NILPOTENTMINIMUM_H
#include "fl/norm/TNorm.h"
namespace fl {
class FL_API NilpotentMinimum : public TNorm {
public:
std::string className() const FL_IOVERRIDE;
scalar compute(scalar a, scalar b) const FL_IOVERRIDE;
NilpotentMinimum* clone() const FL_IOVERRIDE;
static TNorm* constructor();
};
}
#endif /* FL_NILPOTENTMINIMUM_H */

77
dep/fl/rule/Antecedent.h Normal file
View File

@ -0,0 +1,77 @@
/*
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.
*/
#ifndef FL_ANTECEDENT_H
#define FL_ANTECEDENT_H
#include "fl/fuzzylite.h"
#include <string>
namespace fl {
class Engine;
class Rule;
class TNorm;
class SNorm;
class Expression;
class FL_API Antecedent {
protected:
std::string _text;
Expression* _expression;
public:
Antecedent();
virtual ~Antecedent();
virtual void setText(const std::string& text);
virtual std::string getText() const;
virtual Expression* getExpression() const;
virtual bool isLoaded() const;
virtual void unload();
virtual void load(Rule* rule, const Engine* engine);
virtual void load(const std::string& antecedent, Rule* rule, const Engine* engine);
virtual scalar activationDegree(const TNorm* conjunction, const SNorm* disjunction,
const Expression* node) const;
virtual scalar activationDegree(const TNorm* conjunction, const SNorm* disjunction) const;
virtual std::string toString() const;
virtual std::string toPrefix(const Expression* node = fl::null) const;
virtual std::string toInfix(const Expression* node = fl::null) const;
virtual std::string toPostfix(const Expression* node = fl::null) const;
private:
FL_DISABLE_COPY(Antecedent)
};
}
#endif /* FL_ANTECEDENT_H */

68
dep/fl/rule/Consequent.h Normal file
View File

@ -0,0 +1,68 @@
/*
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.
*/
#ifndef FL_CONSEQUENT_H
#define FL_CONSEQUENT_H
#include "fl/fuzzylite.h"
#include <string>
#include <vector>
namespace fl {
class Engine;
class Rule;
class Proposition;
class TNorm;
class FL_API Consequent {
protected:
std::string _text;
std::vector<Proposition*> _conclusions;
public:
Consequent();
virtual ~Consequent();
virtual void setText(const std::string& text);
virtual std::string getText() const;
virtual const std::vector<Proposition*>& conclusions() const;
virtual bool isLoaded();
virtual void unload();
virtual void load(Rule* rule, const Engine* engine);
virtual void load(const std::string& consequent, Rule* rule, const Engine* engine);
virtual void modify(scalar activationDegree, const TNorm* activation);
virtual std::string toString() const;
private:
FL_DISABLE_COPY(Consequent)
};
}
#endif /* FL_CONSEQUENT_H */

84
dep/fl/rule/Expression.h Normal file
View File

@ -0,0 +1,84 @@
/*
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.
*/
#ifndef FL_EXPRESSION_H
#define FL_EXPRESSION_H
#include "fl/fuzzylite.h"
#include <string>
#include <vector>
namespace fl {
class Variable;
class Hedge;
class Term;
class FL_API Expression {
public:
Expression();
virtual ~Expression();
virtual std::string toString() const = 0;
private:
FL_DISABLE_COPY(Expression)
};
class FL_API Proposition : public Expression {
public:
Variable* variable;
std::vector<Hedge*> hedges;
Term* term;
Proposition();
virtual ~Proposition() FL_IOVERRIDE;
virtual std::string toString() const FL_IOVERRIDE;
private:
FL_DISABLE_COPY(Proposition)
};
class FL_API Operator : public Expression {
public:
std::string name;
Expression* left;
Expression* right;
Operator();
virtual ~Operator() FL_IOVERRIDE;
virtual std::string toString() const FL_IOVERRIDE;
private:
FL_DISABLE_COPY(Operator)
};
}
#endif /* FL_FUZZYEXPRESSION_H */

121
dep/fl/rule/Rule.h Normal file
View File

@ -0,0 +1,121 @@
/*
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.
*/
#ifndef FL_RULE_H
#define FL_RULE_H
#include "fl/fuzzylite.h"
#include <map>
#include <string>
namespace fl {
class Engine;
class Antecedent;
class Consequent;
class Hedge;
class TNorm;
class SNorm;
class FL_API Rule {
protected:
std::string _text;
scalar _weight;
FL_unique_ptr<Antecedent> _antecedent;
FL_unique_ptr<Consequent> _consequent;
std::map<std::string, Hedge*> _hedges;
public:
explicit Rule(const std::string& text = "", scalar weight = 1.0);
Rule(const Rule& other);
Rule& operator=(const Rule& other);
virtual ~Rule();
FL_DEFAULT_MOVE(Rule)
virtual void setText(const std::string& text);
virtual std::string getText() const;
virtual void setWeight(scalar weight);
virtual scalar getWeight() const;
virtual void setAntecedent(Antecedent* antecedent);
virtual Antecedent* getAntecedent() const;
virtual void setConsequent(Consequent* consequent);
virtual Consequent* getConsequent() const;
virtual void addHedge(Hedge* hedge);
virtual Hedge* getHedge(const std::string& name) const;
virtual Hedge* removeHedge(const std::string& hedge);
virtual bool hasHedge(const std::string& name) const;
virtual int numberOfHedges() const;
virtual void setHedges(const std::map<std::string, Hedge*>& hedges);
virtual const std::map<std::string, Hedge*>& hedges() const;
virtual std::map<std::string, Hedge*>& hedges();
virtual scalar activationDegree(const TNorm* conjunction, const SNorm* disjunction) const;
virtual void activate(scalar degree, const TNorm* activation) const;
virtual std::string toString() const;
virtual bool isLoaded() const;
virtual void unload();
virtual void load(const Engine* engine);
virtual void load(const std::string& rule, const Engine* engine);
virtual Rule* clone() const;
static Rule* parse(const std::string& rule, const Engine* engine);
static std::string ifKeyword() {
return "if";
}
static std::string isKeyword() {
return "is";
}
static std::string thenKeyword() {
return "then";
}
static std::string andKeyword() {
return "and";
}
static std::string orKeyword() {
return "or";
}
static std::string withKeyword() {
return "with";
}
};
}
#endif /* FL_RULE_H */

97
dep/fl/rule/RuleBlock.h Normal file
View File

@ -0,0 +1,97 @@
/*
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.
*/
#ifndef FL_RULEBLOCK_H
#define FL_RULEBLOCK_H
#include "fl/fuzzylite.h"
#include <string>
#include <vector>
namespace fl {
class Engine;
class Rule;
class TNorm;
class SNorm;
class FL_API RuleBlock {
private:
void copyFrom(const RuleBlock& source);
protected:
std::string _name;
std::vector<Rule*> _rules;
FL_unique_ptr<TNorm> _conjunction;
FL_unique_ptr<SNorm> _disjunction;
FL_unique_ptr<TNorm> _activation;
bool _enabled;
public:
explicit RuleBlock(const std::string& name = "");
RuleBlock(const RuleBlock& other);
RuleBlock& operator=(const RuleBlock& other);
virtual ~RuleBlock();
FL_DEFAULT_MOVE(RuleBlock)
virtual void activate();
virtual void setName(std::string name);
virtual std::string getName() const;
virtual void setConjunction(TNorm* conjunction);
virtual TNorm* getConjunction() const;
virtual void setDisjunction(SNorm* disjunction);
virtual SNorm* getDisjunction() const;
virtual void setActivation(TNorm* activation);
virtual TNorm* getActivation() const;
virtual void setEnabled(bool enabled);
virtual bool isEnabled() const;
virtual void unloadRules() const;
virtual void loadRules(const Engine* engine);
virtual void reloadRules(const Engine* engine);
virtual std::string toString() const;
/**
* Operations for iterable datatype _rules
*/
virtual void addRule(Rule* rule);
virtual void insertRule(Rule* rule, int index);
virtual Rule* getRule(int index) const;
virtual Rule* removeRule(int index);
virtual int numberOfRules() const;
virtual void setRules(const std::vector<Rule*>& rules);
virtual const std::vector<Rule*>& rules() const;
virtual std::vector<Rule*>& rules();
};
}
#endif /* RULEBLOCK_H */

94
dep/fl/term/Accumulated.h Normal file
View File

@ -0,0 +1,94 @@
/*
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.
*/
#ifndef FL_ACCUMULATED_H
#define FL_ACCUMULATED_H
#include "fl/term/Term.h"
#include <vector>
namespace fl {
class Activated;
class SNorm;
class TNorm;
class FL_API Accumulated : public Term {
private:
void copyFrom(const Accumulated& source);
protected:
std::vector<Activated*> _terms;
scalar _minimum, _maximum;
FL_unique_ptr<SNorm> _accumulation;
public:
explicit Accumulated(const std::string& name = "",
scalar minimum = fl::nan,
scalar maximum = fl::nan,
SNorm* accumulation = fl::null);
Accumulated(const Accumulated& other);
Accumulated& operator=(const Accumulated& other);
virtual ~Accumulated() FL_IOVERRIDE;
FL_DEFAULT_MOVE(Accumulated)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual Accumulated* clone() const FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual scalar activationDegree(const Term* forTerm) const;
virtual std::string toString() const FL_IOVERRIDE;
virtual void setMinimum(scalar minimum);
virtual scalar getMinimum() const;
virtual void setMaximum(scalar maximum);
virtual scalar getMaximum() const;
virtual void setRange(scalar minimum, scalar maximum);
virtual scalar range() const;
virtual void setAccumulation(SNorm* accumulation);
virtual SNorm* getAccumulation() const;
/**
* Operations for std::vector _terms
*/
virtual void addTerm(const Term* term, scalar degree, const TNorm* activation);
virtual void addTerm(Activated* term);
virtual Activated* getTerm(int index) const;
virtual Activated* removeTerm(int index);
virtual int numberOfTerms() const;
virtual const std::vector<Activated*>& terms() const;
virtual std::vector<Activated*>& terms();
virtual bool isEmpty() const;
virtual void clear();
};
}
#endif /* FL_ACCUMULATED_H */

65
dep/fl/term/Activated.h Normal file
View File

@ -0,0 +1,65 @@
/*
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.
*/
#ifndef FL_ACTIVATED_H
#define FL_ACTIVATED_H
#include "fl/term/Term.h"
namespace fl {
class TNorm;
class FL_API Activated : public Term {
protected:
const Term* _term;
scalar _degree;
const TNorm* _activation;
public:
explicit Activated(const Term* term = fl::null, scalar degree = 1.0,
const TNorm* activationOperator = fl::null);
virtual ~Activated() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Activated)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual std::string toString() const FL_IOVERRIDE;
virtual void setTerm(const Term* term);
virtual const Term* getTerm() const;
virtual void setDegree(scalar degree);
virtual scalar getDegree() const;
virtual void setActivation(const TNorm* activation);
virtual const TNorm* getActivation() const;
virtual Activated* clone() const FL_IOVERRIDE;
};
}
#endif /* FL_ACTIVATED_H */

68
dep/fl/term/Bell.h Normal file
View File

@ -0,0 +1,68 @@
/*
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.
*/
#ifndef FL_BELL_H
#define FL_BELL_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Bell : public Term {
protected:
scalar _center;
scalar _width;
scalar _slope;
public:
explicit Bell(const std::string& name = "",
scalar center = fl::nan,
scalar width = fl::nan,
scalar slope = fl::nan,
scalar height = 1.0);
virtual ~Bell() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Bell)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setCenter(scalar center);
virtual scalar getCenter() const;
virtual void setWidth(scalar width);
virtual scalar getWidth() const;
virtual void setSlope(scalar slope);
virtual scalar getSlope() const;
virtual Bell* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_BELL_H */

64
dep/fl/term/Concave.h Normal file
View File

@ -0,0 +1,64 @@
/*
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.
*/
#ifndef FL_CONCAVE_H
#define FL_CONCAVE_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Concave : public Term {
protected:
scalar _inflection, _end;
public:
explicit Concave(const std::string& name = "",
scalar inflection = fl::nan,
scalar end = fl::nan,
scalar height = 1.0);
virtual ~Concave() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Concave)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setInflection(scalar inflection);
virtual scalar getInflection() const;
virtual void setEnd(scalar end);
virtual scalar getEnd() const;
virtual Concave* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_CONCAVE_H */

58
dep/fl/term/Constant.h Normal file
View File

@ -0,0 +1,58 @@
/*
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.
*/
#ifndef FL_CONSTANT_H
#define FL_CONSTANT_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Constant : public Term {
protected:
scalar _value;
public:
explicit Constant(const std::string& name = "",
scalar value = fl::nan);
virtual ~Constant() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Constant)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setValue(scalar value);
virtual scalar getValue() const;
virtual Constant* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_CONSTANT_H */

62
dep/fl/term/Cosine.h Normal file
View File

@ -0,0 +1,62 @@
/*
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.
*/
#ifndef FL_COSINE_H
#define FL_COSINE_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Cosine : public Term {
protected:
scalar _center, _width;
public:
explicit Cosine(const std::string& name = "",
scalar center = fl::nan,
scalar width = fl::nan,
scalar height = 1.0);
virtual ~Cosine() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Cosine)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setCenter(scalar center);
virtual scalar getCenter() const;
virtual void setWidth(scalar width);
virtual scalar getWidth() const;
virtual Cosine* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_COSINE_H */

81
dep/fl/term/Discrete.h Normal file
View File

@ -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.
*/
#ifndef FL_DISCRETE_H
#define FL_DISCRETE_H
#include "fl/term/Term.h"
#include <vector>
#include <utility>
namespace fl {
class FL_API Discrete : public Term {
public:
typedef std::pair<scalar, scalar> Pair;
protected:
std::vector<Pair> _xy;
public:
explicit Discrete(const std::string& name = "",
const std::vector<Pair>& xy = std::vector<Pair>(),
scalar height = 1.0);
virtual ~Discrete() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Discrete)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
//Warning: this method is unsafe. Make sure you use it correctly.
template <typename T>
static Discrete* create(const std::string& name, int argc,
T x1, T y1, ...); // throw (fl::Exception);
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setXY(const std::vector<Pair>& pairs);
virtual const std::vector<Pair>& xy() const;
virtual std::vector<Pair>& xy();
virtual const Pair& xy(int index) const;
virtual Pair& xy(int index);
static std::vector<scalar> toVector(const std::vector<Pair>& xy);
static std::vector<Pair> toPairs(const std::vector<scalar>& xy);
static std::vector<Pair> toPairs(const std::vector<scalar>& xy,
scalar missingValue) FL_INOEXCEPT;
static std::string formatXY(const std::vector<Pair>& xy,
const std::string& prefix = "(", const std::string& innerSeparator = ",",
const std::string& postfix = ")", const std::string& outerSeparator = " ");
virtual Discrete* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_DISCRETE_H */

171
dep/fl/term/Function.h Normal file
View File

@ -0,0 +1,171 @@
/*
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.
*/
#ifndef FL_FUNCTION_H
#define FL_FUNCTION_H
#include "fl/term/Term.h"
#include <map>
#include <string>
namespace fl {
class Engine;
class FL_API Function : public Term {
/****************************
* Parsing Elements
****************************/
public:
typedef scalar(*Unary)(scalar);
typedef scalar(*Binary)(scalar, scalar);
struct FL_API Element {
enum Type {
OPERATOR, FUNCTION
};
std::string name;
std::string description;
Type type;
Unary unary;
Binary binary;
int arity;
int precedence; //Operator
int associativity;
Element(const std::string& name, const std::string& description, Type type);
Element(const std::string& name, const std::string& description,
Type type, Unary unary, int precedence = 0, int associativity = -1);
Element(const std::string& name, const std::string& description,
Type type, Binary binary, int precedence = 0, int associativity = -1);
virtual ~Element();
FL_DEFAULT_COPY_AND_MOVE(Element)
virtual bool isOperator() const;
virtual bool isFunction() const;
virtual Element* clone() const;
virtual std::string toString() const;
};
/**************************
* Tree elements, wrap Elements into Nodes.
**************************/
struct FL_API Node {
FL_unique_ptr<Element> element;
FL_unique_ptr<Node> left;
FL_unique_ptr<Node> right;
std::string variable;
scalar value;
explicit Node(Element* element, Node* left = fl::null, Node* right = fl::null);
explicit Node(const std::string& variable);
explicit Node(scalar value);
Node(const Node& source);
Node& operator=(const Node& rhs);
virtual ~Node();
FL_DEFAULT_MOVE(Node)
virtual scalar evaluate(const std::map<std::string, scalar>*
variables = fl::null) const;
virtual Node* clone() const;
virtual std::string toString() const;
virtual std::string toPrefix(const Node* node = fl::null) const;
virtual std::string toInfix(const Node* node = fl::null) const;
virtual std::string toPostfix(const Node* node = fl::null) const;
private:
void copyFrom(const Node& source);
};
/******************************
* Term
******************************/
protected:
FL_unique_ptr<Node> _root;
std::string _formula;
const Engine* _engine;
public:
mutable std::map<std::string, scalar> variables;
explicit Function(const std::string& name = "",
const std::string& formula = "", const Engine* engine = fl::null);
Function(const Function& other);
Function& operator=(const Function& other);
virtual ~Function() FL_IOVERRIDE;
FL_DEFAULT_MOVE(Function)
static Function* create(const std::string& name,
const std::string& formula,
const Engine* engine = fl::null); // throw (fl::Exception);
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual scalar evaluate(const std::map<std::string, scalar>* variables) const;
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual void setFormula(const std::string& formula);
virtual std::string getFormula() const;
virtual void setEngine(const Engine* engine);
virtual const Engine* getEngine() const;
virtual Node* root() const;
virtual bool isLoaded() const;
virtual void unload();
virtual void load(); // throw (fl::Exception);
virtual void load(const std::string& formula); // throw (fl::Exception);
virtual void load(const std::string& formula, const Engine* engine); // throw (fl::Exception);
virtual Node* parse(const std::string& formula); // throw (fl::Exception);
virtual std::string toPostfix(const std::string& formula) const; //throw (fl::Exception);
virtual std::string space(const std::string& formula) const;
virtual Function* clone() const FL_IOVERRIDE;
static Term* constructor();
static void main();
};
}
#endif /* FL_FUNCTION_H */

63
dep/fl/term/Gaussian.h Normal file
View File

@ -0,0 +1,63 @@
/*
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.
*/
#ifndef FL_GAUSSIAN_H
#define FL_GAUSSIAN_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Gaussian : public Term {
protected:
scalar _mean;
scalar _standardDeviation;
public:
explicit Gaussian(const std::string& name = "",
scalar mean = fl::nan,
scalar standardDeviation = fl::nan,
scalar height = 1.0);
virtual ~Gaussian() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Gaussian)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setMean(scalar c);
virtual scalar getMean() const;
virtual void setStandardDeviation(scalar sigma);
virtual scalar getStandardDeviation() const;
virtual Gaussian* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_GAUSSIAN_H */

View File

@ -0,0 +1,73 @@
/*
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.
*/
#ifndef FL_GAUSSIANPRODUCT_H
#define FL_GAUSSIANPRODUCT_H
#include "fl/term/Term.h"
namespace fl {
class FL_API GaussianProduct : public Term {
protected:
scalar _meanA;
scalar _standardDeviationA;
scalar _meanB;
scalar _standardDeviationB;
public:
explicit GaussianProduct(const std::string& name = "",
scalar meanA = fl::nan,
scalar standardDeviationA = fl::nan,
scalar meanB = fl::nan,
scalar standardDeviationB = fl::nan,
scalar height = 1.0);
virtual ~GaussianProduct() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(GaussianProduct)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setMeanA(scalar meanA);
virtual scalar getMeanA() const;
virtual void setStandardDeviationA(scalar sigmaA);
virtual scalar getStandardDeviationA() const;
virtual void setMeanB(scalar meanB);
virtual scalar getMeanB() const;
virtual void setStandardDeviationB(scalar sigmaB);
virtual scalar getStandardDeviationB() const;
virtual GaussianProduct* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_GAUSSIANPRODUCT_H */

72
dep/fl/term/Linear.h Normal file
View File

@ -0,0 +1,72 @@
/*
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.
*/
#ifndef FL_LINEAR_H
#define FL_LINEAR_H
#include "fl/term/Term.h"
namespace fl {
class Engine;
class FL_API Linear : public Term {
protected:
std::vector<scalar> _coefficients;
const Engine* _engine;
public:
explicit Linear(const std::string& name = "",
const std::vector<scalar>& coefficients = std::vector<scalar>(),
const Engine* engine = fl::null);
virtual ~Linear() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Linear)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void set(const std::vector<scalar>& coeffs, const Engine* engine);
virtual void setCoefficients(const std::vector<scalar>& coeffs);
virtual const std::vector<scalar>& coefficients() const;
virtual std::vector<scalar>& coefficients();
virtual void setEngine(const Engine* engine);
virtual const Engine* getEngine() const;
virtual Linear* clone() const FL_IOVERRIDE;
static Term* constructor();
//Warning: this method is unsafe, make sure you use it correctly.
template <typename T>
static Linear* create(const std::string& name, const Engine* engine,
T firstCoefficient, ...); // throw (fl::Exception);
};
}
#endif /* FL_LINEAR_H */

74
dep/fl/term/PiShape.h Normal file
View File

@ -0,0 +1,74 @@
/*
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.
*/
#ifndef FL_PISHAPE_H
#define FL_PISHAPE_H
#include "fl/term/Term.h"
namespace fl {
class FL_API PiShape : public Term {
protected:
scalar _bottomLeft;
scalar _topLeft;
scalar _topRight;
scalar _bottomRight;
public:
explicit PiShape(const std::string& name = "",
scalar bottomLeft = fl::nan,
scalar topLeft = fl::nan,
scalar topRight = fl::nan,
scalar bottomRight = fl::nan,
scalar height = 1.0);
virtual ~PiShape() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(PiShape)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setBottomLeft(scalar a);
virtual scalar getBottomLeft() const;
virtual void setTopLeft(scalar b);
virtual scalar getTopLeft() const;
virtual void setTopRight(scalar d);
virtual scalar getTopRight() const;
virtual void setBottomRight(scalar c);
virtual scalar getBottomRight() const;
virtual PiShape* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_PISHAPE_H */

68
dep/fl/term/Ramp.h Normal file
View File

@ -0,0 +1,68 @@
/*
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.
*/
#ifndef FL_RAMP_H
#define FL_RAMP_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Ramp : public Term {
protected:
scalar _start, _end;
public:
enum Direction {
POSITIVE, ZERO, NEGATIVE
};
explicit Ramp(const std::string& name = "",
scalar start = fl::nan,
scalar end = fl::nan,
scalar height = 1.0);
virtual ~Ramp() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Ramp)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setStart(scalar start);
virtual scalar getStart() const;
virtual void setEnd(scalar end);
virtual scalar getEnd() const;
virtual Direction direction() const;
virtual Ramp* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_RAMP_H */

62
dep/fl/term/Rectangle.h Normal file
View File

@ -0,0 +1,62 @@
/*
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.
*/
#ifndef FL_RECTANGLE_H
#define FL_RECTANGLE_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Rectangle : public Term {
protected:
scalar _start, _end;
public:
explicit Rectangle(const std::string& name = "",
scalar start = fl::nan,
scalar end = fl::nan,
scalar height = 1.0);
virtual ~Rectangle() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Rectangle)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setStart(scalar start);
virtual scalar getStart() const;
virtual void setEnd(scalar end);
virtual scalar getEnd() const;
virtual Rectangle* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_RECTANGLE_H */

64
dep/fl/term/SShape.h Normal file
View File

@ -0,0 +1,64 @@
/*
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.
*/
#ifndef FL_SSHAPE_H
#define FL_SSHAPE_H
#include "fl/term/Term.h"
namespace fl {
class FL_API SShape : public Term {
protected:
scalar _start, _end;
public:
explicit SShape(const std::string& name = "",
scalar start = fl::nan,
scalar end = fl::nan,
scalar height = 1.0);
virtual ~SShape() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(SShape)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setStart(scalar start);
virtual scalar getStart() const;
virtual void setEnd(scalar end);
virtual scalar getEnd() const;
virtual SShape* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_SSHAPE_H */

68
dep/fl/term/Sigmoid.h Normal file
View File

@ -0,0 +1,68 @@
/*
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.
*/
#ifndef FL_SIGMOID_H
#define FL_SIGMOID_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Sigmoid : public Term {
protected:
scalar _inflection;
scalar _slope;
public:
enum Direction {
POSITIVE, ZERO, NEGATIVE
};
explicit Sigmoid(const std::string& name = "",
scalar inflection = fl::nan,
scalar slope = fl::nan,
scalar height = 1.0);
virtual ~Sigmoid() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Sigmoid)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setInflection(scalar inflection);
virtual scalar getInflection() const;
virtual void setSlope(scalar slope);
virtual scalar getSlope() const;
virtual Direction direction() const;
virtual Sigmoid* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_SIGMOID_H */

View File

@ -0,0 +1,73 @@
/*
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.
*/
#ifndef FL_SIGMOIDDIFFERENCE_H
#define FL_SIGMOIDDIFFERENCE_H
#include "fl/term/Term.h"
namespace fl {
class FL_API SigmoidDifference : public Term {
protected:
scalar _left;
scalar _rising;
scalar _falling;
scalar _right;
public:
explicit SigmoidDifference(const std::string& name = "",
scalar left = fl::nan,
scalar rising = fl::nan,
scalar falling = fl::nan,
scalar right = fl::nan,
scalar height = 1.0);
virtual ~SigmoidDifference() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(SigmoidDifference)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setLeft(scalar leftInflection);
virtual scalar getLeft() const;
virtual void setRising(scalar risingSlope);
virtual scalar getRising() const;
virtual void setFalling(scalar fallingSlope);
virtual scalar getFalling() const;
virtual void setRight(scalar rightInflection);
virtual scalar getRight() const;
virtual SigmoidDifference* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_SIGMOIDDIFFERENCE_H */

View File

@ -0,0 +1,73 @@
/*
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.
*/
#ifndef FL_SIGMOIDPRODUCT_H
#define FL_SIGMOIDPRODUCT_H
#include "fl/term/Term.h"
namespace fl {
class FL_API SigmoidProduct : public Term {
protected:
scalar _left;
scalar _rising;
scalar _falling;
scalar _right;
public:
explicit SigmoidProduct(const std::string& name = "",
scalar left = fl::nan,
scalar rising = fl::nan,
scalar falling = fl::nan,
scalar right = fl::nan,
scalar height = 1.0);
virtual ~SigmoidProduct() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(SigmoidProduct)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setLeft(scalar leftInflection);
virtual scalar getLeft() const;
virtual void setRising(scalar risingSlope);
virtual scalar getRising() const;
virtual void setFalling(scalar fallingSlope);
virtual scalar getFalling() const;
virtual void setRight(scalar rightInflection);
virtual scalar getRight() const;
virtual SigmoidProduct* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_SIGMOIDPRODUCT_H */

62
dep/fl/term/Spike.h Normal file
View File

@ -0,0 +1,62 @@
/*
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.
*/
#ifndef FL_SPIKE_H
#define FL_SPIKE_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Spike : public Term {
protected:
scalar _center, _width;
public:
explicit Spike(const std::string& name = "",
scalar center = fl::nan,
scalar width = fl::nan,
scalar height = 1.0);
virtual ~Spike() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Spike)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setCenter(scalar center);
virtual scalar getCenter() const;
virtual void setWidth(scalar width);
virtual scalar getWidth() const;
virtual Spike* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_SPIKE_H */

71
dep/fl/term/Term.h Normal file
View File

@ -0,0 +1,71 @@
/*
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.
*/
#ifndef FL_TERM_H
#define FL_TERM_H
#include "fl/fuzzylite.h"
#include "fl/Operation.h"
#include <cmath>
#include <string>
#include <vector>
namespace fl {
class Engine;
class FL_API Term {
protected:
std::string _name;
scalar _height;
public:
explicit Term(const std::string& name = "", scalar height = 1.0);
virtual ~Term();
FL_DEFAULT_COPY_AND_MOVE(Term)
virtual void setName(const std::string& name);
virtual std::string getName() const;
virtual void setHeight(scalar height);
virtual scalar getHeight() const;
virtual std::string toString() const;
virtual std::string className() const = 0;
virtual std::string parameters() const = 0;
virtual void configure(const std::string& parameters) = 0;
virtual scalar membership(scalar x) const = 0;
virtual Term* clone() const = 0;
//FIXME: This should not be static, and may not be here either.
static void updateReference(Term* term, const Engine* engine);
};
}
#endif /* FL_TERM_H */

69
dep/fl/term/Trapezoid.h Normal file
View File

@ -0,0 +1,69 @@
/*
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.
*/
#ifndef FL_TRAPEZOID_H
#define FL_TRAPEZOID_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Trapezoid : public Term {
protected:
scalar _vertexA, _vertexB, _vertexC, _vertexD;
public:
explicit Trapezoid(const std::string& name = "",
scalar vertexA = fl::nan,
scalar vertexB = fl::nan,
scalar vertexC = fl::nan,
scalar vertexD = fl::nan,
scalar height = 1.0);
virtual ~Trapezoid() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Trapezoid)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setVertexA(scalar a);
virtual scalar getVertexA() const;
virtual void setVertexB(scalar b);
virtual scalar getVertexB() const;
virtual void setVertexC(scalar c);
virtual scalar getVertexC() const;
virtual void setVertexD(scalar d);
virtual scalar getVertexD() const;
virtual Trapezoid* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_TRAPEZOID_H */

68
dep/fl/term/Triangle.h Normal file
View File

@ -0,0 +1,68 @@
/*
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.
*/
#ifndef FL_TRIANGLE_H
#define FL_TRIANGLE_H
#include "fl/term/Term.h"
namespace fl {
class FL_API Triangle : public Term {
protected:
scalar _vertexA;
scalar _vertexB;
scalar _vertexC;
public:
explicit Triangle(const std::string& name = "",
scalar vertexA = fl::nan,
scalar vertexB = fl::nan,
scalar vertexC = fl::nan,
scalar height = 1.0);
virtual ~Triangle() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(Triangle)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setVertexA(scalar a);
virtual scalar getVertexA() const;
virtual void setVertexB(scalar b);
virtual scalar getVertexB() const;
virtual void setVertexC(scalar c);
virtual scalar getVertexC() const;
virtual Triangle* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* FL_TRIANGLE_H */

63
dep/fl/term/ZShape.h Normal file
View File

@ -0,0 +1,63 @@
/*
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.
*/
#ifndef FL_ZSHAPE_H
#define FL_ZSHAPE_H
#include "fl/term/Term.h"
namespace fl {
class FL_API ZShape : public Term {
protected:
scalar _start, _end;
public:
explicit ZShape(const std::string& name = "",
scalar _start = fl::nan,
scalar _end = fl::nan,
scalar _height = 1.0);
virtual ~ZShape() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(ZShape)
virtual std::string className() const FL_IOVERRIDE;
virtual std::string parameters() const FL_IOVERRIDE;
virtual void configure(const std::string& parameters) FL_IOVERRIDE;
virtual scalar membership(scalar x) const FL_IOVERRIDE;
virtual void setStart(scalar start);
virtual scalar getStart() const;
virtual void setEnd(scalar end);
virtual scalar getEnd() const;
virtual ZShape* clone() const FL_IOVERRIDE;
static Term* constructor();
};
}
#endif /* ZSHAPE_H */

View File

@ -0,0 +1,52 @@
/*
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.
*/
#ifndef FL_INPUTVARIABLE_H
#define FL_INPUTVARIABLE_H
#include "fl/variable/Variable.h"
namespace fl {
class FL_API InputVariable : public Variable {
protected:
scalar _inputValue;
public:
explicit InputVariable(const std::string& name = "",
scalar minimum = -fl::inf,
scalar maximum = fl::inf);
virtual ~InputVariable() FL_IOVERRIDE;
FL_DEFAULT_COPY_AND_MOVE(InputVariable)
virtual void setInputValue(scalar inputValue);
virtual scalar getInputValue() const;
virtual std::string fuzzyInputValue() const;
virtual std::string toString() const FL_IOVERRIDE;
};
}
#endif /* FL_INPUTVARIABLE_H */

View File

@ -0,0 +1,90 @@
/*
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.
*/
#ifndef FL_OUTPUTVARIABLE_H
#define FL_OUTPUTVARIABLE_H
#include "fl/variable/Variable.h"
namespace fl {
class Accumulated;
class Defuzzifier;
class FL_API OutputVariable : public Variable {
private:
void copyFrom(const OutputVariable& other);
protected:
FL_unique_ptr<Accumulated> _fuzzyOutput;
FL_unique_ptr<Defuzzifier> _defuzzifier;
scalar _outputValue;
scalar _previousOutputValue;
scalar _defaultValue;
bool _lockOutputValueInRange;
bool _lockPreviousOutputValue;
public:
explicit OutputVariable(const std::string& name = "",
scalar minimum = -fl::inf, scalar maximum = fl::inf);
OutputVariable(const OutputVariable& other);
OutputVariable& operator=(const OutputVariable& other);
virtual ~OutputVariable() FL_IOVERRIDE;
FL_DEFAULT_MOVE(OutputVariable)
virtual Accumulated* fuzzyOutput() const;
virtual void setName(const std::string& name) FL_IOVERRIDE;
virtual void setMinimum(scalar minimum) FL_IOVERRIDE;
virtual void setMaximum(scalar maximum) FL_IOVERRIDE;
virtual void setDefuzzifier(Defuzzifier* defuzzifier);
virtual Defuzzifier* getDefuzzifier() const;
virtual void setOutputValue(scalar outputValue);
virtual scalar getOutputValue() const;
virtual void setPreviousOutputValue(scalar defuzzifiedValue);
virtual scalar getPreviousOutputValue() const;
virtual void setDefaultValue(scalar defaultValue);
virtual scalar getDefaultValue() const;
virtual void setLockOutputValueInRange(bool lockOutputValueInRange);
virtual bool isLockedOutputValueInRange() const;
virtual void setLockPreviousOutputValue(bool lockPreviousOutputValue);
virtual bool isLockedPreviousOutputValue() const;
virtual void defuzzify();
virtual std::string fuzzyOutputValue() const;
virtual void clear();
virtual std::string toString() const FL_IOVERRIDE;
};
}
#endif /* FL_OUTPUTVARIABLE_H */

View File

@ -0,0 +1,96 @@
/*
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.
*/
#ifndef FL_VARIABLE_H
#define FL_VARIABLE_H
#include "fl/fuzzylite.h"
#include "fl/defuzzifier/Centroid.h"
#include <string>
#include <vector>
namespace fl {
class Term;
class FL_API Variable {
private:
void copyFrom(const Variable& source);
protected:
std::string _name;
std::vector<Term*> _terms;
scalar _minimum, _maximum;
bool _enabled;
public:
explicit Variable(const std::string& name = "",
scalar minimum = -fl::inf,
scalar maximum = fl::inf);
Variable(const Variable& other);
Variable& operator=(const Variable& other);
virtual ~Variable();
FL_DEFAULT_MOVE(Variable)
virtual void setName(const std::string& name);
virtual std::string getName() const;
virtual void setRange(scalar minimum, scalar maximum);
virtual scalar range() const;
virtual void setMinimum(scalar minimum);
virtual scalar getMinimum() const;
virtual void setMaximum(scalar maximum);
virtual scalar getMaximum() const;
virtual void setEnabled(bool enabled);
virtual bool isEnabled() const;
virtual std::string fuzzify(scalar x) const;
virtual Term* highestMembership(scalar x, scalar* yhighest = fl::null) const;
virtual std::string toString() const;
/**
* Operations for iterable datatype _terms
*/
virtual void sort();
virtual void addTerm(Term* term);
virtual void insertTerm(Term* term, int index);
virtual Term* getTerm(int index) const;
virtual Term* getTerm(const std::string& name) const;
virtual bool hasTerm(const std::string& name) const;
virtual Term* removeTerm(int index);
virtual int numberOfTerms() const;
virtual void setTerms(const std::vector<Term*>& terms);
virtual const std::vector<Term*>& terms() const;
virtual std::vector<Term*>& terms();
};
}
#endif /* FL_VARIABLE_H */

91
driver.fcl Normal file
View File

@ -0,0 +1,91 @@
FUNCTION_BLOCK driver
VAR_INPUT
trackPos: REAL;
angle: REAL;
track9: REAL;
speedX: REAL;
END_VAR
VAR_OUTPUT
steer: REAL;
accel: REAL;
brake: REAL;
END_VAR
FUZZIFY trackPos
RANGE := (-9.000 .. 9.000);
TERM left := Trapezoid 0.300 0.600 9.000 9.000;
TERM center := Trapezoid -0.600 -0.300 0.300 0.600;
TERM right := Trapezoid -9.000 -9.000 -0.600 -0.300;
END_FUZZIFY
FUZZIFY angle
RANGE := (-3.150 .. 3.150);
TERM left := Trapezoid -3.150 -3.150 -0.900 -0.000;
TERM center := Trapezoid -0.900 -0.000 0.000 0.900;
TERM right := Trapezoid 0.000 0.900 3.150 3.150;
END_FUZZIFY
FUZZIFY track9
RANGE := (-1.000 .. 200.000);
TERM outside := Trapezoid -1.000 -1.000 0.000 0.000;
TERM near := Trapezoid 0.000 0.000 30.000 60.000;
TERM far := Trapezoid 30.000 60.000 200.00 200.000;
END_FUZZIFY
FUZZIFY speedX
RANGE := (0.000 .. 300.000);
TERM f_slow := Trapezoid 0.000 0.000 15.000 30.000;
TERM f_fast := Trapezoid 15.000 30.000 100.00 130.000;
TERM f_very_fast := Trapezoid 100.000 130.000 300.00 300.000;
END_FUZZIFY
DEFUZZIFY steer
RANGE := (-1.000 .. 1.000);
TERM turn_left := Trapezoid 0.000 0.100 1.000 1.000;
TERM stay_center := Triangle -0.100 0.000 0.100;
TERM turn_right := Trapezoid -1.000 -1.000 -0.100 0.000;
METHOD : COG;
ACCU : MAX;
DEFAULT := 0.000;
END_DEFUZZIFY
DEFUZZIFY accel
RANGE := (0.000 .. 1.000);
TERM nogas := Trapezoid 0.000 0.000 0.300 0.500;
TERM medgas := Triangle 0.100 0.200 0.300;
TERM fullgas := Trapezoid 0.300 0.400 1.000 1.000;
METHOD : COG;
ACCU : MAX;
DEFAULT := 1.000;
END_DEFUZZIFY
DEFUZZIFY brake
RANGE := (0.000 .. 1.000);
TERM nobrake := Triangle 0.000 0.000 0.035;
TERM fullbrake := Trapezoid 0.035 0.100 1.000 1.000;
METHOD : COG;
ACCU : MAX;
DEFAULT := 0.000;
END_DEFUZZIFY
RULEBLOCK
AND : MIN;
OR : MAX;
ACT : MIN;
RULE 1 : if trackPos is left then steer is turn_right;
RULE 2 : if trackPos is center then steer is stay_center;
RULE 3 : if trackPos is right then steer is turn_left;
RULE 4 : if angle is left then steer is turn_right;
RULE 5 : if angle is center then steer is stay_center;
RULE 6 : if angle is right then steer is turn_left;
RULE 7 : if track9 is near and speedX is f_fast then accel is nogas;
RULE 8 : if track9 is far and speedX is f_slow then accel is fullgas and brake is nobrake;
RULE 9 : if track9 is outside then accel is medgas and brake is nobrake;
RULE 10 : if track9 is near and speedX is f_very_fast then accel is nogas and brake is fullbrake;
END_RULEBLOCK
END_FUNCTION_BLOCK

24
src/BaseDriver.cpp Normal file
View File

@ -0,0 +1,24 @@
#include "BaseDriver.h"
BaseDriver::BaseDriver()
{
}
BaseDriver::~BaseDriver()
{
}
// Initialization of the desired angles for the rangefinders
void BaseDriver::init(float *angles)
{
for (int i = 0; i < 19; ++i)
angles[i] = (float)(-90 + i * 10);
}
void BaseDriver::onShutdown()
{
}
void BaseDriver::onRestart()
{
}

51
src/BaseDriver.h Normal file
View File

@ -0,0 +1,51 @@
/***************************************************************************
file : BaseDriver.h
copyright : (C) 2007 Daniele Loiacono
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef BASEDRIVER_H_
#define BASEDRIVER_H_
#include <string>
class BaseDriver
{
public:
typedef enum { WARMUP = 0, QUALIFYING = 1, RACE = 2, UNKNOWN = 3 } tstage;
tstage stage;
std::string trackName;
// Default Constructor
BaseDriver();
// Default Destructor;
virtual ~BaseDriver();
// Initialization of the desired angles for the rangefinders
virtual void init(float *angles);
// The main function:
// - the input variable sensors represents the current world sate
// - it returns a string representing the controlling action to perform
virtual std::string drive(std::string sensors) = 0;
// Callback function called at shutdown
virtual void onShutdown();
// Callback function called at server restart
virtual void onRestart();
};
#endif /*BASEDRIVER_H_*/

156
src/CarControl.cpp Normal file
View File

@ -0,0 +1,156 @@
/***************************************************************************
file : CarControl.cpp
copyright : (C) 2007 Daniele Loiacono
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "CarControl.h"
#include "SimpleParser.h"
int CarControl::META_RESTART = 1;
CarControl::CarControl()
{
}
CarControl::CarControl(float accel, float brake, int gear, float steer, float clutch, int focus, int meta)
{
this->accel = accel;
this->brake = brake;
this->gear = gear;
this->steer = steer;
this->clutch = clutch;
this->focus = focus;
this->meta = meta;
}
CarControl::CarControl(float accel, float brake, int gear, float steer, float clutch, int focus)
{
this->accel = accel;
this->brake = brake;
this->gear = gear;
this->steer = steer;
this->clutch = clutch;
this->focus = focus;
this->meta = 0;
}
CarControl::CarControl(std::string sensors)
{
fromString(sensors);
}
std::string CarControl::toString()
{
std::string str;
str = SimpleParser::stringify("accel", accel);
str += SimpleParser::stringify("brake", brake);
str += SimpleParser::stringify("gear", gear);
str += SimpleParser::stringify("steer", steer);
str += SimpleParser::stringify("clutch", clutch);
str += SimpleParser::stringify("focus", focus);
str += SimpleParser::stringify("meta", meta);
return str;
}
void CarControl::fromString(std::string sensors)
{
if (SimpleParser::parse(sensors, "accel", accel) == false)
accel = 0.0;
if (SimpleParser::parse(sensors, "brake", brake) == false)
brake = 0.0;
if (SimpleParser::parse(sensors, "gear", gear) == false)
gear = 1;
if (SimpleParser::parse(sensors, "steer", steer) == false)
steer = 0.0;
if (SimpleParser::parse(sensors, "clutch", clutch) == false)
clutch = 0.0;
if (SimpleParser::parse(sensors, "meta", meta) == false)
meta = 0;
if (SimpleParser::parse(sensors, "focus", focus) == false) //ML
focus = 0; //ML
if (focus < -90 || focus > 90)//ML What to do with focus requests out of allowed range?
focus = 360;//ML A value of 360 is used for not requesting focus readings; -1 is returned as focus reading to the client
}
float CarControl::getAccel() const
{
return this->accel;
}
void CarControl::setAccel(float accel)
{
this->accel = accel;
}
float CarControl::getBrake() const
{
return this->brake;
}
void CarControl::setBrake(float brake)
{
this->brake = brake;
}
int CarControl::getGear() const
{
return this->gear;
}
void CarControl::setGear(int gear)
{
this->gear = gear;
}
float CarControl::getSteer() const
{
return this->steer;
}
void CarControl::setSteer(float steer)
{
this->steer = steer;
}
int CarControl::getMeta() const
{
return this->meta;
}
void CarControl::setMeta(int meta)
{
this->meta = meta;
}
float CarControl::getClutch() const
{
return clutch;
}
void CarControl::setClutch(float clutch)
{
this->clutch = clutch;
}
int CarControl::getFocus()
{
return this->focus;
}
void CarControl::setFocus(int focus)
{
this->focus = focus;
}

78
src/CarControl.h Normal file
View File

@ -0,0 +1,78 @@
/***************************************************************************
file : CarControl.h
copyright : (C) 2007 Daniele Loiacono
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef CARCONTROL_H_
#define CARCONTROL_H_
#include <string>
class CarControl
{
private:
// Accelerate command [0,1]
float accel;
// Brake command [0,1]
float brake;
// Gear command {-1,0,1,...,6}
int gear;
// Steering command [-1,1]
float steer;
// Clutch command [0,1]
float clutch;
// meta-command {0 do nothing, 1 ask competition server to restart the race}
int meta;
// focus command [-90,90], i.e. angle of track sensor focus desired by client
int focus;
public:
CarControl();
CarControl(std::string sensors);
CarControl(float accel, float brake, int gear, float steer, float clutch, int focus, int meta = 0);
CarControl(float accel, float brake, int gear, float steer, float clutch, int focus = 0);
std::string toString();
void fromString(std::string sensors);
/* Getter and setter methods */
float getAccel() const;
void setAccel(float accel);
float getBrake() const;
void setBrake(float brake);
int getGear() const;
void setGear(int gear);
float getSteer() const;
void setSteer(float steer);
int getMeta() const;
void setMeta(int gear);
float getClutch() const;
void setClutch(float clutch);
int getFocus();
void setFocus(int focus);
// meta-command value for race restart
static int META_RESTART;
};
#endif /*CARCONTROL_H_*/

274
src/CarState.cpp Normal file
View File

@ -0,0 +1,274 @@
/***************************************************************************
file : CarState.h
copyright : (C) 2007 Daniele Loiacono
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "CarState.h"
#include "SimpleParser.h"
#include <cassert>
CarState::CarState()
{
}
CarState::CarState(std::string sensors)
{
SimpleParser::parse(sensors, "angle", this->angle);
SimpleParser::parse(sensors, "curLapTime", this->curLapTime);
SimpleParser::parse(sensors, "damage", this->damage);
SimpleParser::parse(sensors, "distFromStart", this->distFromStart);
SimpleParser::parse(sensors, "distRaced", this->distRaced);
SimpleParser::parse(sensors, "focus", this->focus, FOCUS_SENSORS_NUM);
SimpleParser::parse(sensors, "fuel", this->fuel);
SimpleParser::parse(sensors, "gear", this->gear);
SimpleParser::parse(sensors, "lastLapTime", this->lastLapTime);
SimpleParser::parse(sensors, "opponents", this->opponents, OPPONENTS_SENSORS_NUM);
SimpleParser::parse(sensors, "racePos", this->racePos);
SimpleParser::parse(sensors, "rpm", this->rpm);
SimpleParser::parse(sensors, "speedX", this->speedX);
SimpleParser::parse(sensors, "speedY", this->speedY);
SimpleParser::parse(sensors, "speedZ", this->speedZ);
SimpleParser::parse(sensors, "track", this->track, TRACK_SENSORS_NUM);
SimpleParser::parse(sensors, "trackPos", this->trackPos);
SimpleParser::parse(sensors, "wheelSpinVel", this->wheelSpinVel, 4);
SimpleParser::parse(sensors, "z", this->z);
}
std::string CarState::toString()
{
std::string str;
str = SimpleParser::stringify("angle", this->angle);
str += SimpleParser::stringify("curLapTime", this->curLapTime);
str += SimpleParser::stringify("damage", this->damage);
str += SimpleParser::stringify("distFromStart", this->distFromStart);
str += SimpleParser::stringify("distRaced", this->distRaced);
str += SimpleParser::stringify("focus", this->focus, FOCUS_SENSORS_NUM);
str += SimpleParser::stringify("fuel", this->fuel);
str += SimpleParser::stringify("gear", this->gear);
str += SimpleParser::stringify("lastLapTime", this->lastLapTime);
str += SimpleParser::stringify("opponents", this->opponents, OPPONENTS_SENSORS_NUM);
str += SimpleParser::stringify("racePos", this->racePos);
str += SimpleParser::stringify("rpm", this->rpm);
str += SimpleParser::stringify("speedX", this->speedX);
str += SimpleParser::stringify("speedY", this->speedY);
str += SimpleParser::stringify("speedZ", this->speedZ);
str += SimpleParser::stringify("track", this->track, TRACK_SENSORS_NUM);
str += SimpleParser::stringify("trackPos", this->trackPos);
str += SimpleParser::stringify("wheelSpinVel", this->wheelSpinVel, 4);
str += SimpleParser::stringify("z", this->z);
return str;
}
float CarState::getAngle()
{
return angle;
}
void CarState::setAngle(float angle)
{
this->angle = angle;
}
float CarState::getCurLapTime()
{
return curLapTime;
}
void CarState::setCurLapTime(float curLapTime)
{
this->curLapTime = curLapTime;
}
float CarState::getDamage()
{
return damage;
}
void CarState::setDamage(float damage)
{
this->damage = damage;
}
float CarState::getDistFromStart()
{
return distFromStart;
}
void CarState::setDistFromStart(float distFromStart)
{
this->distFromStart = distFromStart;
}
float CarState::getDistRaced()
{
return distRaced;
}
void CarState::setDistRaced(float distRaced)
{
this->distRaced = distRaced;
}
float CarState::getFocus(int i)
{
assert(i >= 0 && i < FOCUS_SENSORS_NUM);
return focus[i];
}
void CarState::setFocus(int i, float value)
{
assert(i >= 0 && i < FOCUS_SENSORS_NUM);
this->focus[i] = value;
}
float CarState::getFuel()
{
return fuel;
}
void CarState::setFuel(float fuel)
{
this->fuel = fuel;
}
int CarState::getGear()
{
return gear;
}
void CarState::setGear(int gear)
{
this->gear = gear;
}
float CarState::getLastLapTime()
{
return lastLapTime;
}
void CarState::setLastLapTime(float lastLapTime)
{
this->lastLapTime = lastLapTime;
}
float CarState::getOpponents(int i)
{
assert(i >= 0 && i < OPPONENTS_SENSORS_NUM);
return opponents[i];
}
void CarState::setOpponents(int i, float value)
{
assert(i >= 0 && i < OPPONENTS_SENSORS_NUM);
this->opponents[i] = value;
}
int CarState::getRacePos()
{
return racePos;
}
void CarState::setRacePos(int racePos)
{
this->racePos = racePos;
}
int CarState::getRpm()
{
return rpm;
}
void CarState::setRpm(int rpm)
{
this->rpm = rpm;
}
float CarState::getSpeedX()
{
return speedX;
}
void CarState::setSpeedX(float speedX)
{
this->speedX = speedX;
}
float CarState::getSpeedY()
{
return speedY;
}
void CarState::setSpeedY(float speedY)
{
this->speedY = speedY;
}
float CarState::getSpeedZ()
{
return speedZ;
}
void CarState::setSpeedZ(float speedZ)
{
this->speedZ = speedZ;
}
float CarState::getTrack(int i)
{
assert(i >= 0 && i < TRACK_SENSORS_NUM);
return track[i];
}
void CarState::setTrack(int i, float value)
{
assert(i >= 0 && i < TRACK_SENSORS_NUM);
this->track[i] = value;
}
float CarState::getTrackPos()
{
return trackPos;
}
void CarState::setTrackPos(float prackPos)
{
this->trackPos = trackPos;
}
float CarState::getWheelSpinVel(int i)
{
assert(i >= 0 && i < 4);
return wheelSpinVel[i];
}
void CarState::setWheelSpinVel(int i, float value)
{
assert(i >= 0 && i < 4);
wheelSpinVel[i] = value;
}
float CarState::getZ()
{
return z;
}
void CarState::setZ(float z)
{
this->z = z;
}

99
src/CarState.h Normal file
View File

@ -0,0 +1,99 @@
/***************************************************************************
file : CarState.h
copyright : (C) 2007 Daniele Loiacono
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef CARSTATE_H_
#define CARSTATE_H_
#define FOCUS_SENSORS_NUM 5
#define TRACK_SENSORS_NUM 19
#define OPPONENTS_SENSORS_NUM 36
#include <string>
class CarState
{
private:
float angle;
float curLapTime;
float damage;
float distFromStart;
float distRaced;
float focus[FOCUS_SENSORS_NUM];
float fuel;
int gear;
float lastLapTime;
float opponents[OPPONENTS_SENSORS_NUM];
int racePos;
int rpm;
float speedX;
float speedY;
float speedZ;
float track[TRACK_SENSORS_NUM];
float trackPos;
float wheelSpinVel[4];
float z;
public:
CarState();
CarState(std::string sensors);
std::string toString();
/* Getter and setter methods */
float getAngle();
void setAngle(float angle);
float getCurLapTime();
void setCurLapTime(float curLapTime);
float getDamage();
void setDamage(float damage);
float getDistFromStart();
void setDistFromStart(float distFromStart);
float getDistRaced();
void setDistRaced(float distRaced);
float getFocus(int i);
void setFocus(int i, float value);
float getFuel();
void setFuel(float fuel);
int getGear();
void setGear(int gear);
float getLastLapTime();
void setLastLapTime(float lastLapTime);
float getOpponents(int i);
void setOpponents(int i, float value);
int getRacePos();
void setRacePos(int racePos);
int getRpm();
void setRpm(int rpm);
float getSpeedX();
void setSpeedX(float speedX);
float getSpeedY();
void setSpeedY(float speedY);
float getSpeedZ();
void setSpeedZ(float speedZ);
float getTrack(int i);
void setTrack(int i, float value);
float getTrackPos();
void setTrackPos(float trackPos);
float getWheelSpinVel(int i);
void setWheelSpinVel(int i, float value);
float getZ();
void setZ(float z);
};
#endif /*CARSTATE_H_*/

128
src/FuzzyDriver.cpp Normal file
View File

@ -0,0 +1,128 @@
#include "FuzzyDriver.h"
#include <iomanip>
#include <iostream>
FuzzyDriver::FuzzyDriver(std::string trackName, BaseDriver::tstage, std::string fclFile)
{
this->trackName = trackName;
this->stage = stage;
this->fclFile = fclFile;
}
FuzzyDriver::~FuzzyDriver()
{
delete flEngine;
}
bool FuzzyDriver::loadFCLfile()
{
bool fileLoaded = false;
try
{
flEngine = fl::FclImporter().fromFile(fclFile);
fileLoaded = true;
}
catch (fl::Exception &e)
{
std::cerr << "FuzzyLite: " << e.getWhat() << std::endl;
}
return fileLoaded;
}
void FuzzyDriver::init(float *angles)
{
// set angles as {-90,-75,-60,-45,-30,20,15,10,5,0,5,10,15,20,30,45,60,75,90}
for (int i = 0; i < 5; i++)
{
angles[i] = (float)(-90 + i * 15);
angles[18 - i] = (float)(90 - i * 15);
}
for (int i = 5; i < 9; i++)
{
angles[i] = (float)(-20 + (i - 5) * 5);
angles[18 - i] = (float)(20 - (i - 5) * 5);
}
angles[9] = 0;
}
void FuzzyDriver::onShutdown()
{
std::cout << "Bye bye!" << std::endl;
}
void FuzzyDriver::onRestart()
{
std::cout << "Restarting the race!" << std::endl;
}
/* Gear Changing Constants*/
const int FuzzyDriver::gearUp[6] =
{
5000,6000,6000,6500,7000,0
};
const int FuzzyDriver::gearDown[6] =
{
0,2500,3000,3000,3500,3500
};
CarControl FuzzyDriver::wDrive(CarState cs)
{
float accel = 0; // [0,1]
float brake = 0; // [0,1]
int gear = 0; // {-1,..,6}
float steer = 0; // [-1,1]
float clutch = 0; // [0,1]
int meta = 0; // {0,1}
int focus = 0; // [-90,90]
float trackPos = cs.getTrackPos();
float angle = cs.getAngle();
float track9 = cs.getTrack(9);
float speedX = cs.getSpeedX();
flEngine->setInputValue("trackPos", trackPos);
flEngine->setInputValue("angle", angle);
flEngine->setInputValue("track9", track9);
flEngine->setInputValue("speedX", speedX);
flEngine->process();
steer = (float)flEngine->getOutputVariable("steer")->getOutputValue();
accel = (float)flEngine->getOutputVariable("accel")->getOutputValue();
brake = (float)flEngine->getOutputVariable("brake")->getOutputValue();
gear = getGear(cs);
std::cout << '\r' << std::fixed << std::setw(7) << std::setprecision(3) << std::setfill('0') <<
"trackPos: " << trackPos << ", angle: " << angle << ", speedX: " << speedX << ", track9: " << track9 << ", steer: " << steer << ", accel: " << accel <<
", brake: " << brake << std::flush;
CarControl cc(accel, brake, gear, steer, clutch, focus, meta);
return cc;
}
int FuzzyDriver::getGear(CarState &cs)
{
int gear = cs.getGear();
int rpm = cs.getRpm();
// if gear is 0 (N) or -1 (R) just return 1
if (gear < 1)
return 1;
// check if the RPM value of car is greater than the one suggested
// to shift up the gear from the current one
if (gear < 6 && rpm >= gearUp[gear - 1])
return gear + 1;
else
// check if the RPM value of car is lower than the one suggested
// to shift down the gear from the current one
if (gear > 1 && rpm <= gearDown[gear - 1])
return gear - 1;
else // otherwhise keep current gear
return gear;
}

Some files were not shown because too many files have changed in this diff Show More