/// <summary> /// Set coefficient by fuzzy variable /// </summary> /// <param name="var">Fuzzy variable</param> /// <param name="coeff">New value of the coefficient</param> public void SetCoefficient(FuzzyVariable var, double coeff) { if (var == null) { _constValue = coeff; } else { _coeffs[var] = coeff; } }
/// <summary> /// Get coefficient by fuzzy variable /// </summary> /// <param name="var">Fuzzy variable</param> /// <returns>Coefficient's value</returns> public double GetCoefficient(FuzzyVariable var) { if (var == null) { return(_constValue); } else { return(_coeffs[var]); } }
void AddSugenoFuzzyRule( SugenoFuzzySystem fs, FuzzyVariable fv1, FuzzyVariable fv2, SugenoVariable sv, string value1, string value2, string result) { SugenoFuzzyRule rule = fs.EmptyRule(); rule.Condition.Op = OperatorType.And; rule.Condition.ConditionsList.Add(rule.CreateCondition(fv1, fv1.GetTermByName(value1))); rule.Condition.ConditionsList.Add(rule.CreateCondition(fv2, fv2.GetTermByName(value2))); rule.Conclusion.Var = sv; rule.Conclusion.Term = sv.GetFuncByName(result); fs.Rules.Add(rule); }
SugenoFuzzySystem CreateSystem() { // // Create empty Sugeno Fuzzy System // SugenoFuzzySystem fsCruiseControl = new SugenoFuzzySystem(); // // Create input variables for the system // FuzzyVariable fvSCPU = new FuzzyVariable("CPU", 500, 4000); fvSCPU.Terms.Add(new FuzzyTerm("slow", new TriangularMembershipFunction(500, 1000, 1500))); fvSCPU.Terms.Add(new FuzzyTerm("medium", new TriangularMembershipFunction(1400, 1700, 2000))); fvSCPU.Terms.Add(new FuzzyTerm("fast", new TriangularMembershipFunction(1800, 2500, 4000))); fsCruiseControl.Input.Add(fvSCPU); FuzzyVariable fvCore = new FuzzyVariable("Core", 1, 8); fvCore.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(1, 2, 3))); fvCore.Terms.Add(new FuzzyTerm("medium", new TriangularMembershipFunction(3, 4, 6))); fvCore.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(4, 6, 8))); fsCruiseControl.Input.Add(fvCore); FuzzyVariable fvRam = new FuzzyVariable("Ram", 512, 6000); fvRam.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(512, 1000, 1500))); fvRam.Terms.Add(new FuzzyTerm("medium", new TriangularMembershipFunction(1200, 2000, 3000))); fvRam.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(2500, 4000, 6000))); fsCruiseControl.Input.Add(fvRam); FuzzyVariable fvPrice = new FuzzyVariable("Price", 70, 3500); fvPrice.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(-9.0, -5.0, -1.0))); fvPrice.Terms.Add(new FuzzyTerm("medium", new TriangularMembershipFunction(-4.0, -0.0, 4.0))); fvPrice.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(1.0, 5.0, 9.0))); fsCruiseControl.Input.Add(fvPrice); FuzzyVariable fvBattery = new FuzzyVariable("Battery", 350, 12000); fvBattery.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(350, 2000, 5000))); fvBattery.Terms.Add(new FuzzyTerm("medium", new TriangularMembershipFunction(4000, 6000, 9000))); fvBattery.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(8000, 10000, 12000))); fsCruiseControl.Input.Add(fvBattery); FuzzyVariable fvStorage = new FuzzyVariable("Storage", 8, 256); fvStorage.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(8, 60, 100))); fvStorage.Terms.Add(new FuzzyTerm("medium", new TriangularMembershipFunction(90, 150, 180))); fvStorage.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(170, 200, 256))); fsCruiseControl.Input.Add(fvStorage); FuzzyVariable fvScreen1 = new FuzzyVariable("Screen1", 400, 4000); fvScreen1.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(400, 1000, 1500))); fvScreen1.Terms.Add(new FuzzyTerm("medium", new TriangularMembershipFunction(1200, 2000, 2500))); fvScreen1.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(2200, 3000, 4000))); fsCruiseControl.Input.Add(fvScreen1); FuzzyVariable fvScreen2 = new FuzzyVariable("Screen2", 800, 4000); fvScreen2.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(400, 1000, 1500))); fvScreen2.Terms.Add(new FuzzyTerm("medium", new TriangularMembershipFunction(1200, 2000, 2500))); fvScreen2.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(2200, 3000, 4000))); fsCruiseControl.Input.Add(fvScreen2); // FuzzyVariable fvCamera = new FuzzyVariable("Camera", 5, 23); fvCamera.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(5, 7, 12))); fvCamera.Terms.Add(new FuzzyTerm("medium", new TriangularMembershipFunction(8, 14, 17))); fvCamera.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(15, 18, 23))); fsCruiseControl.Input.Add(fvCamera); // Create output variables for the system // /* SugenoVariable svAccelerate = new SugenoVariable("Accelerate"); * svAccelerate.Functions.Add(fsCruiseControl.CreateSugenoFunction("zero", new double[] { 0.0, 0.0, 0.0 })); * svAccelerate.Functions.Add(fsCruiseControl.CreateSugenoFunction("faster", new double[] { 0.0, 0.0, 1.0 })); * svAccelerate.Functions.Add(fsCruiseControl.CreateSugenoFunction("slower", new double[] { 0.0, 0.0, -1.0 })); * svAccelerate.Functions.Add(fsCruiseControl.CreateSugenoFunction("func", new double[] { -0.04, -0.1, 0.0 })); * fsCruiseControl.Output.Add(svAccelerate); * * // * // Create fuzzy rules * // * AddSugenoFuzzyRule(fsCruiseControl, fvSCPU, fvCore, svAccelerate, "slower", "slower", "faster"); * AddSugenoFuzzyRule(fsCruiseControl, fvSCPU, fvCore, svAccelerate, "slower", "zero", "faster"); * AddSugenoFuzzyRule(fsCruiseControl, fvSCPU, fvCore, svAccelerate, "slower", "faster", "zero"); * AddSugenoFuzzyRule(fsCruiseControl, fvSCPU, fvCore, svAccelerate, "zero", "slower", "faster"); * AddSugenoFuzzyRule(fsCruiseControl, fvSCPU, fvCore, svAccelerate, "zero", "zero", "func"); * AddSugenoFuzzyRule(fsCruiseControl, fvSCPU, fvCore, svAccelerate, "zero", "faster", "slower"); * AddSugenoFuzzyRule(fsCruiseControl, fvSCPU, fvCore, svAccelerate, "faster", "slower", "zero"); * AddSugenoFuzzyRule(fsCruiseControl, fvSCPU, fvCore, svAccelerate, "faster", "zero", "slower"); * AddSugenoFuzzyRule(fsCruiseControl, fvSCPU, fvCore, svAccelerate, "faster", "faster", "slower");*/ // // Adding the same rules in text form // /////////////////////////////////////////////////////////////////// //SugenoFuzzyRule rule1 = fsCruiseControl.ParseRule("if (SpeedError is slower) and (SpeedErrorDot is slower) then (Accelerate is faster)"); //SugenoFuzzyRule rule2 = fsCruiseControl.ParseRule("if (SpeedError is slower) and (SpeedErrorDot is zero) then (Accelerate is faster)"); //SugenoFuzzyRule rule3 = fsCruiseControl.ParseRule("if (SpeedError is slower) and (SpeedErrorDot is faster) then (Accelerate is zero)"); //SugenoFuzzyRule rule4 = fsCruiseControl.ParseRule("if (SpeedError is zero) and (SpeedErrorDot is slower) then (Accelerate is faster)"); //SugenoFuzzyRule rule5 = fsCruiseControl.ParseRule("if (SpeedError is zero) and (SpeedErrorDot is zero) then (Accelerate is func)"); //SugenoFuzzyRule rule6 = fsCruiseControl.ParseRule("if (SpeedError is zero) and (SpeedErrorDot is faster) then (Accelerate is slower)"); //SugenoFuzzyRule rule7 = fsCruiseControl.ParseRule("if (SpeedError is faster) and (SpeedErrorDot is slower) then (Accelerate is faster)"); //SugenoFuzzyRule rule8 = fsCruiseControl.ParseRule("if (SpeedError is faster) and (SpeedErrorDot is zero) then (Accelerate is slower)"); //SugenoFuzzyRule rule9 = fsCruiseControl.ParseRule("if (SpeedError is faster) and (SpeedErrorDot is faster) then (Accelerate is slower)"); //fsCruiseControl.Rules.Add(rule1); //fsCruiseControl.Rules.Add(rule2); //fsCruiseControl.Rules.Add(rule3); //fsCruiseControl.Rules.Add(rule4); //fsCruiseControl.Rules.Add(rule5); //fsCruiseControl.Rules.Add(rule6); //fsCruiseControl.Rules.Add(rule7); //fsCruiseControl.Rules.Add(rule8); //fsCruiseControl.Rules.Add(rule9); /////////////////////////////////////////////////////////////////// return(fsCruiseControl); }
/// <summary> /// Create a single condition /// </summary> /// <param name="var">A linguistic variable to which the condition is related</param> /// <param name="term">A term in expression 'var is term'</param> /// <param name="not">Does condition contain 'not'</param> /// <param name="hedge">Hedge modifier</param> /// <returns>Generated condition</returns> public FuzzyCondition CreateCondition(FuzzyVariable var, FuzzyTerm term, bool not, HedgeType hedge) { return(new FuzzyCondition(var, term, not, hedge)); }
/// <summary> /// Create a single condition /// </summary> /// <param name="var">A linguistic variable to which the condition is related</param> /// <param name="term">A term in expression 'var is term'</param> /// <param name="not">Does condition contain 'not'</param> /// <returns>Generated condition</returns> public FuzzyCondition CreateCondition(FuzzyVariable var, FuzzyTerm term, bool not) { return(new FuzzyCondition(var, term, not)); }