00001
00009
00010
00011 #ifndef RULE_H
00012 #define RULE_H
00013
00014 #include <vector>
00015 #include "RCPtr.h"
00016 #include <stdarg.h>
00017 #include "FuzzySet.h"
00018 #include "FuzzyException.h"
00019 #include "RCPtr.h"
00020 #include "RCObject.h"
00021
00022
00023
00024 class FuzzyException;
00025 class LinguisticTerm;
00026 class RuleBase;
00027 class NDimFS;
00028
00029 enum Connective {
00030 AND,
00031 OR,
00032 PROD,
00033 PROBOR
00034 };
00035
00036
00037
00048 class Rule: virtual public RCObject {
00049 public:
00050 typedef std::vector< RCPtr<FuzzySet> > IORuleType;
00051 typedef std::vector< RCPtr<FuzzySet> > ConclusionType;
00052
00053
00058 Rule(Connective c=AND,
00059 RuleBase * belongsTo = NULL,
00060 double _weight = 1.0);
00061
00079 Rule( std::string ruleText,
00080 RuleBase * belongsTo,
00081 double _weight = 1.0 );
00082
00083
00084 virtual ~Rule();
00085
00096 double Activation(const std::vector<double> & inputs) const;
00097
00098
00099
00100
00101
00102
00113 inline double Activation(double input) const;
00114
00115
00116
00117
00118
00119
00120
00121
00122
00128 void setConnective(Connective con);
00129
00135 std::string printRule() const;
00136
00137
00143 virtual void addPremise(const RCPtr<LinguisticTerm> & lt);
00144
00151 virtual void addPremise(const RCPtr<LinguisticTerm> & lt1,
00152 const RCPtr<LinguisticTerm> & lt2);
00153
00161 virtual void addPremise(const RCPtr<LinguisticTerm> & lt1,
00162 const RCPtr<LinguisticTerm> & lt2,
00163 const RCPtr<LinguisticTerm> & lt3);
00164
00173 virtual void addPremise(const RCPtr<LinguisticTerm> & lt1,
00174 const RCPtr<LinguisticTerm> & lt2,
00175 const RCPtr<LinguisticTerm> & lt3,
00176 const RCPtr<LinguisticTerm> & lt4);
00177
00178
00179
00180
00181
00187 virtual void addConclusion(const RCPtr<LinguisticTerm>& lt);
00188
00194 NDimFS * getPremise();
00195
00201 inline const ConclusionType& getConclusion() const {
00202 return(conclusion);
00203 };
00204
00205
00211 inline double getWeight() const {
00212 return(weight);
00213 };
00214
00215 protected:
00216
00217 RuleBase * ruleBasePtr;
00218
00219 private:
00220
00221 typedef double ConnectiveFuncType( double, double );
00222
00223 ConnectiveFuncType* connectiveFunc;
00224
00225
00226 Connective ruleConnective;
00227 IORuleType premise;
00228 ConclusionType conclusion;
00229 double weight;
00230
00231
00232 void initializePremise();
00233
00234
00235 void setRule(IORuleType &, Connective, ConclusionType &);
00236 char* nextToken(char* tokenPtr);
00237 };
00238
00239 #endif