Beispiel #1
0
        private void listBoxIfThenRule_MouseClick(object sender, MouseEventArgs e)
        {
            int idx = listBoxIfThenRule.SelectedIndex;

            if (idx < 0)
            {
                return;
            }
            dataGridView1st.Rows.Clear( );
            dataGridView2nd.Rows.Clear();
            IfThenRule itr = (IfThenRule)listBoxIfThenRule.SelectedItem;

            dataGridView1st.Rows.Add();
            dataGridView2nd.Rows.Add();
            for (int i = 0; i < inputCols1.Count; i++)
            {
                dataGridView1st.Rows[0].Cells["Input" + i].Value = itr.inputFuzzySets[i];
                dataGridView2nd.Rows[0].Cells["Input" + i].Value = itr.inputFuzzySets[i];
            }
            dataGridView1st.Rows[0].Cells["Output"].Value = itr.outputFuzzySet;
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        private void btnUpdateRule_Click(object sender, EventArgs e)
        {
            if (listBoxIfThenRule.SelectedIndex < 0)
            {
                return;
            }
            int        idx = listBoxIfThenRule.SelectedIndex;
            IfThenRule itr = (IfThenRule)listBoxIfThenRule.SelectedItem;

            for (int i = 0; i < itr.inputFuzzySets.Count; i++)
            {
                itr.inputFuzzySets[i] = (FuzzySet)dataGridView1st.Rows[0].Cells["Input" + i].Value;
            }
            itr.outputFuzzySet = (FuzzySet)dataGridView1st.Rows[0].Cells["Output"].Value;
            // 將清單內容更新
            listBoxIfThenRule.SelectedIndex = -1;  // 先移開
            listBoxIfThenRule.Items[idx]    = "";  // 清空該項
            listBoxIfThenRule.Items[idx]    = itr; // 重設回來讓他更新內容
            listBoxIfThenRule.SelectedIndex = idx; // 移回本rule
            // 清除此  row
            dataGridView1st.Rows.Clear();
        }
Beispiel #4
0
        //加入rule
        private void btnAddRule_Click(object sender, EventArgs e)
        {
            List <FuzzySet> fslist = new List <FuzzySet>();

            if (OutputUniverse == null || OutputFuzzySets.Count == 0)
            {
                MessageBox.Show("Output Universe doesn' t exist or Output Fuzzy Set doen't exist ", "No Ouput Universe", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            for (int i = 0; i < InputUniverses.Count; i++)
            {
                if (allInputFuzzySets[i].Count == 0) //如果沒有就不要加
                {
                    MessageBox.Show("Fuzzy Set doesn' t exist", "No fuzzy set exist", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                fslist.Add(allInputFuzzySets[i][0]); //預設是把全部universe的第一個加入
            }
            IfThenRule rule = new IfThenRule(fslist, OutputFuzzySets[0]);

            RuleList.Add(rule);
            listBoxIfThenRule.Items.Add(rule);
        }