public void UsageExample_Success() { //Arrange LinguisticVariable water = new LinguisticVariable("Water"); var cold = water.MembershipFunctions.AddTrapezoid("Cold", 0, 0, 20, 40); var warm = water.MembershipFunctions.AddTriangle("Warm", 30, 50, 70); var hot = water.MembershipFunctions.AddTrapezoid("Hot", 50, 80, 100, 100); LinguisticVariable power = new LinguisticVariable("Power"); var low = power.MembershipFunctions.AddTriangle("Low", 0, 25, 50); var high = power.MembershipFunctions.AddTriangle("High", 25, 50, 75); IFuzzyEngine fuzzyEngine = new FuzzyEngineFactory().Default(); var rule1 = Rule.If(water.Is(cold).Or(water.Is(warm))).Then(power.Is(high)); var rule2 = Rule.If(water.Is(hot)).Then(power.Is(low)); fuzzyEngine.Rules.Add(rule1, rule2); //Act var result = fuzzyEngine.Defuzzify(new { water = 60 }); //Assert Assert.That(Math.Floor(result), Is.EqualTo(Math.Floor(40.0))); //Extra System.Diagnostics.Debug.WriteLine(result); }
private static void Zad1() { var insolationDictionary = new Dictionary <string, double>() { { "Warszawa", 0.6 }, { "Kraków", 1.0 }, { "Gdańsk", 0.9 }, { "Wrocław", 0.8 }, { "Katowice", 0.3 }, { "Poznań", 0.7 }, { "Gliwice", 0.3 }, }; var pollutionDictionary = new Dictionary <string, double> { { "Warszawa", 0.3 }, { "Kraków", 0.1 }, { "Gdańsk", 0.9 }, { "Wrocław", 0.7 }, { "Katowice", 0.1 }, { "Poznań", 0.6 }, { "Gliwice", 0.1 }, }; var insolation = new LinguisticVariable("insolation"); var lowInsolation = insolation.MembershipFunctions.AddTrapezoid("lowInsolation", 0, 0.1, 0.6, 0.8); var highInsolation = insolation.MembershipFunctions.AddTrapezoid("highInsolation", 0.6, 0.8, 0.9, 1); var pollution = new LinguisticVariable("pollution"); var lowPollution = pollution.MembershipFunctions.AddTrapezoid("lowPollution", 0, 0.1, 0.3, 0.5); var highPollution = pollution.MembershipFunctions.AddTrapezoid("highPollution", 0.3, 0.5, 0.9, 1); var humanFriendly = new LinguisticVariable("humanFriendly"); var isHumanFriendly = humanFriendly.MembershipFunctions.AddTrapezoid("isHumanFriendly", 0, 0.1, 0.4, 0.6); var notHumanFriendly = humanFriendly.MembershipFunctions.AddTrapezoid("notHumanFriendly", 0.4, 0.6, 0.9, 1); IFuzzyEngine fuzzyEngine = new FuzzyEngineFactory().Default(); var rule1 = Rule.If(insolation.Is(highInsolation).And(pollution.Is(lowPollution))).Then(humanFriendly.Is(isHumanFriendly)); var rule2 = Rule.If(insolation.Is(lowInsolation).And(pollution.Is(highPollution))).Then(humanFriendly.Is(notHumanFriendly)); fuzzyEngine.Rules.Add(rule1, rule2); foreach (var city in insolationDictionary.Keys) { Console.WriteLine($"{city}: {fuzzyEngine.Defuzzify(new { insolation = insolationDictionary[city], pollution = pollutionDictionary[city] })}"); } }
public double KillerFuzzy(double killAmount, double killQuest) { //Killer Fuzzy Set LinguisticVariable killer = new LinguisticVariable("Killer"); var novice = killer.MembershipFunctions.AddTriangle("Novice", 0, 3, 3); var advance = killer.MembershipFunctions.AddTriangle("Advance", 2, 5, 5); var proficient = killer.MembershipFunctions.AddTriangle("Proficient", 4, 8, 8); var expert = killer.MembershipFunctions.AddTrapezoid("Expert", 7, 8, 10, 10); //Support Fuzzy Set LinguisticVariable amount = new LinguisticVariable("Amount"); var low = amount.MembershipFunctions.AddTriangle("Low", 1, 50, 50); var medium = amount.MembershipFunctions.AddTriangle("Medium", 40, 80, 80); var high = amount.MembershipFunctions.AddTrapezoid("High", 70, 80, 1000, 1000); LinguisticVariable quest = new LinguisticVariable("Quest"); var little = quest.MembershipFunctions.AddTriangle("Little", 1, 3, 3); var average = quest.MembershipFunctions.AddTriangle("Average", 2, 5, 5); var lot = quest.MembershipFunctions.AddTrapezoid("Lot", 7, 8, 10, 10); //time /*LinguisticVariable time = new LinguisticVariable("Time"); * var slow = kill.MembershipFunctions.AddTrapezoid("Slow", 0, 0.006, 0.008, 0.008); * var normal = kill.MembershipFunctions.AddTriangle("Normal", 0.007 , 0.16, 0.16); * var fast = kill.MembershipFunctions.AddTriangle("Fast", 0.15, 1, 1);*/ IFuzzyEngine fuzzyEngine = new FuzzyEngineFactory().Create(new MoMDefuzzification()); var rule1 = Rule.If(amount.Is(low).And(quest.Is(little))).Then(killer.Is(novice)); var rule2 = Rule.If(amount.Is(low).And(quest.Is(average))).Then(killer.Is(advance)); var rule3 = Rule.If(amount.Is(low).And(quest.Is(lot))).Then(killer.Is(advance)); var rule4 = Rule.If(amount.Is(medium).And(quest.Is(little))).Then(killer.Is(novice)); var rule5 = Rule.If(amount.Is(medium).And(quest.Is(average))).Then(killer.Is(advance)); var rule6 = Rule.If(amount.Is(medium).And(quest.Is(lot))).Then(killer.Is(proficient)); var rule7 = Rule.If(amount.Is(high).And(quest.Is(little))).Then(killer.Is(advance)); var rule8 = Rule.If(amount.Is(high).And(quest.Is(average))).Then(killer.Is(proficient)); var rule9 = Rule.If(amount.Is(high).And(quest.Is(lot))).Then(killer.Is(expert)); fuzzyEngine.Rules.Add(rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9); var result = fuzzyEngine.Defuzzify(new { amount = killAmount, quest = killQuest }); return(result); }
public void Test1() { LinguisticVariable water = new LinguisticVariable("Water"); var cold = water.MembershipFunctions.AddTrapezoid("Cold", 0, 0, 20, 40); var warm = water.MembershipFunctions.AddTriangle("Warm", 30, 50, 70); var hot = water.MembershipFunctions.AddTrapezoid("Hot", 50, 80, 100, 100); LinguisticVariable power = new LinguisticVariable("Power"); var low = power.MembershipFunctions.AddTriangle("Low", 0, 25, 50); var high = power.MembershipFunctions.AddTriangle("High", 25, 50, 75); IFuzzyEngine fuzzyEngine = new FuzzyEngineFactory().Default(); fuzzyEngine.Rules.If(water.Is(cold).Or(water.Is(warm))).Then(power.Is(high)); fuzzyEngine.Rules.If(water.Is(hot)).Then(power.Is(low)); var result = fuzzyEngine.Defuzzify(new { water = 60 }); }
public double ExplorerFuzzy(double placesTravel, double exploreQuest) { //Explorer Characteristic Fuzzy Set LinguisticVariable travel = new LinguisticVariable("Travel"); var low = travel.MembershipFunctions.AddTriangle("Low", 1, 10, 10); var medium = travel.MembershipFunctions.AddTriangle("Medium", 8, 16, 16); var high = travel.MembershipFunctions.AddTrapezoid("High", 15, 30, 100, 100); LinguisticVariable explore = new LinguisticVariable("Explore"); var little = explore.MembershipFunctions.AddTriangle("Little", 1, 3, 3); var average = explore.MembershipFunctions.AddTriangle("Average", 2, 5, 5); var lot = explore.MembershipFunctions.AddTrapezoid("Lot", 7, 8, 10, 10); LinguisticVariable explorer = new LinguisticVariable("Achiever"); var novice = explorer.MembershipFunctions.AddTriangle("Novice", 0, 3, 3); var advance = explorer.MembershipFunctions.AddTriangle("Advance", 2, 5, 5); var proficient = explorer.MembershipFunctions.AddTriangle("Proficient", 4, 8, 8); var expert = explorer.MembershipFunctions.AddTrapezoid("Expert", 7, 8, 10, 10); IFuzzyEngine fuzzyEngine = new FuzzyEngineFactory().Create(new MoMDefuzzification()); var rule1 = Rule.If(travel.Is(low).And(explore.Is(little))).Then(explorer.Is(novice)); var rule2 = Rule.If(travel.Is(low).And(explore.Is(average))).Then(explorer.Is(advance)); var rule3 = Rule.If(travel.Is(low).And(explore.Is(lot))).Then(explorer.Is(advance)); var rule4 = Rule.If(travel.Is(medium).And(explore.Is(little))).Then(explorer.Is(novice)); var rule5 = Rule.If(travel.Is(medium).And(explore.Is(average))).Then(explorer.Is(advance)); var rule6 = Rule.If(travel.Is(medium).And(explore.Is(lot))).Then(explorer.Is(proficient)); var rule7 = Rule.If(travel.Is(high).And(explore.Is(little))).Then(explorer.Is(advance)); var rule8 = Rule.If(travel.Is(high).And(explore.Is(average))).Then(explorer.Is(proficient)); var rule9 = Rule.If(travel.Is(high).And(explore.Is(lot))).Then(explorer.Is(expert)); fuzzyEngine.Rules.Add(rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9); var result = fuzzyEngine.Defuzzify(new { travel = placesTravel, explore = exploreQuest }); return(result); }
public double AchieverFuzzy(double questFinished, double avgDifficulty) { //Achiever Characteristic Fuzzy Set LinguisticVariable amount = new LinguisticVariable("Amount"); var low = amount.MembershipFunctions.AddTriangle("Low", 1, 10, 10); var medium = amount.MembershipFunctions.AddTriangle("Medium", 8, 16, 16); var high = amount.MembershipFunctions.AddTrapezoid("High", 15, 30, 100, 100); LinguisticVariable difficulty = new LinguisticVariable("Difficulty"); var easy = amount.MembershipFunctions.AddTriangle("Low", 1, 2, 2); var normal = amount.MembershipFunctions.AddTriangle("Medium", 2, 3, 3); var hard = amount.MembershipFunctions.AddTrapezoid("High", 3, 4, 5, 5); LinguisticVariable achiever = new LinguisticVariable("Achiever"); var novice = achiever.MembershipFunctions.AddTriangle("Novice", 0, 3, 3); var advance = achiever.MembershipFunctions.AddTriangle("Advance", 2, 5, 5); var proficient = achiever.MembershipFunctions.AddTriangle("Proficient", 4, 8, 8); var expert = achiever.MembershipFunctions.AddTrapezoid("Expert", 7, 8, 10, 10); IFuzzyEngine fuzzyEngine = new FuzzyEngineFactory().Create(new MoMDefuzzification()); var rule1 = Rule.If(amount.Is(low).And(difficulty.Is(easy))).Then(achiever.Is(novice)); var rule2 = Rule.If(amount.Is(low).And(difficulty.Is(normal))).Then(achiever.Is(advance)); var rule3 = Rule.If(amount.Is(low).And(difficulty.Is(hard))).Then(achiever.Is(advance)); var rule4 = Rule.If(amount.Is(medium).And(difficulty.Is(easy))).Then(achiever.Is(novice)); var rule5 = Rule.If(amount.Is(medium).And(difficulty.Is(normal))).Then(achiever.Is(advance)); var rule6 = Rule.If(amount.Is(medium).And(difficulty.Is(hard))).Then(achiever.Is(proficient)); var rule7 = Rule.If(amount.Is(high).And(difficulty.Is(easy))).Then(achiever.Is(advance)); var rule8 = Rule.If(amount.Is(high).And(difficulty.Is(normal))).Then(achiever.Is(proficient)); var rule9 = Rule.If(amount.Is(high).And(difficulty.Is(hard))).Then(achiever.Is(expert)); fuzzyEngine.Rules.Add(rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9); var result = fuzzyEngine.Defuzzify(new { amount = questFinished, difficulty = avgDifficulty }); return(result); }
public double SocializerFuzzy(double activity, double interaction) { //Socializer Characteristic Fuzzy Set LinguisticVariable amount = new LinguisticVariable("Amount"); var low = amount.MembershipFunctions.AddTriangle("Low", 1, 10, 10); var medium = amount.MembershipFunctions.AddTriangle("Medium", 8, 16, 16); var high = amount.MembershipFunctions.AddTrapezoid("High", 15, 30, 100, 100); LinguisticVariable interact = new LinguisticVariable("Interact"); var little = interact.MembershipFunctions.AddTriangle("Little", 1, 3, 3); var average = interact.MembershipFunctions.AddTriangle("Average", 2, 5, 5); var lot = interact.MembershipFunctions.AddTrapezoid("Lot", 7, 8, 10, 10); LinguisticVariable socializer = new LinguisticVariable("Socializer"); var novice = socializer.MembershipFunctions.AddTriangle("Novice", 0, 3, 3); var advance = socializer.MembershipFunctions.AddTriangle("Advance", 2, 5, 5); var proficient = socializer.MembershipFunctions.AddTriangle("Proficient", 4, 8, 8); var expert = socializer.MembershipFunctions.AddTrapezoid("Expert", 7, 8, 10, 10); IFuzzyEngine fuzzyEngine = new FuzzyEngineFactory().Create(new MoMDefuzzification()); var rule1 = Rule.If(amount.Is(low).And(interact.Is(little))).Then(socializer.Is(novice)); var rule2 = Rule.If(amount.Is(low).And(interact.Is(average))).Then(socializer.Is(advance)); var rule3 = Rule.If(amount.Is(low).And(interact.Is(lot))).Then(socializer.Is(advance)); var rule4 = Rule.If(amount.Is(medium).And(interact.Is(little))).Then(socializer.Is(novice)); var rule5 = Rule.If(amount.Is(medium).And(interact.Is(average))).Then(socializer.Is(advance)); var rule6 = Rule.If(amount.Is(medium).And(interact.Is(lot))).Then(socializer.Is(proficient)); var rule7 = Rule.If(amount.Is(high).And(interact.Is(little))).Then(socializer.Is(advance)); var rule8 = Rule.If(amount.Is(high).And(interact.Is(average))).Then(socializer.Is(proficient)); var rule9 = Rule.If(amount.Is(high).And(interact.Is(lot))).Then(socializer.Is(expert)); fuzzyEngine.Rules.Add(rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9); var result = fuzzyEngine.Defuzzify(new { amount = activity, interact = interaction }); return(result); }
public static double CalcularPoliza(double inputEnfermedadesActuales, double inputEnfermedadesHistoricas, double inputEstiloDeVida, double inputOcupacion) { LinguisticVariable enfermedadesActuales = new LinguisticVariable("EnfermedadesActuales"); var sano = enfermedadesActuales.MembershipFunctions.AddTrapezoid("Sano", 0, 0, 20, 40); var regular = enfermedadesActuales.MembershipFunctions.AddTriangle("Regular", 30, 50, 70); var malo = enfermedadesActuales.MembershipFunctions.AddTrapezoid("Malo", 60, 80, 100, 100); LinguisticVariable enfermedadesHistoricas = new LinguisticVariable("EnfermedadesHistoricas"); var bajas = enfermedadesHistoricas.MembershipFunctions.AddTrapezoid("Bajas", 0, 0, 20, 40); var normales = enfermedadesHistoricas.MembershipFunctions.AddTriangle("Normales", 30, 50, 70); var altas = enfermedadesHistoricas.MembershipFunctions.AddTrapezoid("Altas", 60, 80, 100, 100); LinguisticVariable estiloVida = new LinguisticVariable("EstiloVida"); var tranquilo = estiloVida.MembershipFunctions.AddTrapezoid("Tranquilo", 0, 0, 20, 40); var moderado = estiloVida.MembershipFunctions.AddTriangle("Moderado", 30, 50, 70); var reisgozo = estiloVida.MembershipFunctions.AddTrapezoid("Riesgozo", 60, 80, 100, 100); LinguisticVariable ocupacion = new LinguisticVariable("Ocupacion"); var ocupacionNormal = ocupacion.MembershipFunctions.AddTrapezoid("Normal", 0, 0, 20, 40); var ocupacionBajoRiezgo = ocupacion.MembershipFunctions.AddTriangle("Riesgoza", 30, 50, 70); var ocupacionAltoRiezgo = ocupacion.MembershipFunctions.AddTrapezoid("AltoRiezgo", 60, 80, 100, 100); LinguisticVariable estadoAseguramiento = new LinguisticVariable("EstadoAseguramiento"); var coberturaTotal = estadoAseguramiento.MembershipFunctions.AddTrapezoid("Total", 0, 0, 17.5, 30); var coberturaModerada = estadoAseguramiento.MembershipFunctions.AddTriangle("Moderada", 20, 37.5, 55); var coberturaBaja = estadoAseguramiento.MembershipFunctions.AddTriangle("Baja", 45, 62.5, 80); var coberturaNula = estadoAseguramiento.MembershipFunctions.AddTrapezoid("Nula", 70, 87.5, 100, 100); IFuzzyEngine fuzzyEngine = new FuzzyEngineFactory().Create(new CoGDefuzzification()); fuzzyEngine.Rules .If(enfermedadesActuales.Is(malo).Or(enfermedadesHistoricas.Is(altas))) .If(estiloVida.Is(reisgozo).Or(ocupacion.Is(ocupacionAltoRiezgo))) .Then(estadoAseguramiento.Is(coberturaNula)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(malo).Or(enfermedadesHistoricas.Is(altas))) .If(estiloVida.Is(reisgozo).And(ocupacion.Is(ocupacionBajoRiezgo))) .Then(estadoAseguramiento.Is(coberturaNula)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(malo).Or(enfermedadesHistoricas.Is(altas))) .If(estiloVida.Is(moderado).And(ocupacion.Is(ocupacionAltoRiezgo))) .Then(estadoAseguramiento.Is(coberturaNula)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(malo).Or(enfermedadesHistoricas.Is(altas))) .If(estiloVida.Is(moderado).And(ocupacion.Is(ocupacionBajoRiezgo))) .Then(estadoAseguramiento.Is(coberturaBaja)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(malo).Or(enfermedadesHistoricas.Is(altas))) .If(estiloVida.Is(moderado).And(ocupacion.Is(ocupacionNormal))) .Then(estadoAseguramiento.Is(coberturaBaja)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(malo).Or(enfermedadesHistoricas.Is(altas))) .If(estiloVida.Is(tranquilo).And(ocupacion.Is(ocupacionBajoRiezgo))) .Then(estadoAseguramiento.Is(coberturaBaja)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(malo).Or(enfermedadesHistoricas.Is(altas))) .If(estiloVida.Is(tranquilo).And(ocupacion.Is(ocupacionNormal))) .Then(estadoAseguramiento.Is(coberturaModerada)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(regular).Or(enfermedadesHistoricas.Is(normales)).And(estiloVida.Is(reisgozo)).And(ocupacion.Is(ocupacionAltoRiezgo))) .Then(estadoAseguramiento.Is(coberturaNula)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(regular).Or(enfermedadesHistoricas.Is(normales)).And(estiloVida.Is(moderado)).And(ocupacion.Is(ocupacionAltoRiezgo))) .Then(estadoAseguramiento.Is(coberturaBaja)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(regular).Or(enfermedadesHistoricas.Is(normales)).And(estiloVida.Is(reisgozo)).And(ocupacion.Is(ocupacionBajoRiezgo))) .Then(estadoAseguramiento.Is(coberturaBaja)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(regular).Or(enfermedadesHistoricas.Is(normales)).And(estiloVida.Is(moderado)).And(ocupacion.Is(ocupacionBajoRiezgo))) .Then(estadoAseguramiento.Is(coberturaModerada)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(regular).Or(enfermedadesHistoricas.Is(normales)).And(estiloVida.Is(tranquilo)).And(ocupacion.Is(ocupacionBajoRiezgo))) .Then(estadoAseguramiento.Is(coberturaModerada)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(regular).Or(enfermedadesHistoricas.Is(normales)).And(estiloVida.Is(moderado)).And(ocupacion.Is(ocupacionNormal))) .Then(estadoAseguramiento.Is(coberturaModerada)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(regular).Or(enfermedadesHistoricas.Is(normales)).And(estiloVida.Is(tranquilo)).And(ocupacion.Is(ocupacionNormal))) .Then(estadoAseguramiento.Is(coberturaTotal)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(sano).Or(enfermedadesHistoricas.Is(bajas)).And(estiloVida.Is(reisgozo)).And(ocupacion.Is(ocupacionAltoRiezgo))) .Then(estadoAseguramiento.Is(coberturaBaja)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(sano).Or(enfermedadesHistoricas.Is(bajas)).And(estiloVida.Is(moderado)).And(ocupacion.Is(ocupacionAltoRiezgo))) .Then(estadoAseguramiento.Is(coberturaModerada)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(sano).Or(enfermedadesHistoricas.Is(bajas)).And(estiloVida.Is(reisgozo)).And(ocupacion.Is(ocupacionBajoRiezgo))) .Then(estadoAseguramiento.Is(coberturaModerada)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(sano).Or(enfermedadesHistoricas.Is(bajas)).And(estiloVida.Is(moderado)).And(ocupacion.Is(ocupacionBajoRiezgo))) .Then(estadoAseguramiento.Is(coberturaTotal)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(sano).Or(enfermedadesHistoricas.Is(bajas)).And(estiloVida.Is(tranquilo)).And(ocupacion.Is(ocupacionBajoRiezgo))) .Then(estadoAseguramiento.Is(coberturaTotal)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(sano).Or(enfermedadesHistoricas.Is(bajas)).And(estiloVida.Is(moderado)).And(ocupacion.Is(ocupacionNormal))) .Then(estadoAseguramiento.Is(coberturaTotal)); fuzzyEngine.Rules .If(enfermedadesActuales.Is(sano).Or(enfermedadesHistoricas.Is(bajas))) .If(estiloVida.Is(tranquilo).And(ocupacion.Is(ocupacionNormal))) .Then(estadoAseguramiento.Is(coberturaTotal)); var result = fuzzyEngine.Defuzzify(new { enfermedadesActuales = inputEnfermedadesActuales, enfermedadesHistoricas = inputEnfermedadesHistoricas, estiloVida = inputEstiloDeVida, ocupacion = inputOcupacion }); return result; }