Ejemplo n.º 1
0
        //update treeview
        private void ptgProperty_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            TreeNode tn = treeViewInputUniverse.SelectedNode;

            if (tn.Level == 0) //universe
            {
                Universe SelectedU = InputUniverses[tn.Index];
                tn.Text = SelectedU.Title;
            }
            if (tn.Level == 1)//fuzzySet
            {
                FuzzySet SelectedFS = allInputFuzzySets[tn.Parent.Index][tn.Index];
                tn.Text = SelectedFS.Title;
            }
        }
Ejemplo n.º 2
0
        //    delegate void
        //public double MaximumDegree()
        //{

        //}
        public FuzzySet MamdaniInference(List <FuzzySet> condition)
        {
            FuzzySet result       = null;
            double   fireStrength = 1.0;

            for (int i = 0; i < inputFuzzySets.Count; i++)
            {
                double temp = ((inputFuzzySets[i]) & (condition[i])).getMaxDegree(); //交集取最大值
                if (temp < fireStrength)                                             //取最小值
                {
                    fireStrength = temp;
                }
                result = new UnaryOperatedFuzzySet(new ValueCut(fireStrength), outputFuzzySet); //cut value
            }
            return(result);
        }
Ejemplo n.º 3
0
        //選到output treeview的點
        private void treeViewOutputU_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            int idx = e.Node.Index;

            SelectedNode = e.Node;
            if (SelectedNode.Level == 0) //選到universe->可以更新universe
            {
                Universe selectedU = OutputUniverse;
                txtTitle.Text = selectedU.title;
                txtMax.Text   = selectedU.max.ToString();
                txtMin.Text   = selectedU.min.ToString();
                txtInc.Text   = selectedU.inc.ToString();
                ptgProperty.SelectedObject = selectedU;
            }
            if (SelectedNode.Level == 1)                       //選到fuzzy set->可以更新變數-->準備可用欄位
            {
                FuzzySet selectedFS = OutputFuzzySets[idx];    //選到"那個"fuzzy set
                txtUnaryTarget.Text        = selectedFS.title; //加到Unary
                ptgProperty.SelectedObject = selectedFS;
            }
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        private void btnAddFuzzy_Click(object sender, EventArgs e)
        {
            FuzzySet fs = null; //local variable default

            if (ptgProperty.SelectedObject is FuzzySet)
            {
                MessageBox.Show("You must select a universe", "No Universe selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Universe uu = (Universe)ptgProperty.SelectedObject;

            switch (lsbOptions.SelectedIndex)
            {
            case 0:     //Triangular
                fs = new TriangularFuzzySet(uu);
                break;

            case 1:     //Gaussian
                fs = new GaussianFuzzySet(uu);
                break;

            case 2:    //Bell
                fs = new BellFuzzySet(uu);
                break;

            case 3:    //LeftRight
                fs = new LeftRightFuzzySet(uu);
                break;

            case 4:    //Sigmoodal
                fs = new SigmoidalFuzzySet(uu);
                break;

            case 5:    //Trapezoidal
                fs = new TrapezoidalFuzzySet(uu);
                break;

            case 6:    //Sshape
                fs = new SshapeFuzzySet(uu);
                break;

            case 7:
                fs = new ZshapeFuzzySet(uu);
                break;

            case 8:
                fs = new PishapeFuzzySet(uu);
                break;
            }
            if (SelectedNode.TreeView == treeViewInputUniverse)
            {
                //fuzzySetObjects.Add(fs);
                allInputFuzzySets[SelectedNode.Index].Add(fs);
                //加入comboBox
                comboBoxBinary1stFS.Items.Add(fs);
                comboBoxBinary2ndFS.Items.Add(fs);
                //add a node to represent the fuzzyset
                TreeNode tnn = new TreeNode(fs.title);
                treeViewInputUniverse.Nodes[SelectedNode.Index].Nodes.Add(tnn);
                tnn.ImageIndex         = 1;
                tnn.SelectedImageIndex = 1;
                inputCols1[SelectedNode.Index].Items.Add(fs);
                inputCols2[SelectedNode.Index].Items.Add(fs);
                treeViewInputUniverse.ExpandAll();
                chartInput.Series.Add(fs.line);
            }
            else //output universe
            {
                OutputFuzzySets.Add(fs);
                comboBoxBinary1stFS.Items.Add(fs);
                comboBoxBinary2ndFS.Items.Add(fs);
                //add a node to represent the fuzzyset
                TreeNode tnn = new TreeNode(fs.title);
                treeViewOutputU.Nodes[SelectedNode.Index].Nodes.Add(tnn);
                tnn.ImageIndex         = 1;
                tnn.SelectedImageIndex = 1;
                outputCol1.Items.Add(fs);
                outputCol2.Items.Add(fs);
                treeViewOutputU.ExpandAll();
                chartOutput.Series.Add(fs.line);
            }
        }