public static FuzzySet operator &(FuzzySet operand1, FuzzySet operand2)//static->不屬於物件 { FuzzySet fs = null; fs = new BinaryOperatedFuzzySet(new Union(), operand1, operand2); return(fs); }
private void btnMamdaniInference_Click(object sender, EventArgs e) { if (OutputUniverse == null || OutputFuzzySets.Count == 0) //至少要有output universe { MessageBox.Show("Output Universe doesn' t exist", "No Ouput Universe", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //inference calculation List <FuzzySet> conditionFSlist = new List <FuzzySet>(); IfThenRule SelectedRule = (IfThenRule)listBoxIfThenRule.SelectedItem; FuzzySet result = null; for (int i = 0; i < RuleList.Count; i++) { for (int j = 0; j < InputUniverses.Count; j++) { if (dataGridView2nd.Rows[0].Cells["Input" + j].Value != null) { conditionFSlist.Add((FuzzySet)dataGridView2nd.Rows[i].Cells["Input" + j].Value); } } if (i == 0)// 第一個 { result = RuleList[i].MamdaniInference(conditionFSlist); } FuzzySet temp = RuleList[i].MamdaniInference(conditionFSlist); result = new BinaryOperatedFuzzySet(new Union(), temp, result); } result.Title = "Mamdani Inference result " + countInf; result.line.ChartType = SeriesChartType.Area; chartOutput.Series.Add(result.line); countInf++; //defuzzification txtBOA.Text = result.BOA.ToString(); txtCOA.Text = result.COA.ToString(); txtLOM.Text = result.LOM.ToString(); txtMOM.Text = result.MOM.ToString(); txtSOM.Text = result.SOM.ToString(); }
private void btnAddBinary_Click(object sender, EventArgs e) { TreeNode tn = treeViewInputUniverse.SelectedNode; if (tn.Level == 0) { BinaryOperator op = null; //local variable default FuzzySet SelectedFS1 = (FuzzySet)comboBoxBinary1stFS.SelectedItem; //透過cast轉型 FuzzySet SelectedFS2 = (FuzzySet)comboBoxBinary2ndFS.SelectedItem; if (SelectedFS1 == null || SelectedFS2 == null) //有一格沒選到 { MessageBox.Show("one of fuzzy sets is not selected", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (listBoxBinary.SelectedIndex < 0) { MessageBox.Show("binary operator is not selected", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (SelectedFS1.universe != SelectedFS2.universe) //一定要屬於同個universe { MessageBox.Show("the fuzzy sets must belong to the same universe", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { switch (listBoxBinary.SelectedIndex) { case 0: //Intersect op = new Intersect(); break; case 1: //Alegraic Product op = new AlegraicProduct(); break; case 2: //BoundedProduct op = new BoundedProduct(); break; case 3: //DrasticProduct op = new DrasticProduct(); break; case 4: //Union op = new Union(); break; case 5: //AlgebraicSum op = new AlgebraicSum(); break; case 6: //BoundedSum op = new BoundedSum(); break; case 7: //DrasticSum op = new DrasticSum(); break; case 8: //SugenoT MessageBox.Show("Sugeno T-norm is not implemented yet!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; //op = new SugenoTNorm(); case 9: //SugenoS //op = new SugenoSNorm(); MessageBox.Show("Sugeno S-norm is not implemented yet!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; case 10: //YagerT //op = new YagerTNom(); MessageBox.Show("Yager T-norm is not implemented yet!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; case 11: //YagerS //op = new YagerSNorm(); MessageBox.Show("Yager S-norm is not implemented yet!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //加入各清單之中 BinaryOperatedFuzzySet BFS = new BinaryOperatedFuzzySet(op, SelectedFS1, SelectedFS2); InputfuzzySetObjects.Add(BFS); comboBoxBinary1stFS.Items.Add(BFS); comboBoxBinary2ndFS.Items.Add(BFS); int idx = 0; for (int i = 0; i < InputUniverses.Count; i++) //找是屬於treeview上哪個node { if (SelectedFS1.universe.title != InputUniverses[i].title) { idx++; } else { break; } } allInputFuzzySets[tn.Index].Add(BFS); //add a node to represent the fuzzyset TreeNode tnn = new TreeNode(BFS.title); tnn.ImageIndex = 1; tnn.SelectedImageIndex = 1; treeViewInputUniverse.Nodes[tn.Index].Nodes.Add(tnn); chartInput.Series.Add(BFS.line); } } else { MessageBox.Show("You must select a universe", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }