diff options
Diffstat (limited to 'fuzzylite/fl/imex')
-rw-r--r-- | fuzzylite/fl/imex/CppExporter.h | 161 | ||||
-rw-r--r-- | fuzzylite/fl/imex/Exporter.h | 74 | ||||
-rw-r--r-- | fuzzylite/fl/imex/FclExporter.h | 105 | ||||
-rw-r--r-- | fuzzylite/fl/imex/FclImporter.h | 74 | ||||
-rw-r--r-- | fuzzylite/fl/imex/FisExporter.h | 121 | ||||
-rw-r--r-- | fuzzylite/fl/imex/FisImporter.h | 80 | ||||
-rw-r--r-- | fuzzylite/fl/imex/FldExporter.h | 248 | ||||
-rw-r--r-- | fuzzylite/fl/imex/FllExporter.h | 168 | ||||
-rw-r--r-- | fuzzylite/fl/imex/FllImporter.h | 91 | ||||
-rw-r--r-- | fuzzylite/fl/imex/Importer.h | 71 | ||||
-rw-r--r-- | fuzzylite/fl/imex/JavaExporter.h | 152 | ||||
-rw-r--r-- | fuzzylite/fl/imex/RScriptExporter.h | 246 |
12 files changed, 1591 insertions, 0 deletions
diff --git a/fuzzylite/fl/imex/CppExporter.h b/fuzzylite/fl/imex/CppExporter.h new file mode 100644 index 0000000..1c48225 --- /dev/null +++ b/fuzzylite/fl/imex/CppExporter.h @@ -0,0 +1,161 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_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 Activation; + + /** + The CppExporter class is an Exporter that translates an Engine and its + components to the `C++` programming language using the `fuzzylite` + library. + + @author Juan Rada-Vilela, Ph.D. + @see JavaExporter + @see Exporter + @since 4.0 + */ + class FL_API CppExporter : public Exporter { + private: + bool _usingNamespace; + bool _usingVariableNames; + public: + explicit CppExporter(bool usingNamespace = false, bool usingVariableNames = true); + 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; + + /** + Sets whether the fl namespace of the library is prepended to types + (e.g., fl::Engine) + + @param usingNamespace whether the fl namespace of the library is + prepended to types (e.g., fl::Engine) + */ + virtual void setUsingNamespace(bool usingNamespace); + /** + Gets whether the fl namespace of the library is prepended to types + (e.g., fl::Engine) + @return whether the fl namespace of the library is prepended to types + */ + virtual bool isUsingNamespace() const; + + /** + Returns the given text prepended with the `fl` namespace if + CppExporter::isUsingNamespace is `true`, or the text otherwise + + @param clazz is the text to be prepended the `fl::`. + @return the given text prepended with the `fl` namespace if + CppExporter::isUsingNamespace is `true`, or the text otherwise + */ + virtual std::string fl(const std::string& clazz) const; + /** + Sets whether variables are exported using their names + (e.g., `power->setValue(fl::nan)`) instead of numbered identifiers + (e.g., `inputVariable1->setValue(fl::nan)`) + @param usingVariableNames indicates whether variables are exported using + their names + */ + virtual void setUsingVariableNames(bool usingVariableNames); + /** + Gets whether variables are exported using their names + (e.g., `power->setValue(fl::nan)`) instead of numbered identifiers + (e.g., `inputVariable1->setValue(fl::nan)`) + @return whether variables are exported using their names + */ + virtual bool isUsingVariableNames() const; + + /** + Returns a string representation of InputVariable in the `C++` programming language + @param inputVariable is the input variable + @param engine is the engine in which the input variable is registered + @return a string representation of the input variable in the `C++` programming language + */ + virtual std::string toString(const InputVariable* inputVariable, const Engine* engine) const; + /** + Returns a string representation of the OutputVariable in the `C++` programming language + @param outputVariable is the output variable + @param engine is the engine in which the output variable is registered + @return a string representation of the output variable in the `C++` programming language + */ + virtual std::string toString(const OutputVariable* outputVariable, const Engine* engine) const; + /** + Returns a string representation of the RuleBlock in the `C++` programming language + @param ruleBlock is the rule block + @param engine is the engine in which the rule block is registered + @return a string representation of the rule block in the `C++` programming language + */ + virtual std::string toString(const RuleBlock* ruleBlock, const Engine* engine) const; + + /** + Returns a string representation of the Activation method in the `C++` programming language + @param activation is the activation method + @return a string representation of the activation method in the `C++` programming language + */ + virtual std::string toString(const Activation* activation) const; + + /** + Returns a string representation of the scalar value in the `C++` programming language + @param value is the scalar value + @return a string representation of the scalar value in the `C++` programming language + */ + virtual std::string toString(scalar value) const; + + /** + Returns a string representation of the Hedge in the `C++` programming language + @param hedge is the hedge + @return a string representation of the hedge in the `C++` programming language + */ + virtual std::string toString(const Hedge* hedge) const; + /** + Returns a string representation of the Term in the `C++` programming language + @param term is the term + @return a string representation of the term in the `C++` programming language + */ + virtual std::string toString(const Term* term) const; + /** + Returns a string representation of the Norm in the `C++` programming language + @param norm is the norm + @return a string representation of the norm in the `C++` programming language + */ + virtual std::string toString(const Norm* norm) const; + /** + Returns a string representation of the Defuzzifier in the `C++` programming language + @param defuzzifier is the defuzzifier + @return a string representation of the defuzzifier in the `C++` programming language + */ + virtual std::string toString(const Defuzzifier* defuzzifier) const; + + virtual CppExporter* clone() const FL_IOVERRIDE; + + }; +} +#endif /* FL_CPPEXPORTER_H */ + diff --git a/fuzzylite/fl/imex/Exporter.h b/fuzzylite/fl/imex/Exporter.h new file mode 100644 index 0000000..b883edf --- /dev/null +++ b/fuzzylite/fl/imex/Exporter.h @@ -0,0 +1,74 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_EXPORTER_H +#define FL_EXPORTER_H + +#include "fl/fuzzylite.h" + +#include <string> + +namespace fl { + class Engine; + + /** + The Exporter class is the abstract class for exporters to translate an + Engine into different formats. + + @todo declare methods for exporting other components (e.g., Variable) + + @author Juan Rada-Vilela, Ph.D. + @see Importer + @since 4.0 + */ + class FL_API Exporter { + public: + + Exporter(); + virtual ~Exporter(); + FL_DEFAULT_COPY_AND_MOVE(Exporter) + + /** + Returns a string representation of the engine + @param engine is the engine to export + @return a string representation of the engine + */ + virtual std::string toString(const Engine* engine) const = 0; + /** + Stores the string representation of the engine into the specified file + @param path is the full path of the file to export the engine to + @param engine is the engine to export + @throws fl::Exception if the file cannot be created + */ + virtual void toFile(const std::string& path, const Engine* engine) const; + + /** + Returns the name of the exporter + @return the name of the exporter + */ + virtual std::string name() const = 0; + + /** + Creates a clone of the exporter + @return a clone of the exporter + */ + virtual Exporter* clone() const = 0; + }; + +} + +#endif /* FL_EXPORTER_H */ + diff --git a/fuzzylite/fl/imex/FclExporter.h b/fuzzylite/fl/imex/FclExporter.h new file mode 100644 index 0000000..efec3c4 --- /dev/null +++ b/fuzzylite/fl/imex/FclExporter.h @@ -0,0 +1,105 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_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; + + /** + The FclExporter class is an Exporter that translates an Engine and its + components to the Fuzzy Control Language specification. + + @author Juan Rada-Vilela, Ph.D. + @see FclImporter + @see Exporter + @since 4.0 + */ + class FL_API FclExporter : public Exporter { + private: + std::string _indent; + + public: + explicit FclExporter(const std::string& indent = " "); + virtual ~FclExporter() FL_IOVERRIDE; + FL_DEFAULT_COPY_AND_MOVE(FclExporter) + + /** + Sets the indentation string within blocks + @param indent is the indentation string within blocks + */ + virtual void setIndent(const std::string& indent); + /** + Gets the indentation string within blocks + @return the indentation string within blocks + */ + virtual std::string getIndent() const; + + virtual std::string name() const FL_IOVERRIDE; + virtual std::string toString(const Engine* engine) const FL_IOVERRIDE; + + /** + Returns a string representation of the InputVariable according to the Fuzzy Control Language specification + @param variable is the input variable + @return a string representation of the input variable according to the Fuzzy Control Language specification + */ + virtual std::string toString(const InputVariable* variable) const; + /** + Returns a string representation of the OutputVariable according to the Fuzzy Control Language specification + @param variable is the output variable + @return a string representation of the output variable according to the Fuzzy Control Language specification + */ + virtual std::string toString(const OutputVariable* variable) const; + /** + Returns a string representation of the RuleBlock according to the Fuzzy Control Language specification + @param ruleBlock is the rule block + @return a string representation of the rule block according to the Fuzzy Control Language specification + */ + virtual std::string toString(const RuleBlock* ruleBlock) const; + /** + Returns a string representation of the Norm according to the Fuzzy Control Language specification + @param norm is the norm + @return a string representation of the norm according to the Fuzzy Control Language specification + */ + virtual std::string toString(const Norm* norm) const; + /** + Returns a string representation of the Defuzzifier according to the Fuzzy Control Language specification + @param defuzzifier is the defuzzifier + @return a string representation of the defuzzifier according to the Fuzzy Control Language specification + */ + virtual std::string toString(const Defuzzifier* defuzzifier) const; + /** + Returns a string representation of the Term according to the Fuzzy Control Language specification + @param term is the term + @return a string representation of the term according to the Fuzzy Control Language specification + */ + virtual std::string toString(const Term* term) const; + + virtual FclExporter* clone() const FL_IOVERRIDE; + }; +} + +#endif /* FL_FCLEXPORTER_H */ diff --git a/fuzzylite/fl/imex/FclImporter.h b/fuzzylite/fl/imex/FclImporter.h new file mode 100644 index 0000000..2e75432 --- /dev/null +++ b/fuzzylite/fl/imex/FclImporter.h @@ -0,0 +1,74 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_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; + + /** + The FclImporter class is an Importer that configures an Engine and its + components utilizing the Fuzzy Control Language specification. + + @author Juan Rada-Vilela, Ph.D. + @see FclExporter + @see Importer + @since 4.0 + */ + 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 */ diff --git a/fuzzylite/fl/imex/FisExporter.h b/fuzzylite/fl/imex/FisExporter.h new file mode 100644 index 0000000..a7f5d8c --- /dev/null +++ b/fuzzylite/fl/imex/FisExporter.h @@ -0,0 +1,121 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_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; + + /** + The FisExporter class is an Exporter that translates an Engine and its + components into the Fuzzy Inference System format for Matlab or Octave. + + @author Juan Rada-Vilela, Ph.D. + @see FisImporter + @see Exporter + @since 4.0 + */ + 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; + + /** + Returns a string representation of the TNorm in the Fuzzy Inference System format + @param tnorm is the TNorm + @return a string representation of the TNorm in the Fuzzy Inference System format + */ + virtual std::string toString(const TNorm* tnorm) const; + + /** + Returns a string representation of the SNorm in the Fuzzy Inference System format + @param snorm is the SNorm + @return a string representation of the SNorm in the Fuzzy Inference System format + */ + virtual std::string toString(const SNorm* snorm) const; + + /** + Returns a string representation of the Defuzzifier in the Fuzzy Inference System format + @param defuzzifier is the defuzzifier + @return a string representation of the Defuzzifier in the Fuzzy Inference System format + */ + virtual std::string toString(const Defuzzifier* defuzzifier) const; + /** + Returns a string representation of the Term in the Fuzzy Inference System format + @param term is the term + @return a string representation of the term in the Fuzzy Inference System format + */ + virtual std::string toString(const Term* term) const; + + /** + Returns a string representation of the `[System]` configuration + @param engine is the engine + @return a string representation of the `[System]` configuration + */ + virtual std::string exportSystem(const Engine* engine) const; + /** + Returns a string representation of the `[Input]` configuration + @param engine is the engine + @return a string representation of the `[Input]` configuration + */ + virtual std::string exportInputs(const Engine* engine) const; + /** + Returns a string representation of the `[Output]` configuration + @param engine is the engine + @return a string representation of the `[Output]` configuration + */ + virtual std::string exportOutputs(const Engine* engine) const; + /** + Returns a string representation of the `[Rules]` configuration + @param engine is the engine + @return a string representation of the `[Rules]` configuration + */ + virtual std::string exportRules(const Engine* engine) const; + /** + Returns a string representation for the Rule in the Fuzzy Inference System format + @param rule is the rule + @param engine is the engine in which the rule is registered + @return a string representation for the rule in the Fuzzy Inference System format + */ + virtual std::string exportRule(const Rule* rule, const Engine* engine) const; + + virtual FisExporter* clone() const FL_IOVERRIDE; + }; +} + +#endif /* FL_FISEXPORTER_H */ + diff --git a/fuzzylite/fl/imex/FisImporter.h b/fuzzylite/fl/imex/FisImporter.h new file mode 100644 index 0000000..2c9ce36 --- /dev/null +++ b/fuzzylite/fl/imex/FisImporter.h @@ -0,0 +1,80 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_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; + + /** + The FisImporter class is an Importer that configures an Engine and its + components from utilizing the Fuzzy Inference System format for Matlab or + Octave. + + @author Juan Rada-Vilela, Ph.D. + @see FisExporter + @see Importer + @since 4.0 + */ + 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; + + virtual std::string translateTNorm(const std::string& tnorm) const; + virtual std::string translateSNorm(const std::string& tnorm) const; + virtual std::string translateDefuzzifier(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; + + virtual std::pair<scalar, scalar> parseRange(const std::string& range) const; + + }; +} + +#endif /* FL_FISIMPORTER_H */ + diff --git a/fuzzylite/fl/imex/FldExporter.h b/fuzzylite/fl/imex/FldExporter.h new file mode 100644 index 0000000..98a14c9 --- /dev/null +++ b/fuzzylite/fl/imex/FldExporter.h @@ -0,0 +1,248 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_FLDEXPORTER_H +#define FL_FLDEXPORTER_H + +#include "fl/imex/Exporter.h" + +#include <vector> + +namespace fl { + class Engine; + class InputVariable; + class OutputVariable; + + /** + The FldExporter class is an Exporter that evaluates an Engine and exports + its input values and output values to the FuzzyLite Dataset (FLD) format, + see [http://www.fuzzylite.com/fll-fld](http://www.fuzzylite.com/fll-fld) + for more information. + + @author Juan Rada-Vilela, Ph.D. + @see FllExporter + @see Exporter + @since 4.0 + */ + class FL_API FldExporter : public Exporter { + private: + std::string _separator; + bool _exportHeaders; + bool _exportInputValues; + bool _exportOutputValues; + public: + + /** + The ScopeOfValues refers to the scope of the equally-distributed values + to generate. + */ + enum ScopeOfValues { + /**Generates @f$n@f$ values for each variable*/ + EachVariable, + /**Generates @f$n@f$ values for all variables*/ + AllVariables + }; + explicit FldExporter(const std::string& separator = " "); + virtual ~FldExporter() FL_IOVERRIDE; + FL_DEFAULT_COPY_AND_MOVE(FldExporter) + + virtual std::string name() const FL_IOVERRIDE; + + /** + Sets the separator of the dataset columns + @param separator is the separator of the dataset columns + */ + virtual void setSeparator(const std::string& separator); + /** + Gets the separator of the dataset columns + @return the separator of the dataset columns + */ + virtual std::string getSeparator() const; + + /** + Sets whether the header of the dataset is to be exported + @param exportHeaders indicates whether the header of the dataset is + to be exported + */ + virtual void setExportHeader(bool exportHeaders); + /** + Gets whether the header of the dataset is to be exported + @return whether the header of the dataset is to be exported + */ + virtual bool exportsHeader() const; + + /** + Sets whether the values of the input variables are to be exported + @param exportInputValues indicates whether the values of the input + variables are to be exported + */ + virtual void setExportInputValues(bool exportInputValues); + /** + Gets whether the values of the input variables are to be exported + @return whether the values of the input variables are to be exported + */ + virtual bool exportsInputValues() const; + + /** + Sets whether the values of the output variables are to be exported + @param exportOutputValues indicates whether the values of the output + variables are to be exported + */ + virtual void setExportOutputValues(bool exportOutputValues); + /** + Gets whether the values of the output variables are to be exported + @return whether the values of the output variables are to be exported + */ + virtual bool exportsOutputValues() const; + + /** + Gets the header of the dataset for the given engine + @param engine is the engine to be exported + @return the header of the dataset for the given engine + */ + virtual std::string header(const Engine* engine) const; + + /** + Returns a FuzzyLite Dataset from the engine. Please consider that the + engine will be `const_cast`ed to achieve so; that is, despite being + marked as `const`, the engine will be modified in order to compute + the output values based on the input values. + @param engine is the engine to export + @return a FuzzyLite Dataset from the engine + */ + virtual std::string toString(const Engine* engine) const FL_IOVERRIDE; + /** + Returns a FuzzyLite Dataset from the engine. + @param engine is the engine to export + @param values is the number of values to export + @param scope indicates the scope of the values + @return a FuzzyLite Dataset from the engine + */ + virtual std::string toString(Engine* engine, int values, ScopeOfValues scope = AllVariables) const; + + /** + Returns a FuzzyLite Dataset from the engine. + @param engine is the engine to export + @param values is the number of values to export + @param scope indicates the scope of the values + @param activeVariables contains the input variables to generate values for. + The input variables must be in the same order as in the engine. A value of + fl::null indicates the variable is not active. + @return a FuzzyLite Dataset from the engine + */ + virtual std::string toString(Engine* engine, int values, ScopeOfValues scope, + const std::vector<InputVariable*>& activeVariables) const; + /** + Returns a FuzzyLite Dataset from the engine. + @param engine is the engine to export + @param reader is the reader of a set of lines containing space-separated + input values + @return a FuzzyLite Dataset from the engine + */ + virtual std::string toString(Engine* engine, std::istream& reader) const; + + + using Exporter::toFile; + /** + Saves the engine as a FuzzyLite Dataset into the specified file + @param path is the full path of the file + @param engine is the engine to export + @param values is the number of values to export + @param scope indicates the scope of the values + */ + virtual void toFile(const std::string& path, Engine* engine, + int values, ScopeOfValues scope = AllVariables) const; + /** + Saves the engine as a FuzzyLite Dataset into the specified file + @param path is the full path of the file + @param engine is the engine to export + @param values is the number of values to export + @param scope indicates the scope of the values + @param activeVariables contains the input variables to generate values for. + The input variables must be in the same order as in the engine. A value of + fl::null indicates the variable is not active. + */ + virtual void toFile(const std::string& path, Engine* engine, + int values, ScopeOfValues scope, + const std::vector<InputVariable*>& activeVariables) const; + /** + Saves the engine as a FuzzyLite Dataset into the specified file + @param path is the full path of the file + @param engine is the engine to export + @param reader is the reader of a set of lines containing space-separated input values + */ + virtual void toFile(const std::string& path, Engine* engine, std::istream& reader) const; + + /** + Parses the string into a vector of values unless the string starts with `#` + @param values is a space-separated set of values + @return a vector of values + */ + virtual std::vector<scalar> parse(const std::string& values) const; + + /** + Writes the engine into the given writer + @param engine is the engine to export + @param writer is the output where the engine will be written to + @param values is the number of values to export + @param scope indicates the scope of the values + */ + virtual void write(Engine* engine, std::ostream& writer, int values, + ScopeOfValues scope = AllVariables) const; + /** + Writes the engine into the given writer + @param engine is the engine to export + @param writer is the output where the engine will be written to + @param values is the number of values to export + @param scope indicates the scope of the values + @param activeVariables contains the input variables to generate values for. + The input variables must be in the same order as in the engine. A value of + fl::null indicates the variable is not active. + */ + virtual void write(Engine* engine, std::ostream& writer, int values, ScopeOfValues scope, + const std::vector<InputVariable*>& activeVariables) const; + /** + Writes the engine into the given writer + @param engine is the engine to export + @param writer is the output where the engine will be written to + @param reader is the reader of a set of lines containing space-separated input values + */ + virtual void write(Engine* engine, std::ostream& writer, std::istream& reader) const; + /** + Writes the engine into the given writer + @param engine is the engine to export + @param writer is the output where the engine will be written to + @param inputValues is the vector of input values + */ + virtual void write(Engine* engine, std::ostream& writer, const std::vector<scalar>& inputValues) const; + /** + Writes the engine into the given writer + @param engine is the engine to export + @param writer is the output where the engine will be written to + @param inputValues is the vector of input values + @param activeVariables contains the input variables to generate values for. + The input variables must be in the same order as in the engine. A value of + fl::null indicates the variable is not active. + */ + virtual void write(Engine* engine, std::ostream& writer, const std::vector<scalar>& inputValues, + const std::vector<InputVariable*>& activeVariables) const; + + virtual FldExporter* clone() const FL_IOVERRIDE; + }; +} + +#endif /* FL_FLDEXPORTER_H */ + diff --git a/fuzzylite/fl/imex/FllExporter.h b/fuzzylite/fl/imex/FllExporter.h new file mode 100644 index 0000000..5a222e4 --- /dev/null +++ b/fuzzylite/fl/imex/FllExporter.h @@ -0,0 +1,168 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_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 Activation; + class Defuzzifier; + class Term; + + /** + The FllExporter class is an Exporter that translates an Engine and its + components to the FuzzyLite Language (FLL), see + [http://www.fuzzylite.com/fll-fld](http://www.fuzzylite.com/fll-fld) for + more information. + + @author Juan Rada-Vilela, Ph.D. + @see FllImporter + @see Exporter + @since 4.0 + */ + class FL_API FllExporter : public Exporter { + private: + 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; + + /** + Sets the indent string of the FuzzyLite Language + @param indent is the indent string of the FuzzyLite Language + */ + virtual void setIndent(const std::string& indent); + /** + Gets the indent string of the FuzzyLite Language + @return the indent string of the FuzzyLite Language + */ + virtual std::string getIndent() const; + + /** + Gets the separator of the FuzzyLite Language + @param separator of the FuzzyLite Language + */ + virtual void setSeparator(const std::string& separator); + /** + Gets the separator of the FuzzyLite Language + @return the separator of the FuzzyLite Language + */ + virtual std::string getSeparator() const; + + virtual std::string toString(const Engine* engine) const FL_IOVERRIDE; + + /** + Returns a string representation of the vector of variables in the FuzzyLite Language + @param variables is the vector of variables + @return a string representation of the vector of variables in the FuzzyLite Language + */ + virtual std::string toString(const std::vector<Variable*>& variables) const; + /** + Returns a string representation of the vector of input variables in the FuzzyLite Language + @param inputVariables is the vector of input variables + @return a string representation of the vector of input variables in the FuzzyLite Language + */ + virtual std::string toString(const std::vector<InputVariable*>& inputVariables) const; + /** + Returns a string representation of the vector of output variables in the FuzzyLite Language + @param outputVariables is a vector of output variables + @return a string representation of the vector of output variables in the FuzzyLite Language + */ + virtual std::string toString(const std::vector<OutputVariable*>& outputVariables) const; + /** + Returns a string representation of the vector of rule blocks in the FuzzyLite Language + @param ruleBlocks is the vector of rule blocks + @return a string representation of the vector of rule blocks in the FuzzyLite Language + */ + virtual std::string toString(const std::vector<RuleBlock*>& ruleBlocks) const; + + /** + Returns a string representation of the Variable in the FuzzyLite Language + @param variable is the variable + @return a string representation of the variable in the FuzzyLite Language + */ + virtual std::string toString(const Variable* variable) const; + /** + Returns a string representation of the InputVariable in the FuzzyLite Language + @param inputVariable is the input variable to export + @return a string representation of the input variable in the FuzzyLite Language + */ + virtual std::string toString(const InputVariable* inputVariable) const; + /** + Returns a string representation of the OutputVariable in the FuzzyLite Language + @param outputVariable is the output variable + @return a string representation of the output variable in the FuzzyLite Language + */ + virtual std::string toString(const OutputVariable* outputVariable) const; + + /** + Returns a string representation of the RuleBlock in the FuzzyLite Language + @param ruleBlock is the rule block + @return a string representation of the rule block in the FuzzyLite Language + */ + virtual std::string toString(const RuleBlock* ruleBlock) const; + /** + Returns a string representation of the Rule in the FuzzyLite Language + @param rule is the rule + @return a string representation of the rule in the FuzzyLite Language + */ + virtual std::string toString(const Rule* rule) const; + + /** + Returns a string representation of the Norm in the FuzzyLite Language + @param norm is the norm + @return a string representation of the norm in the FuzzyLite Language + */ + virtual std::string toString(const Norm* norm) const; + /** + Returns a string representation of the Activation method in the FuzzyLite Language + @param activation is the activation method + @return a string representation of the activation method in the FuzzyLite Language + */ + virtual std::string toString(const Activation* activation) const; + /** + Returns a string representation of the Defuzzifier in the FuzzyLite Language + @param defuzzifier is the defuzzifier + @return a string representation of the defuzzifier in the FuzzyLite Language + */ + virtual std::string toString(const Defuzzifier* defuzzifier) const; + /** + Returns a string representation of the Term in the FuzzyLite Language + @param term is the term + @return a string representation of the term in the FuzzyLite Language + */ + virtual std::string toString(const Term* term) const; + + virtual FllExporter* clone() const FL_IOVERRIDE; + }; +} + +#endif /* FL_FLLEXPORTER_H */ + diff --git a/fuzzylite/fl/imex/FllImporter.h b/fuzzylite/fl/imex/FllImporter.h new file mode 100644 index 0000000..055bb88 --- /dev/null +++ b/fuzzylite/fl/imex/FllImporter.h @@ -0,0 +1,91 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_FLLIMPORTER_H +#define FL_FLLIMPORTER_H + +#include "fl/imex/Importer.h" + +#include <utility> + +namespace fl { + class TNorm; + class SNorm; + class Activation; + class Term; + class Defuzzifier; + + /** + The FllImporter class is an Importer that configures an Engine and its + components utilizing the FuzzyLite Language (FLL), see + [http://www.fuzzylite.com/fll-fld](http://www.fuzzylite.com/fll-fld) for + more information. + + @author Juan Rada-Vilela, Ph.D. + @see FllExporter + @see Importer + @since 4.0 + @todo parse methods returning respective instances from blocks of text + */ + class FL_API FllImporter : public Importer { + private: + std::string _separator; + public: + explicit FllImporter(const std::string& separator = "\n"); + virtual ~FllImporter() FL_IOVERRIDE; + FL_DEFAULT_COPY_AND_MOVE(FllImporter) + + /** + Sets the separator of the language (default separator is a new line '\n') + @param separator is the separator of the language + */ + virtual void setSeparator(const std::string& separator); + /** + Gets the separator of the language (default separator is a new line '\n') + @return the separator of the language + */ + 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 Activation* parseActivation(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; + + }; +} + +#endif /* FL_FLLIMPORTER_H */ + diff --git a/fuzzylite/fl/imex/Importer.h b/fuzzylite/fl/imex/Importer.h new file mode 100644 index 0000000..1250e66 --- /dev/null +++ b/fuzzylite/fl/imex/Importer.h @@ -0,0 +1,71 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_IMPORTER_H +#define FL_IMPORTER_H + +#include "fl/fuzzylite.h" + +#include <string> + +namespace fl { + class Engine; + + /** + The Importer class is the abstract class for importers to configure an + Engine and its components from different text formats. + + @todo declare methods to import specific components + + @author Juan Rada-Vilela, Ph.D. + @see Exporter + @since 4.0 + */ + class FL_API Importer { + public: + + Importer(); + virtual ~Importer(); + FL_DEFAULT_COPY_AND_MOVE(Importer) + + /** + Imports the engine from the given text + @param text is the string representation of the engine to import from + @return the engine represented by the text + */ + virtual Engine* fromString(const std::string& text) const = 0; + /** + Imports the engine from the given file + @param path is the full path of the file containing the engine to import from + @return the engine represented by the file + */ + virtual Engine* fromFile(const std::string& path) const; + + /** + Returns the name of the importer + @return the name of the importer + */ + virtual std::string name() const = 0; + /** + Creates a clone of the importer + @return a clone of the importer + */ + virtual Importer* clone() const = 0; + }; +} + +#endif /* IMPORTER_H */ + diff --git a/fuzzylite/fl/imex/JavaExporter.h b/fuzzylite/fl/imex/JavaExporter.h new file mode 100644 index 0000000..a1817f6 --- /dev/null +++ b/fuzzylite/fl/imex/JavaExporter.h @@ -0,0 +1,152 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_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 Activation; + + /** + The JavaExporter class is an Exporter that translates an Engine and its + components to the `Java` programming language using the `jfuzzylite` + library. + + @author Juan Rada-Vilela, Ph.D. + @see CppExporter + @see Exporter + @since 4.0 + */ + class FL_API JavaExporter : public Exporter { + private: + bool _usingVariableNames; + public: + explicit JavaExporter(bool usingVariableNames = true); + virtual ~JavaExporter() FL_IOVERRIDE; + FL_DEFAULT_COPY_AND_MOVE(JavaExporter) + + virtual std::string name() const FL_IOVERRIDE; + + /** + Sets whether variables are exported using their names + (e.g., `power.setValue(Double.NaN)`) instead of numbered identifiers + (e.g., `inputVariable1.setValue(Double.NaN)`) + @param usingVariableNames indicates whether variables are exported using + their names + */ + virtual void setUsingVariableNames(bool usingVariableNames); + + /** + Gets whether variables are exported using their names + (e.g., `power.setValue(Double.NaN)`) instead of numbered identifiers + (e.g., `inputVariable1.setValue(Double.NaN)`) + @return whether variables are exported using their names + */ + virtual bool isUsingVariableNames() const; + + virtual std::string toString(const Engine* engine) const FL_IOVERRIDE; + /** + Returns a string representation of the InputVariable in the Java + programming language + @param inputVariable is the input variable + @param engine is the engine in which the input variable is registered + @return a string representation of the input variable in the Java + programming language + */ + virtual std::string toString(const InputVariable* inputVariable, const Engine* engine) const; + /** + Returns a string representation of the OutputVariable in the Java + programming language + @param outputVariable is the output variable + @param engine is the engine in which the output variable is registered + @return a string representation of the output variable in the Java + programming language + */ + virtual std::string toString(const OutputVariable* outputVariable, const Engine* engine) const; + /** + Returns a string representation of the RuleBlock in the Java + programming language + @param ruleBlock is the rule block + @param engine is the engine in which the rule block is registered + @return a string representation of the rule block in the Java + programming language + */ + virtual std::string toString(const RuleBlock* ruleBlock, const Engine* engine) const; + + /** + Returns a string representation of the Term in the Java programming + language + @param term is the term + @return a string representation of the term in the Java programming + language + */ + virtual std::string toString(const Term* term) const; + + /** + Returns a string representation of the Activation method in the Java + programming language + @param activation is the activation method + @return a string representation of the activation method in the Java + programming language + */ + virtual std::string toString(const Activation* activation) const; + + /** + Returns a string representation of the Defuzzifier in the Java + programming language + @param defuzzifier is the defuzzifier + @return a string representation of the defuzzifier in the Java + programming language + */ + virtual std::string toString(const Defuzzifier* defuzzifier) const; + + /** + Returns a string representation of the Norm in the Java programming + language + @param norm is the norm + @return a string representation of the norm in the Java programming + language + */ + virtual std::string toString(const Norm* norm) const; + + /** + Returns a string representation of the scalar value in the Java + programming language + @param value is the scalar value + @return a string representation of the scalar value in the Java + programming language + */ + virtual std::string toString(scalar value) const; + + virtual JavaExporter* clone() const FL_IOVERRIDE; + + }; +} + +#endif /* FL_JAVAEXPORTER_H */ + diff --git a/fuzzylite/fl/imex/RScriptExporter.h b/fuzzylite/fl/imex/RScriptExporter.h new file mode 100644 index 0000000..c53c751 --- /dev/null +++ b/fuzzylite/fl/imex/RScriptExporter.h @@ -0,0 +1,246 @@ +/* + fuzzylite (R), a fuzzy logic control library in C++. + Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. + Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the FuzzyLite License included with the software. + + You should have received a copy of the FuzzyLite License along with + fuzzylite. If not, see <http://www.fuzzylite.com/license/>. + + fuzzylite is a registered trademark of FuzzyLite Limited. + */ + +#ifndef FL_RSCRIPTEXPORTER_H +#define FL_RSCRIPTEXPORTER_H + +#include "fl/imex/Exporter.h" +#include "fl/imex/FldExporter.h" + +#include <vector> + +namespace fl { + class Engine; + class InputVariable; + class OutputVariable; + + /** + The RScriptExporter class is an Exporter that creates an R script to plot one or + more surfaces of an engine for two input variables and any number of output + variables. + + @author Juan Rada-Vilela, Ph.D. + @see FldExporter + @see Exporter + @since 6.0 + */ + class FL_API RScriptExporter : public Exporter { + private: + std::string _minimumColor; + std::string _maximumColor; + std::string _contourColor; + + public: + RScriptExporter(); + virtual ~RScriptExporter() FL_IOVERRIDE; + FL_DEFAULT_COPY_AND_MOVE(RScriptExporter) + + virtual std::string name() const FL_IOVERRIDE; + + /** + Sets the color to represent the minimum values. + @param minimumColor is the color to represent the minimum values + */ + void setMinimumColor(const std::string& minimumColor); + /** + Gets the color to represent the minimum values. + @return the color to represent the minimum values + */ + std::string getMinimumColor() const; + + /** + Sets the color to represent the maximum values. + @param maximumColor is the color to represent the maximum values + */ + void setMaximumColor(const std::string& maximumColor); + /** + Gets the color to represent the maximum values. + @return maximumColor is the color to represent the maximum values + */ + std::string getMaximumColor() const; + + /** + Sets the color to draw the contour lines + @param contourColor is the color to draw the contour lines + */ + void setContourColor(const std::string& contourColor); + /** + Gets the color to draw the contour lines + @return the color to draw the contour lines + */ + std::string getContourColor() const; + + /** + Returns an R script plotting multiple surfaces based on a data frame + generated with 1024 values in the scope of FldExporter::AllVariables + for the first two input variables. + @param engine is the engine to export + @return an R script plotting multiple surfaces for the first two input + variables in the engine. + */ + virtual std::string toString(const Engine* engine) const FL_IOVERRIDE; + + /** + Returns an R script plotting multiple surfaces based on a data frame + generated with the given number of values and scope for the two input + variables. + @param engine is the engine to export + @param a is the first input variable + @param b is the second input variable + @param values is the number of values to evaluate the engine + @param scope is the scope of the number of values to evaluate the engine + @param outputVariables are the output variables to create the surface for + @return an R script plotting multiple surfaces for the two input + variables on the output variables. + */ + virtual std::string toString(Engine* engine, InputVariable* a, InputVariable* b, + int values, FldExporter::ScopeOfValues scope, + const std::vector<OutputVariable*>& outputVariables) const; + + /** + Returns an R script plotting multiple surfaces based on the input stream + of values for the two input variables. + @param engine is the engine to export + @param a is the first input variable + @param b is the second input variable + @param reader is an input stream of data whose lines contain space-separated + input values + @param outputVariables are the output variables to create the surface for + @return an R script plotting multiple surfaces for the two input + variables on the output variables + */ + virtual std::string toString(Engine* engine, InputVariable* a, InputVariable* b, + std::istream& reader, const std::vector<OutputVariable*>& outputVariables) const; + + /** + Creates an R script file plotting multiple surfaces based on a data frame + generated with 1024 values in the scope of FldExporter::AllVariables + for the two input variables + @param filePath is the full path of the R script file + @param engine is the engine to export + */ + virtual void toFile(const std::string& filePath, const Engine* engine) const FL_IOVERRIDE; + + /** + Creates an R script file plotting multiple surfaces based on a data frame + generated with the given number of values and scope for the two input + variables + @param filePath is the full path of the R script file + @param engine is the engine to export + @param a is the first input variable + @param b is the second input variable + @param values is the number of values to evaluate the engine + @param scope is the scope of the number of values to evaluate the engine + @param outputVariables are the output variables to create the surface for + */ + virtual void toFile(const std::string& filePath, Engine* engine, + InputVariable* a, InputVariable* b, + int values, FldExporter::ScopeOfValues scope, + const std::vector<OutputVariable*>& outputVariables) const; + + /** + Creates an R script file plotting multiple surfaces based on the input stream + of values for the two input variables. + @param filePath is the full path of the R script file + @param engine is the engine to export + @param a is the first input variable + @param b is the second input variable + @param reader is an input stream of data whose lines contain space-separated + input values + @param outputVariables are the output variables to create the surface for + */ + virtual void toFile(const std::string& filePath, Engine* engine, + InputVariable* a, InputVariable* b, std::istream& reader, + const std::vector<OutputVariable*>& outputVariables) const; + + + /** + Writes an R script plotting multiple surfaces based on a manually + imported data frame containing the data for the two input variables + on the output variables. + @param engine is the engine to export + @param writer is the output where the engine will be written to + @param a is the first input variable + @param b is the second input variable + @param dataFramePath is the path where the data frame should be located + (the path will not be accessed, it will only be written to script) + @param outputVariables are the output variables to create the surface for + */ + virtual void writeScriptImportingDataFrame(const Engine* engine, std::ostream& writer, + InputVariable* a, InputVariable* b, const std::string& dataFramePath, + const std::vector<OutputVariable*>& outputVariables) const; + + /** + Writes an R script plotting multiple surfaces based on a data frame + generated with the given number of values and scope for the two input + variables on the output variables. + @param engine is the engine to export + @param writer is the output where the engine will be written to + @param a is the first input variable + @param b is the second input variable + @param values is the number of values to evaluate the engine + @param scope is the scope of the number of values to evaluate the engine + @param outputVariables are the output variables to create the surface for + */ + virtual void writeScriptExportingDataFrame(Engine* engine, std::ostream& writer, + InputVariable* a, InputVariable* b, int values, FldExporter::ScopeOfValues scope, + const std::vector<OutputVariable*>& outputVariables) const; + + /** + Writes an R script plotting multiple surfaces based on a data frame + generated with the given number of values and scope for the two input + variables on the output variables. + @param engine is the engine to export + @param writer is the output where the engine will be written to + @param a is the first input variable + @param b is the second input variable + @param reader is an input stream of data whose lines contain space-separated + input values + @param outputVariables are the output variables to create the surface for + */ + virtual void writeScriptExportingDataFrame(Engine* engine, std::ostream& writer, + InputVariable* a, InputVariable* b, std::istream& reader, + const std::vector<OutputVariable*>& outputVariables) const; + + protected: + /** + Writes the header of the R script (e.g., import libraries) + @param writer is the output where the header will be written to + @param engine is the engine to export + */ + virtual void writeScriptHeader(std::ostream& writer, const Engine* engine) const; + + /** + Writes the code to generate the surface plots for the input variables + on the output variables. + @param writer is the output where the engine will be written to + @param a is the first input variable + @param b is the second input variable + @param outputVariables are the output variables to create the surface for + */ + virtual void writeScriptPlots(std::ostream& writer, + InputVariable* a, InputVariable* b, + const std::vector<OutputVariable*>& outputVariables) const; + + + virtual RScriptExporter* clone() const FL_IOVERRIDE; + + }; + +} + +#endif /* FL_RSCRIPTEXPORTER_H */ + |