1 // cz - p��li� �lu�ou�k� k�� �p�l ��belsk� �dy 2 ///////////////////////////////////////////////////////////////////////////// 3 // fuzzy.h 4 // 5 // SIMLIB version: 2.16.4 6 // Date: 2001-04-04 7 // Copyright (c) 1999-2001 Dr. Ing. Petr Peringer, David Martinek 8 // 9 // This library is licensed under GNU Library GPL. See the file COPYING. 10 // 11 // Warning: this is EXPERIMENTAL code, interfaces can be changed 12 // 13 // Fuzzy subsystem for SIMLIB 14 // version 0.6 --- We apr 4 10:33:52 CEST 2001 15 // 16 // subsystem interfaces: 17 // - membership functions 18 // - fuzzy variable 19 // - fuzzification and defuzzification methods 20 // - fuzzy block 21 // - sampled fuzzy block 22 // - interfaces for typing inference rules in 23 // 24 25 26 #ifndef FUZZY_H 27 #define FUZZY_H 28 29 #if 0 30 #include <stdio.h> 31 #define TRACE(x) do{ if(1) x; } while(0) 32 #else 33 #define TRACE(x) 34 #endif 35 36 #include "simlib.h" 37 #include <vector> 38 39 namespace simlib3 { 40 41 /** 42 * @mainpage FuzzySIMLIB 43 * @version 1.0 44 * @author David Martinek 45 * @author Dr. Ing. Petr Peringer 46 * 47 * FuzzySIMLIB is part of SIMulation LIBrary including the fuzzy and xml module. 48 * 49 * FuzzySIMLIB je ��st� simula�n� knihovny SIMLIB a obsahuje fuzzy a xml modul. 50 */ 51 52 /** 53 * @defgroup fuzzy Fuzzy modul 54 * This module contains number of classes which is needed for fuzzy controllers modeling. 55 * 56 * Tento modul obsahuje soubor t��d pot�ebn�ch pro modelov�n� fuzzy regul�tor�. 57 */ 58 59 /** 60 * @defgroup xml XML modul 61 * General interface for loading of external data. Now only interface for reding fuzzy models 62 * from XML is implemented here. 63 * 64 * Obecn� rozhran� pro na��t�n� extern� ulo�en�ch dat. Prozat�m je zde implementov�no 65 * konkr�tn� rozhran� pro na��t�n� fuzzy model� z XML soubor�. 66 */ 67 68 69 /** 70 * @example auta.cc 71 * This is complete general interface example for typing inference rules in. Time for start 72 * is a little slower but the run is quite fast. This interface is quite uncomfortable. 73 * You can use rather interface which is described in FuzzyExpr and FuzzyGeneralRules classes. 74 * 75 * Toto je kompletn� p��klad pou�it� obecn�ho rozhran� pro zad�v�n� inferen�n�ch 76 * pravidel. Start tohoto programu je trochu del��, ale samotn� b�h modelu je 77 * pom�rn� rychl�. Toto rozhran� je celkem nepohodln�. Rad�ji pou��vejte rozhran� popsan� 78 * ve t��d�ch FuzzyExpr a FuzzyGeneralRules. 79 */ 80 /** 81 * @example auta2.cc 82 * This is comfortable general interface example for typing inference rules in. This is the 83 * slowest but the most general solution. 84 * 85 * P��klad komfortn�ho obecn�ho rozhran� pro z�pis inferen�n�ch pravidel. Toto je nejpomalej�� 86 * ale nejobecn�j�� �e�en�. 87 */ 88 /** 89 * @example autanottree.cc 90 * This is complete specialized interface example for typing infrence rules in. This is the most 91 * faster solution from all these examples. 92 * 93 * Toto je kompletn� p��klad pou�it� specializovan�ho rozhran� pro zad�v�n� inferen�n�ch 94 * pravidel. Pou�it�m tohoto rozhran� je inicializace modelu nejrychlej�� ze v�ech 95 * t�chto p��klad�. 96 */ 97 /** 98 * @example xml.cc 99 * This is complete example of use XML for model specification. The analyzis takes a quite 100 * muxh time, but it has no influence on time for run. This solution is most flexible. 101 * 102 * Toto je kompletn� p��klad pou�it� XML p�i specifikaci modelu. Anal�za xml zp�sobuje 103 * pom�rn� dlouhou inicialializaci, ale na b�h modelu nem� ��dn� vliv. Toto �e�en� 104 * je nejv�ce flexibiln�. 105 */ 106 /** 107 * @example ftycka.cc 108 * Next complete example of use XML for model specification. The analyzis takes a quite 109 * muxh time, but it has no influence on time for run. This solution is most flexible. 110 * 111 * Dal�� kompletn� p��klad pou�it� XML p�i specifikaci modelu. Anal�za xml zp�sobuje 112 * pom�rn� dlouhou inicialializaci, ale na b�h modelu nem� ��dn� vliv. Toto �e�en� 113 * je nejv�ce flexibiln�. 114 */ 115 116 117 ///////////////////////////////////////////////////////////////////////////// 118 // general membership function 119 ///////////////////////////////////////////////////////////////////////////// 120 /** 121 * Abstract baze class for membership functions.<br> 122 * Abstraktn� b�zov� t��da pro funkce p��slu�nosti. 123 * @ingroup fuzzy 124 */ 125 class FuzzyMembershipFunction 126 { 127 char *Name; /**< Word value. */ // TODO: std::string 128 protected: 129 int defValues; /**< Number of definition values. */ 130 public: 131 /** 132 * It assigns word value to the membership function. This does not copy poiner of parameter 133 * name, but it cretes copy of memory.<br> 134 * P�i�ad� slovn� hodnotu funkci p��slu�nosti. Nekop�ruje ukazatel parametru name, ale vytv��� 135 * kopii pam�ti. 136 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 137 */ 138 // implemented in fuzzymf.cc 139 FuzzyMembershipFunction(const char *name); 140 /** 141 * Copy constructor. It creates copy of all member variables. For poiners creates copy of 142 * memory block.<br> 143 * Kopy konstruktor. Vytv��� kopii v�ech �lensk�ch prom�nn�ch. Pro ukazatele vytvo�� kopii 144 * pam�ti. 145 * @param duplicate Object that will be duplicated.<br>Objekt, kter� bude duplikov�n. 146 */ 147 // implemented in fuzzymf.cc 148 FuzzyMembershipFunction(const FuzzyMembershipFunction &duplicate); 149 /** Destructor */ 150 // implemented in fuzzymf.cc 151 virtual ~FuzzyMembershipFunction(); 152 /** Gets word value of this function.<br>Vrac� slovn� hodnotu t�to funkce. */ wordValue()153 const char *wordValue() const { return Name; } 154 /** It duplicates object.<br>Duplikuje objekt. */ 155 virtual FuzzyMembershipFunction *clone() const = 0; 156 /** It computes function value (membership).<br>Vypo�te funk�n� hodnotu (p��slu�nost). */ 157 virtual double Membership(double x) const = 0; 158 /** Center of this function.<br>St�ed t�to funkce. */ 159 virtual double center() const = 0; 160 /** First occurence of maximum in this function.<br>Prvn� v�skyt maxima v t�to funkci. */ 161 virtual double min1() const = 0; 162 /** Last occurence of maximum in this function.<br>Posledn� v�skyt maxima v t�to funkci. */ 163 virtual double max1() const = 0; 164 /** Print of membership table.<br>Tisk tabulky p��slu�nosti. */ 165 // implemented in fuzzymf.cc 166 void Print(double a, double b) const; 167 /** Test if is definition of function complete.<br>Test jestli je definice funkce kompletn�. */ isComplete()168 bool isComplete() { return defValues == getNumValues(); } 169 /** This adds next definition value.<br>P�id� dal�� defini�n� hodnotu. */ 170 virtual void addDefValue(double value) = 0; 171 /** It retuns number of definition values.<br>Vr�t� po�et defini�n�ch hodnot. */ 172 virtual int getNumValues() = 0; 173 };//FuzzyMembershipFunction 174 175 ///////////////////////////////////////////////////////////////////////////// 176 // special membership functions: 177 ///////////////////////////////////////////////////////////////////////////// 178 /** 179 * Membership function of type impulse.<br> 180 * Funkce p��slu�nosti typu impuls. 181 * @ingroup fuzzy 182 */ 183 class FuzzySingleton: public FuzzyMembershipFunction 184 { 185 double x0; 186 public: 187 /** 188 * It assigns word value to the membership function and sets definition value.<br> 189 * P�i�ad� slovn� hodnotu funkci p��slu�nosti a nastav� defini�n� hodnotu. 190 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 191 * @param a A definition value.<br>Defini�n� hodnota. 192 */ 193 // implemented in fuzzymf.cc 194 FuzzySingleton(const char *name, double a); 195 /** 196 * It assigns word value to the membership function.<br> 197 * P�i�ad� slovn� hodnotu funkci p��slu�nosti. 198 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 199 */ 200 // implemented in fuzzymf.cc 201 FuzzySingleton(const char *name); 202 // implemented in fuzzymf.cc 203 ~FuzzySingleton()204 virtual ~FuzzySingleton() { TRACE(printf("~FuzzySingleton()\n")); } 205 /** It duplicates object.<br>Duplikuje objekt. */ 206 // implemented in fuzzymf.cc 207 virtual FuzzySingleton *clone() const; 208 /** It computes function value (membership).<br>Vypo�te funk�n� hodnotu (p��slu�nost). */ 209 // implemented in fuzzymf.cc 210 virtual double Membership(double x) const; 211 /** Center of this function.<br>St�ed t�to funkce. */ center()212 virtual double center() const { return x0; } 213 /** First occurence of maximum in this function.<br>Prvn� v�skyt maxima v t�to funkci. */ min1()214 virtual double min1() const { return x0; } 215 /** Last occurence of maximum in this function.<br>Posledn� v�skyt maxima v t�to funkci. */ max1()216 virtual double max1() const { return x0; } 217 /** This adds next definition value.<br>P�id� dal�� defini�n� hodnotu. */ 218 // implemented in fuzzymf.cc 219 virtual void addDefValue(double value); 220 /** It retuns number of definition values.<br>Vr�t� po�et defini�n�ch hodnot. */ getNumValues()221 virtual int getNumValues() { return 1; } 222 };//FuzzySingleton 223 224 /** 225 * Triangulal membership function.<br>Troj�heln�kov� funkce p��slu�nosti. 226 * @ingroup fuzzy 227 */ 228 class FuzzyTriangle: public FuzzyMembershipFunction 229 { 230 double x0, x1, x2; 231 public: 232 /** 233 * It assigns word value to the membership function and sets definition values.<br> 234 * P�i�ad� slovn� hodnotu funkci p��slu�nosti a nastav� defini�n� hodnotu. 235 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 236 * @param a A left vertex.<br>Lev� vrchol. 237 * @param b A center vertex.<br>Prost�edn� vrchol. 238 * @param c A right vertex.<br>Prav� vrchol. 239 */ 240 // implemented in fuzzymf.cc 241 FuzzyTriangle(const char *name, double a, double b, double c); 242 /** 243 * It assigns word value to the membership function.<br> 244 * P�i�ad� slovn� hodnotu funkci p��slu�nosti. 245 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 246 */ 247 // implemented in fuzzymf.cc 248 FuzzyTriangle(const char* name); 249 /** Destructor. */ ~FuzzyTriangle()250 virtual ~FuzzyTriangle() { TRACE(printf("~FuzzyTriangle\n")); } 251 /** It duplicates object.<br>Duplikuje objekt. */ 252 // implemented in fuzzymf.cc 253 virtual FuzzyTriangle *clone() const; 254 /** It computes function value (membership).<br>Vypo�te funk�n� hodnotu (p��slu�nost). */ 255 // implemented in fuzzymf.cc 256 virtual double Membership(double x) const; 257 /** Center of this function.<br>St�ed t�to funkce. */ center()258 virtual double center() const { return (x0+x1+x2)/3; } 259 /** First occurence of maximum in this function.<br>Prvn� v�skyt maxima v t�to funkci. */ min1()260 virtual double min1() const { return x1; } 261 /** Last occurence of maximum in this function.<br>Posledn� v�skyt maxima v t�to funkci. */ max1()262 virtual double max1() const { return x1; } 263 /** It retuns number of definition values.<br>Vr�t� po�et defini�n�ch hodnot. */ getNumValues()264 virtual int getNumValues() { return 3; } 265 /** This adds next definition value.<br>P�id� dal�� defini�n� hodnotu. */ 266 // implemented in fuzzymf.cc 267 virtual void addDefValue(double value); 268 };//FuzzyTriangle 269 270 ///////////////////////////////////////////////////////////////////////////// 271 // FuzzyTrapez --- 272 /** 273 * Trapezoidal membership function.<br> 274 * Lichob�n�kov� funkce p��slu�nosti. 275 * @ingroup fuzzy 276 */ 277 class FuzzyTrapez: public FuzzyMembershipFunction 278 { 279 double x0, x1, x2, x3; 280 public: 281 /** 282 * It assigns word value to the membership function and sets definition values.<br> 283 * P�i�ad� slovn� hodnotu funkci p��slu�nosti a nastav� defini�n� hodnotu. 284 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 285 * @param a A left down vertex.<br>Lev� spodn� vrchol. 286 * @param b A left top vertex.<br>Lev� horn� vrchol. 287 * @param c A right top vertex.<br>Prav� horn� vrchol. 288 * @param d A right down vertex.<br>Prav� spodn� vrchol. 289 */ 290 // implemented in fuzzymf.cc 291 FuzzyTrapez(const char *name, double a, double b, double c, double d); 292 /** 293 * It assigns word value to the membership function.<br> 294 * P�i�ad� slovn� hodnotu funkci p��slu�nosti. 295 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 296 */ 297 // implemented in fuzzymf.cc 298 FuzzyTrapez(const char* name); 299 /** Destructor. */ ~FuzzyTrapez()300 virtual ~FuzzyTrapez() { TRACE(printf("~FuzzyTrapez()\n")); } 301 /** It duplicates object.<br>Duplikuje objekt. */ 302 // implemented in fuzzymf.cc 303 virtual FuzzyTrapez *clone() const; 304 /** It computes function value (membership).<br>Vypo�te funk�n� hodnotu (p��slu�nost). */ 305 // implemented in fuzzymf.cc 306 virtual double Membership(double x) const; 307 // virtual double center() const { return (x1+x2)/2; } // bad### 308 /** Center of this function.<br>St�ed t�to funkce. */ center()309 virtual double center() const { return (x0+2*x1+2*x2+x3)/6; } 310 /** First occurence of maximum in this function.<br>Prvn� v�skyt maxima v t�to funkci. */ min1()311 virtual double min1() const { return x1; } 312 /** Last occurence of maximum in this function.<br>Posledn� v�skyt maxima v t�to funkci. */ max1()313 virtual double max1() const { return x2; } 314 /** It retuns number of definition values.<br>Vr�t� po�et defini�n�ch hodnot. */ getNumValues()315 virtual int getNumValues() { return 4; } 316 /** This adds next definition value.<br>P�id� dal�� defini�n� hodnotu. */ 317 // implemented in fuzzymf.cc 318 virtual void addDefValue(double value); 319 };// FuzzyTrapez 320 321 ///////////////////////////////////////////////////////////////////////////// 322 // FuzzyGauss --- 323 /** 324 * Gaussian membership function.<br> 325 * Gaussovsk� funkce p��slu�nosti. 326 * @ingroup fuzzy 327 */ 328 class FuzzyGauss: public FuzzyMembershipFunction 329 { 330 double sigma, c, twoSqrSigma; 331 public: 332 /** 333 * It assigns word value to the membership function and sets definition values.<br> 334 * P�i�ad� slovn� hodnotu funkci p��slu�nosti a nastav� defini�n� hodnoty. 335 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 336 * @param center A center of function.(mi) <br>St�ed funkce. (mi) 337 * @param radius A radius of function. (3*sigma)<br>Polom�r funkce. (3*sigma) 338 */ 339 // implemented in fuzzymf.cc 340 FuzzyGauss(const char *name, double center, double radius); 341 /** 342 * It assigns word value to the membership function.<br> 343 * P�i�ad� slovn� hodnotu funkci p��slu�nosti. 344 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 345 */ 346 // implemented in fuzzymf.cc 347 FuzzyGauss(const char* name); 348 /** Destructor. */ ~FuzzyGauss()349 virtual ~FuzzyGauss() { TRACE(printf("~FuzzyGauss()\n")); } 350 /** It duplicates object.<br>Duplikuje objekt. */ 351 // implemented in fuzzymf.cc 352 virtual FuzzyGauss *clone() const; 353 /** It computes function value (membership).<br>Vypo�te funk�n� hodnotu (p��slu�nost). */ 354 // implemented in fuzzymf.cc 355 virtual double Membership(double x) const; 356 /** Center of this function.<br>St�ed t�to funkce. */ center()357 virtual double center() const { return c; } 358 /** First occurence of maximum in this function.<br>Prvn� v�skyt maxima v t�to funkci. */ min1()359 virtual double min1() const { return c; } 360 /** Last occurence of maximum in this function.<br>Posledn� v�skyt maxima v t�to funkci. */ max1()361 virtual double max1() const { return c; } 362 /** It retuns number of definition values.<br>Vr�t� po�et defini�n�ch hodnot. */ getNumValues()363 int getNumValues() { return 2; } 364 /** This adds next definition value.<br>P�id� dal�� defini�n� hodnotu. */ 365 // implemented in fuzzymf.cc 366 virtual void addDefValue(double value); 367 };// FuzzyGauss 368 369 /** 370 * Nonsymetric Gaussian membership function.<br> 371 * Nesymetrick� Gaussovsk� funkce p��slu�nosti. 372 * @ingroup fuzzy 373 */ 374 class FuzzyGauss2 : public FuzzyMembershipFunction 375 { 376 public: 377 /** 378 * It assigns word value to the membership function and sets definition values.<br> 379 * P�i�ad� slovn� hodnotu funkci p��slu�nosti a nastav� defini�n� hodnoty. 380 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 381 * @param leftCenter A center of the left function.(mi) <br>St�ed lev� funkce. (mi) 382 * @param leftRadius A radius of the left function. (3*sigma)<br>Polom�r lev� funkce. (3*sigma) 383 * @param rightCenter A center of the right function.(mi) <br>St�ed prav� funkce. (mi) 384 * @param rightRadius A radius of the right function. (3*sigma)<br>Polom�r prav� funkce. (3*sigma) 385 */ 386 // implemented in fuzzymf.cc 387 FuzzyGauss2(const char* name, 388 double leftCenter, double leftRadius, 389 double rightCenter, double rightRadius); 390 /** 391 * It assigns word value to the membership function.<br> 392 * P�i�ad� slovn� hodnotu funkci p��slu�nosti. 393 * @param name Word value for this function.<br>Slovn� hodnota pro tuto funkci 394 */ 395 // implemented in fuzzymf.cc 396 FuzzyGauss2(const char* name); 397 /** Destructor. */ ~FuzzyGauss2()398 virtual ~FuzzyGauss2() { TRACE(printf("~FuzzyGauss2()\n")); } 399 /** It duplicates object.<br>Duplikuje objekt. */ 400 // implemented in fuzzymf.cc 401 virtual FuzzyGauss2 *clone() const; 402 /** It computes function value (membership).<br>Vypo�te funk�n� hodnotu (p��slu�nost). */ 403 // implemented in fuzzymf.cc 404 virtual double Membership(double x) const; 405 /** Center of this function.<br>St�ed t�to funkce. */ 406 // implemented in fuzzymf.cc 407 virtual double center() const; 408 /** First occurence of maximum in this function.<br>Prvn� v�skyt maxima v t�to funkci. */ 409 // implemented in fuzzymf.cc 410 virtual double min1() const; 411 /** Last occurence of maximum in this function.<br>Posledn� v�skyt maxima v t�to funkci. */ 412 // implemented in fuzzymf.cc 413 virtual double max1() const; 414 /** It retuns number of definition values.<br>Vr�t� po�et defini�n�ch hodnot. */ getNumValues()415 int getNumValues() { return 4; } 416 /** This adds next definition value.<br>P�id� dal�� defini�n� hodnotu. */ 417 // implemented in fuzzymf.cc 418 virtual void addDefValue(double value); 419 protected: 420 double leftSigma; /**< A radius of the left function. */ 421 double leftCenter; /**< A center of the left function. */ 422 double rightSigma; /**< A radius of the right function. */ 423 double rightCenter; /**< A center of the right function. */ 424 /** Position of vertex when leftCenter > rightCenter.<br>Pozice vrcholu, kdy� leftCenter > rightCenter. */ 425 // implemented in fuzzymf.cc 426 double vertexPosition() const; 427 private: 428 double twoSqrSigmaL; /**< 2*leftSigma*leftSigma */ 429 double twoSqrSigmaR; /**< 2*rightSigma*rightSigma */ 430 }; 431 432 // TODO: add other mf 433 434 ///////////////////////////////////////////////////////////////////////////// 435 // FuzzySet --- definition of all membership functions for fuzzy set 436 // 437 // TODO: make INTERNAL to fuzzy set, use reference counting??? 438 // add load/store 439 // dynamic change of parameters 440 // 441 /** 442 * Implementation of a fuzzy set.<br> 443 * Implementace fuzzy mno�iny. 444 * @ingroup fuzzy 445 */ 446 class FuzzySet 447 { 448 protected: 449 unsigned n; /**< actual number of elements */ 450 enum { MAX=10 }; /**< implementation limit */ 451 const FuzzyMembershipFunction *array[MAX]; /**< is owner of objects on pointers */ 452 double xmin, xmax; /**< limits */ 453 char * Name; /**< name of this set */ 454 public: 455 /** 456 * Creates fuzzy set. 457 * @param min Minimal value of universum.<br>Spodn� mez univerza. 458 * @param max Maximal value of universum.<br>Horn� mez univerza. 459 */ 460 // implemented in fuzzy.cc 461 FuzzySet(const char * name, double min, double max, 462 const FuzzyMembershipFunction &m1); 463 /** 464 * Creates fuzzy set. 465 * @param min Minimal value of universum.<br>Spodn� mez univerza. 466 * @param max Maximal value of universum.<br>Horn� mez univerza. 467 */ 468 // implemented in fuzzy.cc 469 FuzzySet(const char * name, double min, double max, 470 const FuzzyMembershipFunction &m1, 471 const FuzzyMembershipFunction &m2); 472 /** 473 * Creates fuzzy set. 474 * @param min Minimal value of universum.<br>Spodn� mez univerza. 475 * @param max Maximal value of universum.<br>Horn� mez univerza. 476 */ 477 // implemented in fuzzy.cc 478 FuzzySet(const char * name, double min, double max, 479 const FuzzyMembershipFunction &m1, 480 const FuzzyMembershipFunction &m2, 481 const FuzzyMembershipFunction &m3); 482 /** 483 * Creates fuzzy set. 484 * @param min Minimal value of universum.<br>Spodn� mez univerza. 485 * @param max Maximal value of universum.<br>Horn� mez univerza. 486 */ 487 // implemented in fuzzy.cc 488 FuzzySet(const char * name, double min, double max, 489 const FuzzyMembershipFunction &m1, 490 const FuzzyMembershipFunction &m2, 491 const FuzzyMembershipFunction &m3, 492 const FuzzyMembershipFunction &m4); 493 /** 494 * Creates fuzzy set. 495 * @param min Minimal value of universum.<br>Spodn� mez univerza. 496 * @param max Maximal value of universum.<br>Horn� mez univerza. 497 */ 498 // implemented in fuzzy.cc 499 FuzzySet(const char * name, double min, double max, 500 const FuzzyMembershipFunction &m1, 501 const FuzzyMembershipFunction &m2, 502 const FuzzyMembershipFunction &m3, 503 const FuzzyMembershipFunction &m4, 504 const FuzzyMembershipFunction &m5); 505 /** 506 * Creates fuzzy set. 507 * @param min Minimal value of universum.<br>Spodn� mez univerza. 508 * @param max Maximal value of universum.<br>Horn� mez univerza. 509 */ 510 // implemented in fuzzy.cc 511 FuzzySet(const char * name, double min, double max); 512 /** Destructor removes all membership functions.<br>Destruktor uvoln� v�echny funkce p��slu�nosti. */ 513 // implemented in fuzzy.cc 514 virtual ~FuzzySet(); 515 /** It duplicates object.<br>Duplikuje objekt. */ 516 // implemented in fuzzy.cc 517 virtual FuzzySet *clone() const; 518 /** 519 * It adds next word value into the universum.<br>P�id� dal�� slovn� hodnotu do univerza. 520 * @param x Membership function representing word value.<br>Funkce p��slu�nosti reprezentuj�c� slovn� hodnotu. 521 */ 522 // implemented in fuzzy.cc 523 void add(const FuzzyMembershipFunction &x); 524 /** Number of membership functions.<br>Po�et funkc� p��slu�nosti. */ count()525 int count() const { return n; } 526 /** It selects i-th member function.<br>Vybere i-tou funkci p��slu�nosti. */ 527 // implemented in fuzzy.cc 528 virtual const FuzzyMembershipFunction *operator[] (int i) const; 529 /** It computes i-th function value (membership).<br>Vypo�te i-tou funk�n� hodnotu (p��slu�nost). */ 530 // implemented in fuzzy.cc 531 double Membership(int i, double x) const; 532 /** Minimal value of universum.<br>Spodn� mez univerza. */ min()533 double min() { return xmin; } 534 /** Maximal value of universum.<br>Horn� mez univerza. */ max()535 double max() { return xmax; } 536 /** Name of this fuzzy set.<br>Jm�no t�to fuzzy mno�iny. */ name()537 const char * name() const { return Name; } 538 /** Word value of i-th membership function.<br>Slovn� hodnota i-t� funkce p��slu�nosti. */ wordValue(int i)539 const char * wordValue(int i) const { return array[i]->wordValue(); } 540 /** Minimum of maxims.<br>Minimum z maxim. */ 541 // implemented in fuzzy.cc 542 double min1(); // min of 1 543 /** Maximum of maxims.<br>Maximum z maxim. */ 544 // implemented in fuzzy.cc 545 double max1(); // max of 1 546 547 }; // FuzzySet 548 549 550 ///////////////////////////////////////////////////////////////////////////// 551 // FuzzyVariable --- fuzzy set 552 // 553 //TODO: dynamic change of variable type 554 // 555 class FuzzyBlock; // forward 556 /** 557 * General fuzzy variable. Baze class for FuzzyInput and FuzzyOutput.<br> 558 * Obecn� fuzzy prom�nn�. B�zov� t��da pro FuzzyInput a FuzzyOutput. 559 * @ingroup fuzzy 560 */ 561 class FuzzyVariable : public aContiBlock 562 { 563 FuzzyBlock *where; /**< location */ 564 // const FuzzySet *m; /**< pattern: n membership functions, parameters */ 565 FuzzySet *m; /**< pattern: n membership functions, parameters */ 566 const unsigned n; /**< number of values */ 567 double *mval; /**< membership values, dynamically, size given by m */ 568 public: 569 /** 570 * It connects fuzzy set with variable. If it is created inside FuzzyBlock then it is not need 571 * to call registerOwner. Object FuzzySet is cloned and stored inside. Therefore you must release 572 * memory allocated by t in your way.<br> 573 * Spoj� fuzzy mno�inu s fuzzy prom�nnou. Pokud je prom�nn� vytv��ena 574 * uvnit� t��dy FuzzyBlock, nen� t�eba volat metodu registerOwner. Objekt FuzzySet je p�i p�ed�n� 575 * klonov�n a ulo�en uvnit� objektu. Proto mus�te uvolnit pam� alokovanou pro t vy sami. 576 * @param t Fuzzy set.<br>Fuzzy mno�ina. 577 */ 578 // implemented in fuzzy.cc 579 FuzzyVariable(const FuzzySet &t); 580 /** It releases memory allocated by FuzzySet.<br>Uvoln� pam� alokovanou pro FuzzySet. */ ~FuzzyVariable()581 virtual ~FuzzyVariable() 582 { 583 TRACE(printf("~FuzzyVariable()\n")); 584 delete m; 585 delete [] mval; 586 } 587 588 /** 589 * It registers owner of this variable.<br>Zaregistruje vlastn�ka t�to prom�nn�. 590 * @param owner Owner of this variable.<br>Vlastn�k t�to prom�nn�. 591 */ 592 // implemented in fuzzy.cc 593 void registerOwner(FuzzyBlock *owner); // registration inside owner 594 /** Number of members.<br>Po�et �len�. */ count()595 unsigned count() const { return n; } 596 /** I-th member function.<br>I-t� funkce p��slu�nosti. */ 597 // implemented in fuzzy.cc 598 const FuzzyMembershipFunction *mf(int i) const; 599 /** It gets center of i-th member function.<br>Vrac� st�ed i-t� funkce p��slu�nosti. */ 600 // implemented in fuzzy.cc 601 double center(int i) const; 602 /** It gets i-th word value.<br>Vrac� i-tou slovn� hondotu. */ 603 // implemented in fuzzy.cc 604 const char *wordValue(int i) const; // name of i-th membership function 605 /** Get/set fuzzy value.<br>Vra�/nastav fuzzy hodnotu. */ 606 // implemented in fuzzy.cc 607 double &operator[] (int i) const; 608 /** Get/set fuzzy value.<br>Vra�/nastav fuzzy hodnotu. */ 609 double &operator[] (const char *s) const { return mval[search(s)]; } 610 /** Search by member name.<br>Hled� podle jm�na. */ 611 // implemented in fuzzy.cc 612 unsigned search(const char *s) const; 613 614 /** Fuzzify all membership functions.<br>Fuzzifikuje v�echny funkce p��slu�nosti.*/ 615 // implemented in fuzzyio.cc 616 void Fuzzify(double x); 617 /** 618 * Initializes all values for membership functions or fuzzify all value<br> 619 * Inicializuje v�echny hodnoty funkc� p��slu�nosti nebo provede fuzzifikaci. 620 */ Init()621 virtual void Init() { for(unsigned i=0; i!=n; i++) mval[i]=0.0F; } Done()622 virtual void Done() {} 623 /** It gets owner.<br>Vrac� vlastn�ka. */ Where()624 FuzzyBlock *Where() // location 625 { 626 // if(where==0) SIMLIB_error("Fuzzy set should be used inside FuzzyBlock only"); 627 return where; 628 } 629 // implemented in fuzzy.cc 630 void Print(); // print contents 631 private: 632 // implemented in fuzzy.cc 633 double SetMembership(int i, double x); 634 }; // FuzzyVariable 635 636 ///////////////////////////////////////////////////////////////////////////// 637 // FuzzyInput --- continuous input fuzzy variable 638 // 639 /** 640 * Input varible. It fuzzifies inputs. I.e. it gets Input value and transforms this 641 * sharp value into fuzzy reprezentation.<br> 642 * Vstupn� prom�nn�. Fuzzifikuje vstup. To znamen�, �e vezme ostrou vstupn� hodnotu 643 * (Input) a transformuje ji do fuzzy reprezentace. 644 * @ingroup fuzzy 645 */ 646 class FuzzyInput : public FuzzyVariable { 647 Input in; /**< continuous input */ 648 public: 649 /** 650 * It assignes continuous input and fuzzy set into this object.<br> 651 * P�i�ad� spojit� vstup a fuzzy mno�inu do tohoto objektu. 652 * @param i Continuous input.<br>Spojit� vstup. 653 * @param t Fuzzy set.<br>Fuzzy mno�ina. 654 */ FuzzyInput(Input i,const FuzzySet & t)655 FuzzyInput(Input i, const FuzzySet &t) : FuzzyVariable(t), in(i) {} 656 /** 657 * It assignes only fuzzy set into this object. Continuous input must be 658 * added by setInput method. <br> 659 * P�i�ad� tomuto objektu pouze fuzzy mno�inu. Spojit� vstup mus� b�t 660 * p�id�n pomoc� metody setInput. 661 * @param t Fuzzy set.<br>Fuzzy mno�ina. 662 */ FuzzyInput(const FuzzySet & t)663 FuzzyInput(const FuzzySet &t) : FuzzyVariable(t), in(0.0) {} 664 /** Destructor. */ ~FuzzyInput()665 virtual ~FuzzyInput() { TRACE(printf("~FuzzyInput()\n")); } 666 /** 667 * It adds continuous input into this object.<br> 668 * P�id� spojit� vstup do tohoto objektu. 669 * @param i Continuous input.<br>Spojit� vstup. 670 */ setInput(Input i)671 void setInput(Input i) { in = i; } 672 /** 673 * It returns sharp input value.<br>Vrac� ostrou vstupn� hodnotu. 674 * @return It returns sharp input value.<br>Vrac� ostrou vstupn� hodnotu. 675 */ Value()676 virtual double Value() { return in.Value(); } 677 /** 678 * It fuzzifies continuous input. This method is called every time before call 679 * to FuzzyBlock::Behavior().<br> 680 * Fuzzifikuje spojit� vstup. Tato metoda je vol�na v�dy p�ed vol�n�m 681 * FuzzyBlock::Behavior(). 682 */ Init()683 virtual void Init() { Fuzzify(in.Value()); } 684 // virtual void Done() {} 685 };// FuzzyInput 686 687 688 ///////////////////////////////////////////////////////////////////////////// 689 // FuzzyOutput --- continuous output (aggregation, defuzzification) 690 // 691 /** 692 * Output variable. It defuzzifies fuzzy values, which is obtained by processing 693 * inference rules.<br> 694 * V�stupn� prom�nn�. Defuzzifikuje fuzzy hodnoty, kter� jsou z�sk�ny zpracov�n�m 695 * inferen�n�ch pravidel. 696 * @ingroup fuzzy 697 */ 698 class FuzzyOutput: public FuzzyVariable { 699 double value; /**? value after defuzzification */ 700 double (*defuzzify)(const FuzzyVariable&); /**< defuzzification function */ // remove!!!!!!!#### 701 public: 702 /** 703 * It adds fuzzy set and defuzzification function.<br> 704 * P�id� fuzzy mno�inu a defuzzifika�n� funkci. 705 * @param t Fuzzy set.<br>Fuzzy mno�ina. 706 * @param def Defuzzification function.<br>Defuzzifika�n� funkce. 707 */ 708 // implemented in fuzzyrul.cc 709 FuzzyOutput(const FuzzySet &t, double (*def)(const FuzzyVariable&)=0); 710 /** 711 * It assignes fuzzy value by word value.<br>P�i�ad� fuzzy hodnotu pomoc� slovn� hodnoty. 712 */ 713 // implemented in fuzzyrul.cc 714 const char *operator = (const char *val); 715 /** 716 * It defuzzifies itself.<br> Defuzzifikuje se. 717 * @return It returns sharp value.<br>Vr�t� osrou hodnotu. 718 */ 719 // implemented in fuzzyrul.cc 720 double Defuzzify(); 721 /** It adds defuzzification function.<br>P�id� defuzzifika�n� funkci. */ 722 // implemented in fuzzyrul.cc 723 void SetDefuzzifyMethod(double (*f)(const FuzzyVariable&)); 724 /** 725 * Evaluates FuzzyBlock (variable where) and after defuzzification returns sharp value.<br> 726 * Vyhodnot� FuzzyBlock (prom�nnou whera) a po defuzzifikaci vr�t� ostrou hodnotu. 727 * @return Sharp value after defuzzification.<br>Ostr� hodnota po defuzzifikaci. 728 */ 729 // implemented in fuzzyrul.cc 730 double Value(); 731 //inherited: virtual void Init() { for(int i=0; i<n; i++) mval[i]=0.0F; } 732 /** 733 * It defuzzifies itself.<br> Defuzzifikuje se. 734 */ Done()735 virtual void Done() { Defuzzify(); } 736 // implemented in fuzzyrul.cc 737 virtual ~FuzzyOutput(); 738 }; // FuzzyOutput 739 740 ///////////////////////////////////////////////////////////////////////////// 741 // defuzzification methods 742 // 743 744 // TODO: function objects X x(params) a=x(fset) 745 // indexed-centre-of-gravity 746 //double i_g_centre(const FuzzyVariable &fs, double lim=0.0F); 747 //double centroid(const FuzzyVariable &fs); 748 // implemented in fuzzyio.cc 749 /** 750 * @ingroup fuzzy 751 * Defuzzification method "mean-of-maximum".<br>Defuzifika�n� metoda "st�ed maxim". 752 */ 753 double defuzMeanOfMax(const FuzzyVariable &fs); 754 /** 755 * @ingroup fuzzy 756 * Defuzzification method "min-of-maximum".<br>Defuzifika�n� metoda "minim�ln� maximum". 757 */ 758 // implemented in fuzzyio.cc 759 double defuzMinOfMax(const FuzzyVariable &fs); 760 /** 761 * @ingroup fuzzy 762 * Defuzzification method "max-of-maximum".<br>Defuzifika�n� metoda "maxim�ln� maximum". 763 */ 764 // implemented in fuzzyio.cc 765 double defuzMaxOfMax(const FuzzyVariable &fs); 766 /** 767 * @ingroup fuzzy 768 * Defuzzification method "discrete-center-of-gravity".<br>Defuzifika�n� metoda "diskr�tn� t�i�t�". 769 */ 770 // implemented in fuzzyio.cc 771 double defuzDCOG(const FuzzyVariable &fs); 772 773 ///////////////////////////////////////////////////////////////////////////// 774 // FuzzyBlock --- base class for inference blocks 775 // 776 /** 777 * Base class for inference blocks. Representation of fuzzy regulator. <br> 778 * B�zov� t��da pro inferen�n� bloky. Reprezentace fuzzy regul�toru. 779 * @ingroup fuzzy 780 */ 781 class FuzzyBlock 782 { 783 protected: 784 FuzzyBlock *where; /**< position in hierarchical structure */ 785 double lastTime; /**< time of last evaluation */ 786 virtual void Behavior() = 0; /**< user defined fuzzy rules */ 787 dlist<FuzzyVariable*> vlist; /**< all fuzzy variables in the block */ 788 public: 789 /** 790 * If inference rules are specified by FuzzyExpr way then you must call 791 * EndConstructor method on the end of constructor.<br> 792 * Jestli�e jsou inferen�n� pravidla specifikov�na pomoc� FuzzyExpr, pak mus�te 793 * zavolat metodu EndConstructor na konci konstruktoru. 794 */ 795 // implemented in fuzzyrul.cc 796 FuzzyBlock(); 797 /** 798 * It evaluates whole block. It calls method Behavior.<br> 799 * Vyhodnot� cel� blok. Vol� metodu Behavior. 800 */ 801 // implemented in fuzzyrul.cc 802 virtual void Evaluate(); // calls Behavior() 803 /** 804 * If inference rules are specified by FuzzyExpr way then you must call this 805 * method on the end of constructor.<br> 806 * Jestli�e jsou inferen�n� pravidla specifikov�na pomoc� FuzzyExpr, pak mus�te 807 * zavolat tuto metodu na konci konstruktoru. 808 */ 809 // implemented in fuzzyrul.cc 810 void EndConstructor(); // ### marks end, should be called in constructor 811 /** 812 * It registers fuzzy variable inside this object. If inference rules are NOT specified 813 * by FuzzyExpr way then you must call this method inside the constructor for all FuzzyInput 814 * and FuzzyOutput variables.<br> 815 * Registruje fuzzy prom�nnou v tomto objektu. Jestli�e NEjsou inferen�n� pravidla 816 * specifikov�na pomoc� FuzzyExpr, pak mus�te zavolat tuto metodu v konstruktoru pro v�echny 817 * prom�nn� typu FuzzyInput a FuzzyOutput. 818 */ 819 // implemented in fuzzyrul.cc 820 void Register(FuzzyVariable *obj); // register variable in vlist ~FuzzyBlock()821 virtual ~FuzzyBlock() { TRACE(printf("~FuzzyBlock()\n")); } 822 }; // FuzzyBlock 823 824 825 ///////////////////////////////////////////////////////////////////////////// 826 // Author: David Martniek 827 /** 828 * Base class for inference blocks with sampled input.<br> 829 * B�zov� t��da pro inferen�n� bloky se vzorkovan�m vstupem 830 * @ingroup fuzzy 831 */ 832 class FuzzySampledBlock 833 : public FuzzyBlock 834 { 835 /** 836 * Inner class for sampling 837 * Vnit�n� t��da pro vzorkov�n� 838 * @ingroup fuzzy 839 */ 840 class FSampler 841 : public Event 842 { 843 844 double timeStep; 845 FuzzySampledBlock *parent; 846 public: 847 /** 848 * Creates sampler<br>Vytvo�� vzorkova�. 849 * @param parent owner of this class<br>vlastn�k t�to t��dy 850 */ FSampler(FuzzySampledBlock * parent)851 FSampler(FuzzySampledBlock *parent) 852 { 853 this->parent = parent; 854 timeStep = 0; 855 } ~FSampler()856 ~FSampler() { TRACE(printf("~FSampler()\n")); parent = 0; } 857 /** It sets the time step for sampling.<br> Nastav� �asov� krok pro vzorkov�n�. */ setTimeStep(double timeStep)858 void setTimeStep(double timeStep) { this->timeStep = timeStep; } 859 /** It gets time step.<br>Vr�t� �asov� krok. */ getTimeStep()860 double getTimeStep() { return timeStep; } 861 /** 862 * Sampling - it evaluates the parent object and shedules next activacion.<br> 863 * Vzorkov�n� - vyhodnot� rodi�ovsk� objekt a napl�nuje dal�� spu�t�n�. 864 */ Behavior()865 void Behavior() 866 { 867 parent->Evaluate(); 868 Activate(Time+timeStep); 869 } 870 }; 871 872 FSampler *sampler; 873 874 /** 875 * Will contain user defined inference rules.<br> 876 * Bude obsahovat u�ivatelem definovan� inferen�n� pravidla. 877 */ 878 virtual void Behavior() = 0; 879 public: 880 /** 881 * It creates and initializes the sampler object. 882 * If inference rules are specified by FuzzyExpr way then you must call 883 * EndConstructor method on the end of constructor.<br> 884 * Vytvo�� a inicalizuje vzorkova�. 885 * Jestli�e jsou inferen�n� pravidla specifikov�na pomoc� FuzzyExpr, pak mus�te 886 * zavolat metodu EndConstructor na konci konstruktoru. 887 */ FuzzySampledBlock()888 FuzzySampledBlock() { sampler = new FSampler(this); } ~FuzzySampledBlock()889 virtual ~FuzzySampledBlock() { TRACE(printf("~FuzzySampledBlock")); } 890 /** 891 * It sets the time step for sampling.<br> 892 * Nastav� �asov� krok pro vzorkov�n�. 893 */ setTimeStep(double timeStep)894 void setTimeStep(double timeStep) { sampler->setTimeStep(timeStep); } 895 /** It gets time step.<br> Vr�t� �asov� krok. */ getTimeStep()896 double getTimeStep() { return sampler->getTimeStep(); } 897 /** It starts sampling.<br> Nastartuje vzorkov�n�. */ Start()898 void Start() { sampler->Activate(); } 899 /** 900 * It evaluates fuzzy inference rules but only in sampled time steps.<br> 901 * Vyhodnot� fuzzy inferen�n� pravidla, ale jenom ve vzorkovan�ch �asov�ch okam�ic�ch. 902 */ 903 // implemented in fuzzyrul.cc 904 virtual void Evaluate(); 905 }; // FuzzySampledBlock 906 907 ///////////////////////////////////////////////////////////////////////////// 908 // rules 909 // 910 class FuzzyRule; 911 class FuzzyRuleFactory; 912 913 /** 914 * Abstract class for representation and evaluation of inference rules. 915 * It defines interface for generaly inputs, outputs and inference rules insertion. 916 * It does not implement particular format form storing inference rules.<br> 917 * 918 * Abstraktn� t��da pro reprezentaci a vyhodnocen� inferen�n�ch pravidel. 919 * Definuje rozhran� pro obecn� vkl�d�n� vstup�, v�stup� a inferen�n�ch pravidel. 920 * Neimplementuje konkr�tn� form�t ulo�en� pravidel. 921 * 922 * @author David Martinek <a href="mailto://DavidMartinek@seznam.cz">DavidMartinek@seznam.cz</a> 923 * @version 1.0 924 * @ingroup fuzzy 925 */ 926 class FuzzyInferenceRules 927 { 928 friend class FuzzyRuleFactory; 929 public: 930 /** 931 * Operations for use inside inference rules.<br> 932 * Operace, kter� je mo�no pou��t uvnit� inferen�n�ch pravidel. 933 */ 934 enum Operations { opAND, opOR, opNOT, opNAND, opNOR }; 935 936 /** 937 * Destructor - does NOT free memory allocated by FuzzyInput and FuzzyOutput!<br> 938 * 939 * Destruktor - NEuvol�uje pam� zabranou prom�nn�mi FuzzyInput a FuzzyOutput! 940 * Uvoln�n� t�to pam�ti se mus� prov�st JINDE! 941 */ ~FuzzyInferenceRules()942 virtual ~FuzzyInferenceRules() 943 { 944 TRACE(printf("~FuzzyInferenceRules")); 945 in.erase(in.begin(), in.end()); 946 out.erase(out.begin(), out.end()); 947 } 948 949 /** 950 * It adds next input variable. Before calling this method is recommended to call 951 * isComplete.<br> 952 * 953 * Vlo�� dal�� vstupn� prom�nnou. P�ed vol�n�m je vhodn� pou��t funkci isComplete. 954 * @param in Ipnut fuzzy variable. It has not to be registered inside FuzzyBlock yet. 955 * Vstupn� fuzzy prom�nn�. Zde je�t� nemus� b�t registrovan� uvnit� FuzzyBlock. 956 * 957 * @see isComplete() 958 */ addFuzzyInput(FuzzyInput * in)959 virtual void addFuzzyInput(FuzzyInput *in) 960 { this->in.push_back(in); } 961 962 /** 963 * It adds next output variable. Before calling this method is recommended to call 964 * isComplete. <br> 965 * 966 * Vlo�� v�stupn� prom�nnou. P�ed vol�n�m je vhodn� pou��t funkci isComplete. 967 * @param out Output fuzzy variable. It has not to be registered inside FuzzyBlock yet. 968 * V�stupn� fuzzy prom�nn�. Zde je�t� nemus� b�t registrovan� uvnit� FuzzyBlock. 969 * @see isComplete() 970 */ addFuzzyOutput(FuzzyOutput * out)971 virtual void addFuzzyOutput(FuzzyOutput *out) 972 { this->out.push_back(out); } 973 974 /** 975 * It safely creates FuzzyRuleFactory.<br> 976 * Bezpe�n�m zp�sobem vytvo�� FuzzyRuleFactory. 977 */ 978 //implemented in rules.cc 979 virtual FuzzyRuleFactory * createRuleFactory(); 980 981 /** 982 * It returns true when all variables are assigned.<br> 983 * Testuje, jestli u� jsou p�i�azeny v�echny prom�nn�. 984 * @see addFuzzyInput(FuzzyInput *in) 985 * @see addFuzzyOutput(FuzzyOutput *out) 986 */ 987 virtual bool isComplete() = 0; 988 989 /** 990 * It adds next rule into list. When it is too much rules here, error is indicated.<br> 991 * 992 * P�id� dal�� pravidlo do seznamu. Pokud u� je definov�no p��li� pravidel, nastane chyba. 993 * @param rule Inference rule who is represented by tree structure. 994 * Inferen�n� pravidlo reprezentovan� stromovou strukturou. 995 * @param release ��k�, �e se po vlo�en� uvoln� pam�. Implicitn� nastaveno true. 996 * Memory will be released after rule storing. Default it is true. 997 */ 998 virtual void add(FuzzyRule *rule, bool release=true) = 0; 999 1000 /** 1001 * It evaluates all rules. This method is defaultly called from a method Behavior in class 1002 * FuzzyRSBlock.<br> 1003 * Vyhodnot� pravidla. Tato funkce je standardn� vol�na z funkce Behavior t��dy 1004 * FuzzyRSBlock. 1005 */ 1006 virtual void evaluate() = 0; 1007 protected: 1008 /** Vector of input variables. <br> Vektor vstupn�ch prom�nn�ch. */ 1009 std::vector<FuzzyInput *>in; 1010 1011 /** Vector of output variables. <br> Vektor v�stupn�ch prom�nn�ch. */ 1012 std::vector<FuzzyOutput *>out; 1013 private: 1014 }; // FuzzyInferenceRules 1015 1016 /** 1017 * This class is representing inference rules for classic fuzzy regulator with two inputs and 1018 * one output. It is possible to adds rules by new defined methods add(). These methods are 1019 * suitable for use during XML analysis.<br> 1020 * 1021 * T��da reprezentuj�c� inferen�n� pravidla pro klasick� fuzzy regul�tor se dv�ma vstupy a 1022 * jedn�m v�stupem. Pravidla je mo�n� vkl�dat pomoc� nov�ch funkc� add, kter� jsou vhodn� 1023 * pro pou�it� b�hem anal�zy dat z XML souboru. Krom� toho je mo�no pou��t zd�d�n� rozhran� 1024 * FuzzyInferenceRules 1025 * 1026 * @author David Martinek <a href="mailto://DavidMartinek@seznam.cz">DavidMartinek@seznam.cz</a> 1027 * @version 1.0 1028 * @ingroup fuzzy 1029 */ 1030 class FuzzyIIORules 1031 : public FuzzyInferenceRules 1032 { 1033 public: 1034 ///////////////////////////////////////////////////////////////// 1035 // rozhran� FuzzyInferenceRules -- interface FuzzyInferenceRules 1036 ///////////////////////////////////////////////////////////////// 1037 /** 1038 * Parameterless constructor. Fuzzy variables must be added explicitly.<br> 1039 * Konstruktor bez parametru. Fuzzy prom�nn� je nutno p�i�adit pomoc� dal��ch funkc� explicitn�. 1040 */ 1041 FuzzyIIORules(); 1042 1043 /** 1044 * It initializes all input and output variables.<br> 1045 * Inicializuje v�echny vstupn� a v�stupn� prom�nn�. 1046 */ 1047 //implemented in rules.cc 1048 FuzzyIIORules(FuzzyInput *in1, FuzzyInput *in2, FuzzyOutput *out); 1049 1050 /** 1051 * Destructor - does NOT free memory allocated by FuzzyInput and FuzzyOutput!<br> 1052 * Destruktor - NEuvol�uje pam� zabranou prom�nn�mi FuzzyInput a FuzzyOutput! 1053 * Uvoln�n� t�to pam�ti se mus� prov�st JINDE! 1054 */ 1055 //implemented in rules.cc 1056 virtual ~FuzzyIIORules(); 1057 1058 /** It initializes all member variables. <br> Inicializuje vnit�n� prom�nn� */ 1059 //implemented in rules.cc 1060 void init(); 1061 1062 /** It adds next input variable.<br> Vlo�� dal�� vstupn� prom�nnou. */ 1063 //implemented in rules.cc 1064 virtual void addFuzzyInput(FuzzyInput *in); 1065 1066 /** It adds output variable.<br> Vlo�� v�stupn� prom�nnou. */ 1067 //implemented in rules.cc 1068 virtual void addFuzzyOutput(FuzzyOutput *out); 1069 1070 /** 1071 * It tests if all variables are assigned.<br> 1072 * Testuje, jestli u� jsou p�i�azeny v�echny prom�nn�. 1073 * @see addFuzzyInput(FuzzyInput *in) 1074 * @see addFuzzyOutput(FuzzyOutput *out) 1075 */ 1076 //implemented in rules.cc 1077 virtual bool isComplete(); 1078 1079 /** 1080 * It evaluates the rules.<br> 1081 * Vyhodnot� pravidla. 1082 */ 1083 //implemented in rules.cc 1084 virtual void evaluate(); 1085 1086 /** 1087 * It adds next rule into list. If there is too much rules, an error is indicated.<br> 1088 * P�id� dal�� pravidlo do seznamu. Pokud u� je definov�no p��li� pravidel, nastane chyba. 1089 * @param rule Inference rule with tree structure.<br>Inferen�n� pravidlo reprezentovan� stromovou strukturou. 1090 * @param release Memory will be released after rule storing. Default it is true. 1091 * ��k�, �e se po vlo�en� uvoln� pam�. Implicitn� nastaveno true. 1092 */ 1093 //implemented in rules.cc 1094 virtual void add(FuzzyRule *rule, bool release=true); 1095 1096 ////////////////////////////////////// 1097 // nov� funkce -- new functions 1098 ////////////////////////////////////// 1099 /** 1100 * Adds a rule into the list.<br> 1101 * P��d� inferen�n� pravidlo do seznamu. 1102 * @param operation operation which is used in rule<br>operace, kter� se pou�ije v pravidle 1103 * @param in1WordValue word value of first fuzzy input variable<br>slovn� hodnota prvn� vstupn� fuzzy prom�nn� 1104 * @param in2WordValue word value of second fuzzy input variable<br>slovn� hodnota druh� vstupn� fuzzy prom�nn� 1105 * @param outWordValue word value of output fuzzy variable<br>slovn� hodnota v�stupn� fuzzy prom�nn� 1106 */ 1107 //implemented in rules.cc 1108 void add (const Operations operation, 1109 const char *in1WordValue, 1110 const char *in2WordValue, 1111 const char *outWordValue); 1112 1113 /** 1114 * Adds a rule into the list.<br> 1115 * P��d� inferen�n� pravidlo do seznamu. 1116 * @param operation operation which is used in rule<br>operace, kter� se pou�ije v pravidle 1117 * @param in1WVIndex index of first fuzzy input variable<br>index slovn� hodnoty prvn� vstupn� prom�nn� 1118 * @param in2WVIndex index of second fuzzy input variable<br>index slovn� hodnoty druh� vstupn� prom�nn� 1119 * @param outWVIndex index of output fuzzy variable<br>index slovn� hodnoty v�stupn� prom�nn� 1120 */ 1121 //implemented in rules.cc 1122 void add (const Operations operation, 1123 int in1WVIndex, 1124 int in2WVIndex, 1125 int outWVIndex); 1126 /** 1127 * Adds a rule into the list.<br> 1128 * P��d� inferen�n� pravidlo do seznamu. 1129 * @param operation operation which is used in rule<br>operace, kter� se pou�ije v pravidle 1130 * @param in1WVIndex index of first fuzzy input variable<br>index slovn� hodnoty prvn� vstupn� prom�nn� 1131 * @param in2WVIndex index of second fuzzy input variable<br>index slovn� hodnoty druh� vstupn� prom�nn� 1132 * @param outWordValue word value of output fuzzy variable<br>slovn� hodnota v�stupn� fuzzy prom�nn� 1133 */ 1134 //implemented in rules.cc 1135 void add (const Operations operation, 1136 int in1WVIndex, 1137 int in2WVIndex, 1138 const char *outWordValue); 1139 1140 protected: 1141 /** Array of indexes into FuzzyOutput variable.<br> Pole index� do prom�nn� FuzzyOutput. */ 1142 int *outWV; 1143 /** 1144 * Array of corresponding operations between input variables.<br> Pole odpov�daj�c�ch 1145 * operac� mezi vstupn�mi prom�nn�mi. 1146 */ 1147 Operations *operation; 1148 /** Number of variables and rules in object.<br> Po�et prom�nn�ch a pravidel v objektu */ 1149 int inputs, outputs, rules; 1150 /** Maximum number of variables.<br> Maxim�ln� po�et prom�nn�ch. */ 1151 static const int MAX_INPUTS = 2; 1152 static const int MAX_OUTPUTS = 1; 1153 1154 /** It tests if all arrays are allocated.<br>Testuje, jestli u� jsou alokov�na pole. */ 1155 //implemented in rules.cc 1156 bool isAllCreated(); 1157 private: 1158 /** 1159 * It alocates a memory space for operation and outWV arrays. A alocated array size is 1160 * a product of numbers of word values of all input variables.<br> 1161 * Alokuje prostor pro pole operation a outWV. Velikost alokovan�ho pole je sou�inem 1162 * po�t� slovn�ch hodnot v�ech jednotliv�ch vstupn�ch prom�nn�ch. 1163 */ 1164 //implemented in rules.cc 1165 void createVectors(); 1166 }; // FuzzyIIORules 1167 1168 /** 1169 * General form of inference rules.<br>Obecn� tvar inferen�n�ch pravidel. 1170 * 1171 * General representation of inference rules, which allows to create more complex fuzzy regulators. 1172 * Usualy is this class used indirectly over overloaded operators. For more details see the example 1173 * for class FuzzyExpr and documentation for class Rules. 1174 * 1175 * Obecn� reprezentace inferen�n�ch pravidel, kter� dovoluje vytv��et slo�it�j�� fuzzy regul�tory. 1176 * Obvykle je tato t��da pou��van� nep��mo p�es p�et�en� oper�tory. Dal�� detaily viz p��klad 1177 * u t��dy FuzzyExpr a dokumentace pro t��du Rules. 1178 */ 1179 class FuzzyGeneralRules 1180 : public FuzzyInferenceRules 1181 { 1182 public: 1183 /** 1184 * It destroys vector of rules 1185 */ ~FuzzyGeneralRules()1186 ~FuzzyGeneralRules() 1187 { 1188 TRACE(printf("~FuzzyGeneralRules\n")); 1189 rules.erase(rules.begin(), rules.end()); 1190 } 1191 /** 1192 * It returns true when all variables are assigned.<br> 1193 * Testuje, jestli u� jsou p�i�azeny v�echny prom�nn�. 1194 * @see addFuzzyInput(FuzzyInput *in) 1195 * @see addFuzzyOutput(FuzzyOutput *out) 1196 */ 1197 //implemented in rules.cc 1198 virtual bool isComplete(); 1199 1200 /** 1201 * It adds next rule into list. When it is too much rules here, error is indicated.<br> 1202 * 1203 * P�id� dal�� pravidlo do seznamu. Pokud u� je definov�no p��li� pravidel, nastane chyba. 1204 * @param rule Inference rule who is represented by tree structure.<br> 1205 * Inferen�n� pravidlo reprezentovan� stromovou strukturou. 1206 * @param release It has no meaning here.<br>Zde nem� v�znam. 1207 */ 1208 //implemented in rules.cc 1209 virtual void add(FuzzyRule *rule, bool release=true); 1210 1211 /** 1212 * It evaluates all rules. This method is defaultly called from a method Behavior in class 1213 * FuzzyRSBlock.<br> 1214 * Vyhodnot� pravidla. Tato funkce je standardn� vol�na z funkce Behavior t��dy 1215 * FuzzyRSBlock. 1216 */ 1217 //implemented in rules.cc 1218 virtual void evaluate(); 1219 protected: 1220 /** Vector of rules. */ 1221 std::vector<FuzzyRule *> rules; 1222 private: 1223 }; // FuzzyGeneralRules 1224 1225 /** 1226 * FuzzyRSBlock is base class for inference blocks with sampled input and explicitly defined 1227 * inference rules.<br> 1228 * FuzzyRSBlock je b�zov� t��da pro inferen�n� bloky se vzorkovan�xm vstupem a explicitn� 1229 * definovan�mi inferen�n�mi pravidly. 1230 * @ingroup fuzzy 1231 */ 1232 class FuzzyRSBlock 1233 : public FuzzySampledBlock 1234 { 1235 public: 1236 /** 1237 * Constructor - sets object with inference rules.<br> 1238 * Konstruktor - nastav� objekt s inferen�n�mi pravidly. 1239 */ FuzzyRSBlock(FuzzyInferenceRules & r)1240 FuzzyRSBlock(FuzzyInferenceRules &r) :rules(r) { } 1241 1242 /** Destructor - destruktor. */ ~FuzzyRSBlock()1243 virtual ~FuzzyRSBlock() 1244 { TRACE(printf("~FuzzyRuledSampledBlock()\n")); } 1245 1246 /** 1247 * It specifies behavior of this block. It evaluates all inference rules. <br> 1248 * Specifikuje chov�n� tohoto bloku. Vyhodnot� v�echna inferen�n� pravidla. 1249 */ Behavior()1250 virtual void Behavior() 1251 { rules.evaluate(); } 1252 1253 protected: 1254 FuzzyInferenceRules &rules; 1255 }; // FuzzyRSBlock 1256 1257 /////////////////////////////////////////////////////////////////////////////////////////////// 1258 // FuzzyRule 1259 // Reprezentace pravidla pomoc� stromu objekt�. Tento zp�sob realizace pravidla nen� p��li� 1260 // efektivn�. Na druhou stranu je dostate�n� obecn� na to, aby se s t�m dalo pracovat. Tento 1261 // p��stup je zam��len sp�e tak, �e vytv��en� pravidel pomoc� stromu je vn�j�� rozhran�, kter� 1262 // je v r�mci mo�nost� u�ivatelsky p��jemn�. Pravidlo reprezentovan� t�mto stromem se v ka�d�m 1263 // z potomk� t��dy FuzzyInferenceRules p�ekonvertuje na n�jak� efektivn�j�� form�t. 1264 // 1265 // Pokud by se ov�em vyskytla pot�eba opravdu obecn�ho z�pisu pravidel, je mo�n� tento strom 1266 // pou��t p��mo. Ve�ker� vyhodnocov�n� stromu se ale mus� d�lat zven��, proto�e t��dy tak, jak 1267 // jsou nyn� navr�eny mohou slou�it POUZE pro reprezentaci stromu. S p�ihl�dnut�m k tomu, aby 1268 // byla manipulace s objekty co nejjednodu���, maj� v�echny t��dy v�echny sv� datov� prvky 1269 // ve�ejn�. 1270 /////////////////////////////////////////////////////////////////////////////////////////////// 1271 1272 /** 1273 * Virtual knot in tree. From descendants is created a tree, who represents inference rule.<br> 1274 * Virtu�ln� uzel ve stromu. Z potomk� se vytv��� strom, kter� reprezentuje inferen�n� pravidlo. 1275 * @ingroup fuzzy 1276 */ 1277 class FONode 1278 { 1279 public: 1280 /** 1281 * It does nothing. It is here only to make this class abstract one.<br> 1282 * Pr�zdn� �ist� virtu�ln� funkce, kter� d�l� z t�to t��dy abstraktn� t��du. 1283 */ 1284 /** 1285 * Destruktor 1286 */ ~FONode()1287 virtual ~FONode() { TRACE(printf("~FONode\n")); }; 1288 1289 /** 1290 * It returns value of node - for evaluation of rule.<br>Vrac� hodnotu uzlu - pro 1291 * vyhodnocov�n� pravidel 1292 */ 1293 virtual double getValue() = 0; 1294 }; // FONode 1295 1296 /** 1297 * Knot in a tree, who represents inference rule. This knot represents an operation.<br> 1298 * Uzel ve stromu, kter� reprezentuje inferen�n� pravidlo. Tento uzel reprezentuje operaci. 1299 * @ingroup fuzzy 1300 */ 1301 class FOperation : public FONode 1302 { 1303 public: 1304 /** Operator. */ 1305 FuzzyInferenceRules::Operations op; 1306 1307 /** Left operand. <br> Lev� operand. */ 1308 FONode *L; 1309 1310 /** Right operand. <br> Prav� operand. */ 1311 FONode *R; 1312 1313 /** 1314 * Constructor for a binary operator. <br> Konstruktor pro bin�rn� oper�tor. 1315 */ FOperation(FONode * left,FONode * right,FuzzyInferenceRules::Operations operation)1316 FOperation(FONode *left, FONode *right, FuzzyInferenceRules::Operations operation) 1317 : //FONode(FONode::ntOperation), 1318 op(operation), L(left), R(right){} 1319 1320 /** 1321 * Constructor for an unary operator. <br> Konstruktor pro un�rn� oper�tor. 1322 */ 1323 // implemented in ruletree.cc 1324 FOperation(FONode *operand, FuzzyInferenceRules::Operations operation); 1325 1326 /** 1327 * Destructor releases all subtrees. <br> Destruktor uvoln� oba podstromy. 1328 */ ~FOperation()1329 virtual ~FOperation() 1330 { 1331 if (R != NULL) delete R; 1332 if (L != NULL) delete L; 1333 TRACE(printf("~FOperation\n")); 1334 } 1335 1336 /** 1337 * It returns value after doing operation op.<br>Vrac� hodnotu po proveden� operace op. 1338 */ 1339 // implemented in ruletree.cc 1340 virtual double getValue(); 1341 1342 1343 protected: 1344 private: 1345 }; // FOperation 1346 1347 /** 1348 * Leaf of tree. It represents comparing (in == "low") or (in != "too"). If var is 1349 * FuzzyOutput, this object can represents assigning (out = "reduce").<br> 1350 * List stromu. Reprezentuje porovn�n� typu (in == "malo") pripadne (in != "hodne"). Pokud 1351 * se do prom�nn� var p�i�ad� FuzzyOutput, m��e tento objekt reprezentovat p�i�azen� typu 1352 * (out = "uber".) 1353 * @ingroup fuzzy 1354 */ 1355 class FPair : public FONode 1356 { 1357 public: 1358 /** Equal or not equal. <br> Rovno nebo nerovno. */ 1359 bool eq; 1360 /** Fuzzy variable. <br> Fuzzy prom�nn�. */ 1361 FuzzyVariable *var; 1362 /** Word value. <br> Slovn� hodnota. */ 1363 const char * wordValue; 1364 /** Index of word value in FuzzyVariable.<br> Index slovn� hodnoty ve FuzzyVariable. */ 1365 int indexWV; 1366 1367 /** 1368 * Constructor. 1369 */ 1370 FPair(FuzzyVariable *variable, const char * wordvalue, bool equal=true) 1371 : //FONode(FONode::ntPair), eq(equal)1372 eq(equal), var(variable), wordValue(wordvalue) 1373 { 1374 indexWV = var->search(wordvalue); 1375 } 1376 1377 /** 1378 * Destructor does not release memory alocated by var and wordValue.<br> 1379 * Destruktor neuvol�uje pam� alokovanou prom�nn�mi var a wordValue. 1380 */ ~FPair()1381 virtual ~FPair() 1382 { 1383 var = NULL; 1384 wordValue = NULL; 1385 TRACE(printf("~FPair\n")); 1386 } 1387 1388 /** 1389 * If var is the FuzzyInput then this method returns fuzzified value of input. 1390 * In other words - value of membership function with name wordValue. Do not use if var is 1391 * a class FuzzyOutput. 1392 * 1393 * Jestli�e parametr var je FuzzyInput, tato metoda vrac� fuzzifikovanou hodnotu vstupu. 1394 * Jin�mi slovy - hodnotu funkce p��slu�nosti se jm�nem wordValue. Nepou��vejte jestli�e je 1395 * var t��dy FuzzyOutput. 1396 */ 1397 // implemented in ruletree.cc 1398 virtual double getValue(); 1399 protected: 1400 private: 1401 }; // FPair 1402 1403 /** 1404 * Class for representing one inference rule in tree.<br> 1405 * T��da reprezentuj�c� jedno inferen�n� pravidlo ve form� stromov� struktury. 1406 * @ingroup fuzzy 1407 */ 1408 class FuzzyRule 1409 { 1410 public: 1411 /** Constructor. */ 1412 //implemented in ruletree.cc 1413 FuzzyRule(); 1414 1415 /** 1416 * Destructor releases memory alocated by tree. <br> Destruktor uvoln� pam� alokovanou stromem. 1417 */ 1418 //implemented in ruletree.cc 1419 virtual ~FuzzyRule(); 1420 1421 /** It adds the lvalue of rule. <br> P�id� levou stranu pravidla. */ 1422 //implemented in ruletree.cc 1423 void addLeft(FOperation *left); 1424 1425 /** It adds one command into list. <br> P�id� dal�� p��kaz do seznamu. */ 1426 //implemented in ruletree.cc 1427 void addRight(FPair *right); 1428 1429 /** 1430 * It evaluates one inference rule according to fuzzy model Mamdani.<br> 1431 * Vyhodnot� jedno inferen�n� pravidlo podle fuzzy modelu Mamdani. 1432 */ 1433 //implemented in ruletree.cc 1434 virtual void evaluate(); 1435 1436 /** Lvalue. <br> Lev� strana. */ 1437 FOperation * left; 1438 1439 /** Rvalue. <br> Prav� strana. */ 1440 std::vector<FPair *> right; 1441 protected: 1442 private: 1443 }; // FuzzyRule 1444 1445 /** 1446 * Class for user friendly creating of inference rules.<br> 1447 * T��da pro u�ivatelsky p��jemn�j�� vytv��en� inferen�n�ch pravidel. 1448 * @ingroup fuzzy 1449 */ 1450 class FuzzyRuleFactory 1451 { 1452 public: 1453 /** 1454 * It safely creates fuzzy inference rule.<br> 1455 * Vrac� bezpe�n�m zp�sobem vytvo�en� pravidlo. 1456 */ 1457 // implemented in ruletree.cc 1458 FuzzyRule * createRule(); 1459 1460 /** 1461 * It adds condition of rule.<br> 1462 * P�id� podm�nkovou ��st do pravidla. 1463 */ 1464 //implemented in ruletree.cc 1465 void addCondition(FOperation * operation); 1466 1467 /** 1468 * It adds next assign command into rule.<br> 1469 * P�id� dal�� p�i�azovac� p��kaz do p��kazov� ��sti pravidla (konsekvent). 1470 */ 1471 //implemented in ruletree.cc 1472 void addConsequent(FPair * consequent); 1473 1474 /** 1475 * It creates a leaf knot of rule. <br> 1476 * Vytvo�� listov� uzel pravidla. 1477 * @param equal true for == and not for != 1478 */ 1479 //implemented in ruletree.cc 1480 FPair * createNode(FuzzyVariable *var, const char * wordvalue, bool equal=true); 1481 1482 /** 1483 * It creates a nonleaf knot of rule representing binary operator.<br> 1484 * Vytvo�� nelistov� uzel pravidla reprezentuj�c� bin�rn� oper�tor. 1485 */ 1486 //implemented in ruletree.cc 1487 FOperation * createNode(FONode *left, FONode *right, FuzzyInferenceRules::Operations operation); 1488 1489 /** 1490 * It creates a nonleaf knot of rule representing unary operator.<br> 1491 * Vytvo�� nelistov� uzel pravidla reprezentuj�c� un�rn� oper�tor. 1492 */ 1493 //implemented in ruletree.cc 1494 FOperation * createNode(FONode *operand, FuzzyInferenceRules::Operations operation); 1495 1496 /** Destructor */ ~FuzzyRuleFactory()1497 virtual ~FuzzyRuleFactory() 1498 { 1499 if (rule != NULL) delete rule; 1500 TRACE(printf("~FuzzyRuleFactory\n")); 1501 } 1502 protected: 1503 /** 1504 * Constructor is protected against user. Object of this class can create only 1505 * object of class FuzzyInferenceRules.<br> 1506 * Konstruktor je chr�n�n p�ed u�ivatelem. Objekt t�to t��dy m��e vytvo�it 1507 * pouze objekt t��dy FuzzyInferenceRules. 1508 */ 1509 friend class FuzzyInferenceRules; 1510 // implemented in ruletree.cc 1511 FuzzyRuleFactory(FuzzyInferenceRules * owner); 1512 FuzzyInferenceRules * owner; /**< Vlastn�k tohoto objektu */ 1513 FuzzyRule * rule; /**< Pr�v� vytv��en� pravidlo */ 1514 private: 1515 }; // FuzzyRuleFactory 1516 1517 1518 1519 /** 1520 * A static class for creating general inference rules. See the class FuzzyExpr and FuzzyGeneralRules. 1521 * 1522 * Statick� t��da pro vytv��en� obecn�ch inferen�n�ch pravidel. Pod�vejte se na t��du FuzzyExpr a 1523 * FuzzyGeneralRules. 1524 */ 1525 class Rules 1526 { 1527 public: 1528 1529 /** 1530 * It adds next input into the list. This is needed because of error checking.<br> 1531 * P�id� dal�� vstup do seznamu. Tato metoda je pot�eba kv�li o�et�en� chyb. 1532 */ 1533 static void addFuzzyInput(FuzzyInput * input); 1534 1535 /** 1536 * It adds next output into the list. This is needed because of error checking.<br> 1537 * P�id� dal�� v�stup do seznamu. Tato metoda je pot�eba kv�li o�et�en� chyb. 1538 */ 1539 static void addFuzzyOutput(FuzzyOutput * output); 1540 1541 /** 1542 * It returns complete definition of inference rules. See at class FuzzyExpr to see how to 1543 * create inference rules.<br> 1544 * Vrac� kompletn� definici inferen�n�ch pravidel. Pod�vejte se na t��du FuzzyExpr jak se 1545 * vytv��� inferen�n� pravidla. 1546 */ 1547 static FuzzyGeneralRules * getRules(); 1548 1549 /** 1550 * It produces error if there is not enough inputs and outputs or it returns FuzzyRuleFactory.<br> 1551 * Zp�sob� chybu, jestli�e nen� definov�no dostate�n� mno�stv� vstup� a v�stup� nebo vr�t� 1552 * FuzzyRuleFactory. 1553 */ 1554 static FuzzyRuleFactory * Factory(); 1555 1556 /** 1557 * It adds new rule into rules.<br>P�id� nov� pravidlo do rules. 1558 */ 1559 static void addNewRule(); 1560 1561 static bool addRule; /**< Create new rule in operator == */ 1562 private: 1563 /** This class can not be instanciated. */ Rules()1564 Rules() {} 1565 /** It initializes data members. */ 1566 static void init(); 1567 static bool addedInput; /**< Is here any input? */ 1568 static bool addedOutput; /**< Is here any output? */ 1569 static FuzzyGeneralRules * rules; /**< Rules to return. */ 1570 static FuzzyRuleFactory * factory; /**< Rule factory. */ 1571 };//class Rules 1572 1573 ///////////////////////////////////////////////////////////////////////////// 1574 // FuzzyExpr --- fuzzy expression value class 1575 /** 1576 * "User friendly" writing of inference rules.<br>"U�ivatelsky p��telsk� z�pis" inferen�n�ch pravidel. 1577 * 1578 * Implementation of "user friendly" writing of inference rules. This way can not be use 1579 * inside threads because of using global variables! 1580 * 1581 * Implementace "u�ivatelsky p��telsk�ho" z�pisu inferen�n�ch pravidel. Tento zp�sob nem��e 1582 * b�t pou�it uvnit� vl�ken kv�li pou��v�n� glob�ln�ch prom�nn�ch. 1583 * 1584 * Example/P��klad: 1585 * @code 1586 * FuzzyInferenceRules * createRules(FuzzyInput *speed, 1587 * FuzzyInput *distance, 1588 * FuzzyInput *wet, 1589 * FuzzyOutput *acceleration, 1590 * FuzzyOutput *brake) 1591 * { 1592 * Rules::addFuzzyInput(speed); 1593 * Rules::addFuzzyInput(distance); 1594 * Rules::addFuzzyInput(wet); 1595 * Rules::addFuzzyOutput(acceleration); 1596 * Rules::addFuzzyOutput(brake); 1597 * 1598 * if (speed=="high" && (distance=="middle" || wet != "damp")) 1599 * { 1600 * acceleration = "zero"; 1601 * brake = "middle"; 1602 * } 1603 * ... 1604 * 1605 * return Rules::getRules(); 1606 * } 1607 * @endcode 1608 * @ingroup fuzzy 1609 */ 1610 class FuzzyExpr 1611 { 1612 FONode * value; 1613 public: 1614 /** 1615 * Objects of this class are usualy created inside if command.<br> 1616 * Objekty t�to t��dy jsou obvykle vytv��eny uvnit� p��kazu if. 1617 */ 1618 // implemented in fuzzyrul.cc 1619 explicit FuzzyExpr(FONode * value); 1620 /** It returns value of expression.<br>Vrac� hodnotu v�razu. */ Value()1621 FONode * Value() 1622 { 1623 FONode * node = value; 1624 value = NULL; 1625 return node; 1626 } 1627 /** 1628 * It creates object tree.<br>Vytvo�� strom objekt�. 1629 */ 1630 // implemented in fuzzyrul.cc 1631 operator bool(); // if(bool(expr)) actions; --- store alpha 1632 1633 };// FuzzyExpr 1634 1635 ///////////////////////////////////////////////////////////////////////////// 1636 // Fuzzy operators --- used in FuzzyBlock::Behavior() 1637 // 1638 // implemented in fuzzyrul.cc 1639 /** 1640 * @ingroup fuzzy 1641 * if ((FuzzyExpr) && (FuzzyExpr)) 1642 */ 1643 FuzzyExpr operator && (FuzzyExpr o1, FuzzyExpr o2); // AND 1644 /** 1645 * @ingroup fuzzy 1646 * if ((FuzzyExpr) || (FuzzyExpr)) 1647 */ 1648 FuzzyExpr operator || (FuzzyExpr o1, FuzzyExpr o2); // OR 1649 /** 1650 * @ingroup fuzzy 1651 * if (!(FuzzyExpr)) 1652 */ 1653 FuzzyExpr operator ! (FuzzyExpr o1); // NOT 1654 /** 1655 * @ingroup fuzzy 1656 * if ((input == "wordvalue")...) 1657 */ 1658 FuzzyExpr operator == (FuzzyInput &s, const char *value); // is 1659 1660 1661 } // namespace 1662 1663 #endif 1664