示例#1
0
        /// <summary>
        /// Fills in the specified System.Windows.Forms.TreeView component with content representing the fuzzy relation
        /// </summary>
        /// <param name="treeView">Treeview component to display the relation's hierararchy</param>
        /// <param name="pictureBox">PictureBox component to display grapfs for particular nodes, where possible</param>
        /// <param name="label">Label to display caption for the picture</param>
        public void BuildTree(TreeView treeView, PictureBox pictureBox, Label label)
        {
            ImageList imageList = new ImageList();

            imageList.Images.Add("dimensions", Resources.Graph);
            imageList.Images.Add("function", Resources.Function);
            imageList.Images.Add("subrelations", Resources.Function);
            imageList.Images.Add("fuzzySet", Resources.Function);
            imageList.Images.Add("nodeFuzzyRelation", Resources.Function);
            imageList.Images.Add("dimensionType", Resources.Function);
            imageList.Images.Add("dimensionDiscreteKnown", Resources.Function);
            imageList.Images.Add("dimensionDiscreteUnknown", Resources.Function);
            imageList.Images.Add("dimensionContinuousKnown", Resources.Function);
            imageList.Images.Add("dimensionContinuousUnknown", Resources.Function);


            RelationImage img = new RelationImage(_relation, _inputs, _variableDimension);

            img.SupportOnly = true;

            Bitmap bmp = new Bitmap(300, 200);

            imageList.Images.Add(bmp);

            treeView.ImageList   = imageList;
            pictureBox.BackColor = GraphBackgroundColor;
            pictureBox.Image     = null;
            label.Text           = "";

            treeView.BeginUpdate();
            treeView.Nodes.Clear();

            buildSubTree(_relation, treeView.Nodes, pictureBox, label);

            treeView.EndUpdate();
        }
