private void MfBtn_Click(object sender, EventArgs e) { if (!MFView.Items.ContainsKey(MFNameTxT.Text)) { List <double> pts = FuzzyApp.tokString(MFParamTxT.Text); FuzzyLogicController.MFs.MemberShipFunction mftemp; if (MFTypeCombo.SelectedIndex == 0) { mftemp = new FuzzyLogicController.MFs.Trimf(MFNameTxT.Text, pts[0], pts[1], pts[2]); Current.MFs.Add(mftemp); popualteMF(mftemp); } else if (MFTypeCombo.SelectedIndex == 1) { mftemp = new FuzzyLogicController.MFs.Trapmf(MFNameTxT.Text, pts[0], pts[1], pts[2], pts[3]); Current.MFs.Add(mftemp); popualteMF(mftemp); } Populate(); this.ChartPanel.Paint += new PaintEventHandler(drawSelectedMF); this.ChartPanel.Refresh(); } else { MessageBox.Show("It Exists!!! Try a new mf name", "MemberShip Function Exists", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void OnRangeEdit(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { Current.Range = FuzzyApp.tokString(RangeTxT.Text); this.ChartPanel.Paint += new PaintEventHandler(drawSelectedMF); this.ChartPanel.Refresh(); Populate(); } }
private void SaveMFBtn_Click(object sender, EventArgs e) { if (MFView.Items.Count > 0) { Current.MFs[MFView.SelectedIndices[0]].Name = MFNameTxT.Text; MFView.Items[MFView.SelectedIndices[0]].Name = MFNameTxT.Text; MFView.Items[MFView.SelectedIndices[0]].Text = MFNameTxT.Text; Current.MFs[MFView.SelectedIndices[0]].Params = FuzzyApp.tokString(MFParamTxT.Text); this.ChartPanel.Paint += new PaintEventHandler(drawSelectedMF); this.ChartPanel.Refresh(); Populate(); } }
private void InTxT_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { clearAll(); List <double> inputs = FuzzyApp.tokString(InTxT.Text); CrispPan.RowCount = FuzzyApp.InputVariables.Count; for (int i = 0; i < FuzzyApp.InputVariables.Count; i++) { CrispPan.Controls.Add(TextLabel(FuzzyApp.InputVariables[i].Name + " : " + inputs[i], TextType.Normal)); } //Fuzzification List <FuzzySet> InSets = new List <FuzzySet>(); for (int i = 0; i < FuzzyApp.InputVariables.Count; i++) { InSets.Add(new FuzzySet(FuzzyApp.FuzzyControl.Fuzzification(inputs[i], FuzzyApp.InputVariables[i]), FuzzyApp.InputVariables[i].Name)); } for (int i = 0; i < InSets.Count; i++) { FuzzPan.Controls.Add(TextLabel(InSets[i].Variable, TextType.Normal)); for (int j = 0; j < InSets[i].Set.Count; j++) { FuzzPan.Controls.Add(TextLabel(InSets[i].Set[j].MemberShipName + ":" + InSets[i].Set[j].FuzzyValue.ToString(), TextType.Normal)); } } //Inference Engine InferEngine engine = new InferEngine(FuzzyApp.Configuration, FuzzyApp.Rules, InSets); List <FuzzySet> RuleResults = engine.evaluateRules(); EnginePan.Controls.Add(TextLabel("Triggered Rules", TextType.Header)); for (int i = 0; i < engine.FiredRules.Count; i++) { EnginePan.Controls.Add(TextLabel("Rule :" + engine.FiredRules[i].ToString(), TextType.Normal, FuzzyApp.Rules[engine.FiredRules[i] - 1].ToString())); } for (int i = 0; i < RuleResults.Count; i++) { DeFuzzPan.Controls.Add(TextLabel(RuleResults[i].Variable, TextType.Header)); for (int j = 0; j < RuleResults[i].Set.Count; j++) { DeFuzzPan.Controls.Add(TextLabel(RuleResults[i].Set[j].MemberShipName + " : " + RuleResults[i].Set[j].FuzzyValue.ToString(), TextType.Normal)); } } //deFuzzification List <double> CrispValues = new List <double>(); for (int i = 0; i < FuzzyApp.OutputVariables.Count; i++) { CrispValues.Add(FuzzyApp.FuzzyControl.DeFuzzification(RuleResults, FuzzyApp.OutputVariables[i])); } for (int i = 0; i < CrispValues.Count; i++) { String text = FuzzyApp.OutputVariables[i].Name + " : " + CrispValues[i].ToString(); CrispView.Items.Add(text); } } }