// prepare Metadata condequent for Fuzzy Logic with code private FuzzyVariable PrepareMetadata() { FuzzyVariable Metadata = new FuzzyVariable() { Name = "Metadata" }; FuzzyValue Few = new FuzzyValue() { Name = "Few" }; FuzzyValue Medium = new FuzzyValue() { Name = "Medium" }; FuzzyValue All = new FuzzyValue() { Name = "All" }; Few.MF = new TrapezoidMemberShip(0, 0, 10, 30); Medium.MF = new TrapezoidMemberShip(0, 30, 60, 90); All.MF = new TrapezoidMemberShip(60, 90, 100, 100); Metadata.AddValue(Few); Metadata.AddValue(Medium); Metadata.AddValue(All); return(Metadata); }
/// <summary> /// This method reads all Fuzzy Logic configuration from SQLite database, and applies /// this logic to all relevant fuzzy classes /// </summary> private void CreateFuzzyLogicFromSQLiteDB() { try { DataService db = new DataService("fuzzy.db"); var FuzzParts = db.GetFuzzyParts(); var FuzzValues = db.GetFuzzyValues(); var FuzzRules = db.GetFuzzyRules(); // all read so try to create everything from data FuzzyRuleManager mgr = new FuzzyRuleManager(); foreach (FuzzyParts p in FuzzParts) { FuzzyVariable vv = new FuzzyVariable() { Name = p.Name }; if (string.Compare(p.FuzzyType, "Antecedent", false) == 0) { mgr.Antecedents.Add(vv); } else { mgr.Consequent = vv; } foreach (FuzzyValues val in FuzzValues) { if (string.Compare(val.SetName, p.Name, true) == 0) { FuzzyValue fval = new FuzzyValue() { Name = val.Name, Parent = vv }; double[] MFValues = ParseValues(val.MemberValues); if (string.Compare(val.MemberType, "trapmf", true) == 0) // trapezoid MF? { fval.MF = new TrapezoidMemberShip(MFValues[0], MFValues[1], MFValues[2], MFValues[3]); } else { fval.MF = new TriangleMembership(MFValues[0], MFValues[1], MFValues[2]); } vv.AddValue(fval); } } } foreach (FuzzyRules r in FuzzRules) { mgr.AddNewStringRule(r.Rule); } // apply rule manager to member variable mngr = mgr; ReadFromSQLite = true; LogManager.Instance.AddLog("Success Create Fuzzy Logic from SQLite DB"); } catch (Exception ex) { Debug.LogError(ex.Message); } }
private void OnAddValue(MouseEventArgs e, FuzzyVariable variable) { Random rnd = new Random(); FuzzyValue fv = new FuzzyValue(variable, $"Value-{rnd.Next():X08}", $"Description-{rnd.Next():X08}"); variable.AddValue(fv); }
private void OnDuplicateValue(MouseEventArgs e, FuzzyVariable variable, FuzzyValue value) { FuzzyValue copy = value.Clone(); //copy.Name += " (kopia)"; //copy.Description += " (kopia)"; variable.AddValue(copy); }
// prepare Distance antecedent for Fuzzy logic using code private FuzzyVariable PrepareDistance() { FuzzyVariable Distance = new FuzzyVariable() { Name = "Distance" }; FuzzyValue VeryClose = new FuzzyValue() { Name = "VeryClose" }; FuzzyValue Close = new FuzzyValue() { Name = "Close" }; FuzzyValue Medium = new FuzzyValue() { Name = "Medium" }; FuzzyValue Far = new FuzzyValue() { Name = "Far" }; FuzzyValue VeryFar = new FuzzyValue() { Name = "VeryFar" }; VeryClose.MF = new TrapezoidMemberShip(0, 0, 50, 300); Close.MF = new TriangleMembership(0, 300, 1000); Medium.MF = new TriangleMembership(300, 1000, 2000); Far.MF = new TriangleMembership(1000, 2000, 3000); VeryFar.MF = new TrapezoidMemberShip(2000, 3000, 4000, 4000); Distance.AddValue(VeryClose); Distance.AddValue(Close); Distance.AddValue(Medium); Distance.AddValue(Far); Distance.AddValue(VeryFar); return(Distance); }
// prepare speed antecedent for Fuzzy logic using code private FuzzyVariable PrepareSpeed() { FuzzyVariable speed = new FuzzyVariable() { Name = "Speed" }; FuzzyValue VerySlow = new FuzzyValue() { Name = "VerySlow" }; FuzzyValue Slow = new FuzzyValue() { Name = "Slow" }; FuzzyValue Medium = new FuzzyValue() { Name = "Medium" }; FuzzyValue Fast = new FuzzyValue() { Name = "Fast" }; FuzzyValue VeryFast = new FuzzyValue() { Name = "VeryFast" }; VerySlow.MF = new TrapezoidMemberShip(0, 0, 5, 15); Slow.MF = new TriangleMembership(5, 20, 30); Medium.MF = new TriangleMembership(20, 30, 50); Fast.MF = new TrapezoidMemberShip(30, 60, 80, 100); VeryFast.MF = new TrapezoidMemberShip(80, 100, 120, 120); speed.AddValue(VerySlow); speed.AddValue(Slow); speed.AddValue(Medium); speed.AddValue(Fast); speed.AddValue(VeryFast); return(speed); }