示例#2
0
        void treeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (_pictureBox != null && _label != null)
            {
                //Find nearest relation upper in the hierarchy
                TreeNode tn = e.Node;
                while (tn.Tag == null && !(tn.Tag is FuzzyRelation) && !(tn.Tag is Defuzzification.Defuzzification))
                {
                    if (tn.Parent == null)
                    {   //We are at the top
                        _label.Text = "";
                        _pictureBox.Image = null;
                        tn = null;
                        break;
                    }
                    tn = tn.Parent;
                }

                if (tn != null)
                {
                    if (tn.Tag is Defuzzification.Defuzzification)
                    {
                        Defuzzification.Defuzzification deffuz = (Defuzzification.Defuzzification) tn.Tag;

                        if (allInputDimensionsAvailable(deffuz.Relation))
                        {
                            Dictionary<IDimension, System.Decimal> inputsCopy = new Dictionary<IDimension, System.Decimal>(_inputs);
                            if (!inputsCopy.ContainsKey(deffuz.OutputDimension))
                                inputsCopy.Add(deffuz.OutputDimension, deffuz.CrispValue);
                            else
                                inputsCopy[deffuz.OutputDimension] = deffuz.CrispValue;

                            RelationImage img = new RelationImage(deffuz.Relation, inputsCopy, deffuz.OutputDimension);
                            img.SupportOnly = _supportOnly;
                            Bitmap bmp = new Bitmap(_pictureBox.Width, _pictureBox.Height);
                            img.DrawImage(System.Drawing.Graphics.FromImage(bmp));
                            _pictureBox.Image = bmp;

                            _label.Text = String.Format("{0} deffuzification yields {1}={2:F5} {3}",
                                deffuz.GetType().Name,
                                deffuz.OutputDimension.Name,
                                deffuz.CrispValue,
                                deffuz.OutputDimension is IContinuousDimension ? ((IContinuousDimension)deffuz.OutputDimension).Unit : ""
                             );
                        }else
                            reportTooManyDimensions();
                    }
                    else
                    {
                        FuzzyRelation relation = (FuzzyRelation)tn.Tag;
                        if (allInputDimensionsAvailable(relation))
                        {
                            RelationImage img = null;
                            if ( relation.Dimensions.Count() == 1)
                                img = new RelationImage(relation, _inputs, relation.Dimensions[0]);
                            else if (_variableDimension != null)
                                img = new RelationImage(relation, _inputs, _variableDimension);

                            if (img == null)
                            {
                                _label.Text = "";
                                _pictureBox.Image = null;
                            }
                            else
                            {
                                string lblText = "";
                                img.SupportOnly = _supportOnly;
                                Bitmap bmp = new Bitmap(_pictureBox.Width, _pictureBox.Height);
                                img.DrawImage(System.Drawing.Graphics.FromImage(bmp));
                                _pictureBox.Image = bmp;
                                IDimension realVariableDimension;
                                if (relation.Dimensions.Count() == 1)
                                {
                                    lblText = String.Format("Fuzzy set for dimension {0}.", relation.Dimensions[0].Name);
                                    realVariableDimension = relation.Dimensions[0];
                                }
                                else
                                {
                                    StringBuilder sb = new StringBuilder();
                                    foreach(IDimension dim in relation.Dimensions)
                                    {
                                        if (sb.Length != 0)
                                            sb.Append(" x ");
                                        sb.Append(dim.Name);
                                     }
                                    lblText = String.Format("Fuzzy relation for dimensions ({0}) where {1} is variable.", sb.ToString(), _variableDimension.Name);
                                    realVariableDimension = _variableDimension;
                                }

                                if (_inputs.ContainsKey(realVariableDimension))
                                {
                                    string value;
                                    if (realVariableDimension is IContinuousDimension)
                                    {
                                        IContinuousDimension dim = (IContinuousDimension) realVariableDimension;
                                        value = _inputs[realVariableDimension].ToString("F5");
                                        if (! String.IsNullOrEmpty(dim.Unit) )
                                            value += " " + dim.Unit;
                                    }
                                    else
                                    {
                                        IDiscreteDimension dim = (IDiscreteDimension) realVariableDimension;
                                        if (dim.DefaultSet != null)
                                            value = dim.DefaultSet.GetMember(_inputs[realVariableDimension]).Caption;
                                        else
                                            value = "#" + _inputs[realVariableDimension].ToString("F0");
                                    }

                                    lblText += String.Format("\r\nµ{1}(x)={0:F2} for x={2}.",
                                        relation.IsMember(_inputs),
                                        realVariableDimension.Name,
                                        value
                                     );

                                }
                                _label.Text = lblText;
                            }

                        }

                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Fills in the specified System.Windows.Forms.TreeView component with content representing the fuzzy relation
        /// </summary>
        /// <param name="treeView">Treeview component to display the relation's hierararchy</param>
        /// <param name="pictureBox">PictureBox component to display grapfs for particular nodes, where possible</param>
        /// <param name="label">Label to display caption for the picture</param>
        public void BuildTree( TreeView treeView, PictureBox pictureBox, Label label)
        {
            ImageList imageList = new ImageList();
            imageList.Images.Add("dimensions", Resources.Graph);
            imageList.Images.Add("function", Resources.Function);
            imageList.Images.Add("subrelations", Resources.Function);
            imageList.Images.Add("fuzzySet", Resources.Function);
            imageList.Images.Add("nodeFuzzyRelation", Resources.Function);
            imageList.Images.Add("dimensionType", Resources.Function);
            imageList.Images.Add("dimensionDiscreteKnown", Resources.Function);
            imageList.Images.Add("dimensionDiscreteUnknown", Resources.Function);
            imageList.Images.Add("dimensionContinuousKnown", Resources.Function);
            imageList.Images.Add("dimensionContinuousUnknown", Resources.Function);

            RelationImage img = new RelationImage(_relation, _inputs, _variableDimension);
            img.SupportOnly = true;

            Bitmap bmp = new Bitmap(300, 200);
            imageList.Images.Add(bmp);

            treeView.ImageList = imageList;
            pictureBox.BackColor = GraphBackgroundColor;
            pictureBox.Image = null;
            label.Text = "";

            treeView.BeginUpdate();
            treeView.Nodes.Clear();

            buildSubTree(_relation, treeView.Nodes, pictureBox, label);

            treeView.EndUpdate();
        }
示例#4
0
        void treeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (_pictureBox != null && _label != null)
            {
                //Find nearest relation upper in the hierarchy
                TreeNode tn = e.Node;
                while (tn.Tag == null && !(tn.Tag is FuzzyRelation) && !(tn.Tag is Defuzzification.Defuzzification))
                {
                    if (tn.Parent == null)
                    {   //We are at the top
                        _label.Text       = "";
                        _pictureBox.Image = null;
                        tn = null;
                        break;
                    }
                    tn = tn.Parent;
                }

                if (tn != null)
                {
                    if (tn.Tag is Defuzzification.Defuzzification)
                    {
                        Defuzzification.Defuzzification deffuz = (Defuzzification.Defuzzification)tn.Tag;

                        if (allInputDimensionsAvailable(deffuz.Relation))
                        {
                            Dictionary <IDimension, System.Decimal> inputsCopy = new Dictionary <IDimension, System.Decimal>(_inputs);
                            if (!inputsCopy.ContainsKey(deffuz.OutputDimension))
                            {
                                inputsCopy.Add(deffuz.OutputDimension, deffuz.CrispValue);
                            }
                            else
                            {
                                inputsCopy[deffuz.OutputDimension] = deffuz.CrispValue;
                            }

                            RelationImage img = new RelationImage(deffuz.Relation, inputsCopy, deffuz.OutputDimension);
                            img.SupportOnly = _supportOnly;
                            Bitmap bmp = new Bitmap(_pictureBox.Width, _pictureBox.Height);
                            img.DrawImage(System.Drawing.Graphics.FromImage(bmp));
                            _pictureBox.Image = bmp;

                            _label.Text = String.Format("{0} deffuzification yields {1}={2:F5} {3}",
                                                        deffuz.GetType().Name,
                                                        deffuz.OutputDimension.Name,
                                                        deffuz.CrispValue,
                                                        deffuz.OutputDimension is IContinuousDimension ? ((IContinuousDimension)deffuz.OutputDimension).Unit : ""
                                                        );
                        }
                        else
                        {
                            reportTooManyDimensions();
                        }
                    }
                    else
                    {
                        FuzzyRelation relation = (FuzzyRelation)tn.Tag;
                        if (allInputDimensionsAvailable(relation))
                        {
                            RelationImage img = null;
                            if (relation.Dimensions.Count() == 1)
                            {
                                img = new RelationImage(relation, _inputs, relation.Dimensions[0]);
                            }
                            else if (_variableDimension != null)
                            {
                                img = new RelationImage(relation, _inputs, _variableDimension);
                            }

                            if (img == null)
                            {
                                _label.Text       = "";
                                _pictureBox.Image = null;
                            }
                            else
                            {
                                string lblText = "";
                                img.SupportOnly = _supportOnly;
                                Bitmap bmp = new Bitmap(_pictureBox.Width, _pictureBox.Height);
                                img.DrawImage(System.Drawing.Graphics.FromImage(bmp));
                                _pictureBox.Image = bmp;
                                IDimension realVariableDimension;
                                if (relation.Dimensions.Count() == 1)
                                {
                                    lblText = String.Format("Fuzzy set for dimension {0}.", relation.Dimensions[0].Name);
                                    realVariableDimension = relation.Dimensions[0];
                                }
                                else
                                {
                                    StringBuilder sb = new StringBuilder();
                                    foreach (IDimension dim in relation.Dimensions)
                                    {
                                        if (sb.Length != 0)
                                        {
                                            sb.Append(" x ");
                                        }
                                        sb.Append(dim.Name);
                                    }
                                    lblText = String.Format("Fuzzy relation for dimensions ({0}) where {1} is variable.", sb.ToString(), _variableDimension.Name);
                                    realVariableDimension = _variableDimension;
                                }

                                if (_inputs.ContainsKey(realVariableDimension))
                                {
                                    string value;
                                    if (realVariableDimension is IContinuousDimension)
                                    {
                                        IContinuousDimension dim = (IContinuousDimension)realVariableDimension;
                                        value = _inputs[realVariableDimension].ToString("F5");
                                        if (!String.IsNullOrEmpty(dim.Unit))
                                        {
                                            value += " " + dim.Unit;
                                        }
                                    }
                                    else
                                    {
                                        IDiscreteDimension dim = (IDiscreteDimension)realVariableDimension;
                                        if (dim.DefaultSet != null)
                                        {
                                            value = dim.DefaultSet.GetMember(_inputs[realVariableDimension]).Caption;
                                        }
                                        else
                                        {
                                            value = "#" + _inputs[realVariableDimension].ToString("F0");
                                        }
                                    }

                                    lblText += String.Format("\r\nµ{1}(x)={0:F2} for x={2}.",
                                                             relation.IsMember(_inputs),
                                                             realVariableDimension.Name,
                                                             value
                                                             );
                                }
                                _label.Text = lblText;
                            }
                        }
                    }
                }
            }
        }