summaryrefslogtreecommitdiff
path: root/fuzzylite/fl/Console.h
blob: b96d677e63d71292f0bc677d7b987740b411a7a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 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_CONSOLE_H
#define FL_CONSOLE_H

#include "fl/fuzzylite.h"
#include <map>
#include <string>
#include <vector>

namespace fl {
    class Engine;

    /**
      The Console class is a command-line tool that helps to utilize the
      `fuzzylite` library.

      @author Juan Rada-Vilela, Ph.D.
      @since 4.0
     */
    class FL_API Console {
    public:

        /**
          A command-line option given by key, value and description
         */
        struct Option {
            std::string key, value, description;

            explicit Option(const std::string& key = "",
                    const std::string& value = "",
                    const std::string& description = "");
        };

        /**Keyword for input file*/
        static const std::string KW_INPUT_FILE;
        /**Keyword for input file format*/
        static const std::string KW_INPUT_FORMAT;
        /**Keyword for output file*/
        static const std::string KW_OUTPUT_FILE;
        /**Keyword for output file format*/
        static const std::string KW_OUTPUT_FORMAT;
        /**Keyword for built-in example*/
        static const std::string KW_EXAMPLE;
        /**Keyword for number of decimals*/
        static const std::string KW_DECIMALS;
        /**Keyword for file containing input data*/
        static const std::string KW_DATA_INPUT_FILE;
        /**Keyword for number of values to generate*/
        static const std::string KW_DATA_VALUES;
        /**Keyword for the scope of the number of values to generate*/
        static const std::string KW_DATA_VALUES_SCOPE;
        /**Keyword for exporting headers in FLD*/
        static const std::string KW_DATA_EXPORT_HEADER;
        /**Keyword for exporting input values in FLD*/
        static const std::string KW_DATA_EXPORT_INPUTS;

        /**
          Creates a new Mamdani Engine based on the SimpleDimmer example
          @return a new Mamdani Engine based on the SimpleDimmer example
         */
        static Engine* mamdani();
        /**
          Creates a new TakagiSugeno Engine based on the Approximation example of @f$sin(x)/x@f$
          @return a new TakagiSugeno Engine based on the Approximation example of @f$sin(x)/x@f$
         */
        static Engine* takagiSugeno();

        /**
         Creates a new Hybrid Engine based on the Tipper example using Mamdani
         and TakagiSugeno outputs.
         @return a new Hybrid Engine based on the Tipper example using Mamdani
         and TakagiSugeno outputs.
         */
        static Engine* hybrid();


    protected:
        virtual std::map<std::string, std::string> parse(int argc, const char* argv[]);
        virtual void process(const std::map<std::string, std::string>& options);

        virtual 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);

        virtual int readCharacter();
        virtual void interactive(std::ostream& writer, Engine* engine);
        virtual std::string interactiveHelp();

        virtual void exportAllExamples(const std::string& from, const std::string& to);
        virtual void exportAllExamples(const std::string& from, const std::string& to,
                const std::string& examplesPath, const std::string& outputPath);

        /**
       Benchmarks the engine described in the FLL file against the dataset
       contained in the FLD file.

       @param fllFile is the file describing the engine in FLL format
       @param fldFile is the file containing the dataset in FLD format
       @param runs is the number of runs to evaluate the benchmarks
       @param writer is the output where the results will be written to
       @throws Exception if something goes wrong reading the files, importing the
       engines or evaluating the benchmark
         */

        virtual void benchmark(const std::string& fllFile, const std::string& fldFile,
                int runs, std::ofstream* writer = fl::null) const;
        /**
          Benchmarks the list of engines against the list of datasets, both described
          as absolute or relative paths

          @param fllFileList is the file containing the list of paths of engines in
          FLL format
          @param fldFileList is the file containing the list of paths of datasets in
          FLD format
          @param runs is the number of runs to evaluate the benchmarks
          @param writer is the output where the results will be written to
          @throws Exception if something goes wrong reading the files, importing the
          engines or evaluating the benchmark
         */
        virtual void benchmarks(const std::string& fllFileList, const std::string& fldFileList,
                int runs, std::ofstream* writer = fl::null) const;

    public:
        /**
          Returns a string representation of the usage of the command-line tool
          @return a string representation of the usage of the command-line tool
         */
        virtual std::string usage();

        /**
          Returns a vector of the options available from the command line
          @return a vector of the options available from the command line
         */
        virtual std::vector<Option> availableOptions();

        static int main(int argc, const char* argv[]);
    };
}
#endif  /* FL_CONSOLE_H */