Store.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using FuzzyLogicPCL;
  2. using FuzzyLogicPCL.FuzzySets;
  3. using System;
  4. namespace FuzzyLogicApp
  5. {
  6. class Store
  7. {
  8. static void Main(string[] args)
  9. {
  10. // Création du système
  11. WriteLine("Gestion du store", true);
  12. FuzzySystem system = new FuzzySystem("Gestion du store");
  13. WriteLine("1) Ajout des variables", true);
  14. // Ajout de la variable linguistique "Température"
  15. WriteLine("Ajout de la variable Température");
  16. LinguisticVariable temp = new LinguisticVariable("Temperature", 0, 35);
  17. temp.AddValue(new LinguisticValue("Froid", new LeftFuzzySet(0, 35, 10, 12)));
  18. temp.AddValue(new LinguisticValue("Frais", new TrapezoidalFuzzySet(0, 35, 10, 12, 15, 17)));
  19. temp.AddValue(new LinguisticValue("Bon", new TrapezoidalFuzzySet(0, 35, 15, 17, 20, 25)));
  20. temp.AddValue(new LinguisticValue("Chaud", new RightFuzzySet(0, 35, 20, 25)));
  21. system.addInputVariable(temp);
  22. // Ajout de la variable linguistique "Eclairage"
  23. WriteLine("Ajout de la variable Eclairage");
  24. LinguisticVariable eclair = new LinguisticVariable("Eclairage", 0, 125000);
  25. eclair.AddValue(new LinguisticValue("Sombre", new LeftFuzzySet(0, 125000, 20000, 30000)));
  26. eclair.AddValue(new LinguisticValue("Moyen", new TrapezoidalFuzzySet(0, 125000, 20000, 30000, 65000, 85000)));
  27. eclair.AddValue(new LinguisticValue("Fort", new RightFuzzySet(0, 125000, 65000, 85000)));
  28. system.addInputVariable(eclair);
  29. // Ajout de la variable linguistique "Store"
  30. WriteLine("Ajout de la variable Hauteur de Store");
  31. LinguisticVariable store = new LinguisticVariable("Store", 0, 115);
  32. store.AddValue(new LinguisticValue("Ferme", new LeftFuzzySet(0, 115, 25, 40)));
  33. store.AddValue(new LinguisticValue("MiHauteur", new TrapezoidalFuzzySet(0, 115, 25, 40, 85, 100)));
  34. store.AddValue(new LinguisticValue("Remonte", new RightFuzzySet(0, 115, 85, 100)));
  35. system.addOutputVariable(store);
  36. WriteLine("2) Ajout des règles", true);
  37. // Création des règles
  38. system.addFuzzyRule("IF Eclairage IS Sombre THEN Store IS Remonte");
  39. system.addFuzzyRule("IF Eclairage IS Moyen AND Temperature IS Froid THEN Store IS Remonte");
  40. system.addFuzzyRule("IF Eclairage IS Moyen AND Temperature IS Frais THEN Store IS Remonte");
  41. system.addFuzzyRule("IF Eclairage IS Moyen AND Temperature IS Bon THEN Store IS MiHauteur");
  42. system.addFuzzyRule("IF Eclairage IS Moyen AND Temperature IS Chaud THEN Store IS MiHauteur");
  43. system.addFuzzyRule("IF Eclairage IS Fort AND Temperature IS Froid THEN Store IS Remonte");
  44. system.addFuzzyRule("IF Eclairage IS Fort AND Temperature IS Frais THEN Store IS MiHauteur");
  45. system.addFuzzyRule("IF Eclairage IS Fort AND Temperature IS Bon THEN Store IS Ferme");
  46. system.addFuzzyRule("IF Eclairage IS Fort AND Temperature IS Chaud THEN Store IS Ferme");
  47. WriteLine("9 règles ajoutées \n");
  48. WriteLine("3) Résolution de cas pratiques", true);
  49. // Cas pratique 1 : température de 21°, éclairage de 80000 lux
  50. WriteLine("Cas 1 :", true);
  51. WriteLine("T = 21 (80% bon, 20% chaud)");
  52. WriteLine("E = 80 000 (25% moyen, 75% fort)");
  53. system.SetInputVariable(temp, 21);
  54. system.SetInputVariable(eclair, 80000);
  55. WriteLine("Attendu : store plutôt fermé");
  56. WriteLine("Résultat : " + system.Solve() + "\n");
  57. while (true) ;
  58. }
  59. /// <summary>
  60. /// Aide pour l'écriture de messages en console (et ajouts d'*)
  61. /// </summary>
  62. /// <param name="msg">Message à afficher</param>
  63. /// <param name="stars">Besoin d'astérisques ?</param>
  64. private static void WriteLine(string msg, bool stars = false)
  65. {
  66. if (stars)
  67. {
  68. msg = "*** " + msg + " ";
  69. while (msg.Length < 45)
  70. {
  71. msg += "*";
  72. }
  73. }
  74. Console.WriteLine(msg);
  75. }
  76. }
  77. }