summaryrefslogtreecommitdiff
path: root/fuzzylite/fl/rule/Consequent.h
blob: 275d1e71487e29ef22a1e200a3eca68f5385239c (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
/*
 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_CONSEQUENT_H
#define FL_CONSEQUENT_H

#include "fl/fuzzylite.h"

#include "fl/Complexity.h"

#include <string>
#include <vector>

namespace fl {
    class Engine;
    class Rule;
    class Proposition;
    class TNorm;

    /**
      The Consequent class is a proposition set that represents and evaluates
      the consequent of a Rule.. The structure of a rule is: `if (antecedent)
      then (consequent)`. The structure of the consequent of a rule is:

      `then variable is [hedge]* term [and variable is [hedge]* term]* [with
      w]?`

      where `*`-marked elements may appear zero or more times, elements in
      brackets are optional, elements in parentheses are compulsory, and
      `?`-marked elements may appear once or not at all.

      @author Juan Rada-Vilela, Ph.D.
      @see Antecedent
      @see Rule
      @since 4.0
     */

    class FL_API Consequent {
    private:
        std::string _text;
        std::vector<Proposition*> _conclusions;

    public:
        Consequent();
        virtual ~Consequent();

        /**
          Sets the text of the consequent
          @param text is the text of the consequent
         */
        virtual void setText(const std::string& text);
        /**
          Gets the text of the consequent
          @return the text of the consequent
         */
        virtual std::string getText() const;

        /**
          Computes the estimated complexity of modifying the consequents
          @return the estimated complexity of modifying the consequents
         */
        virtual Complexity complexity(const TNorm* implication) const;
        /**
          Returns an immutable vector of the propositions that represent the 
          Consequent of a Rule
          @return an immutable vector of the set of propositions that represent
          the Consequent of a Rule
         */
        virtual const std::vector<Proposition*>& conclusions() const;

        /**
          Returns the vector of propositions that represent the Consequent of a 
          Rule
          @return the vector of propositions that represent the Consequent of a 
          Rule
         */
        virtual std::vector<Proposition*>& conclusions();

        /**
          Indicates whether the consequent is loaded
          @return whether the consequent is loaded
         */
        virtual bool isLoaded();
        /**
          Unloads the consequent
         */
        virtual void unload();
        /**
          Loads the consequent with text given from Consequent::getText() and
          uses the engine to identify and retrieve references to the input
          variables and output variables as required
          @param engine is the engine from which the rules are part of
         */
        virtual void load(const Engine* engine);
        /**
          Loads the consequent with the given text and uses the engine to
          identify and retrieve references to the input variables and output
          variables as required
          @param consequent is the consequent of the rule in text
          @param engine is the engine from which the rules are part of
         */
        virtual void load(const std::string& consequent, const Engine* engine);

        /**
          Modifies the proposition set according to the activation degree
          (computed in the Antecedent of the Rule) and the implication operator
          (given in the RuleBlock)
          @param activationDegree is the activation degree computed in the
          Antecedent of the Rule
          @param implication is the implication operator configured in the
          RuleBlock
         */
        virtual void modify(scalar activationDegree, const TNorm* implication);

        /**
          Returns a string representation of the Consequent
          @return a string representation of the Consequent
         */
        virtual std::string toString() const;

    private:
        FL_DISABLE_COPY(Consequent)
    };
}
#endif /* FL_CONSEQUENT_H */