Esempio n. 1
0
        internal override IntervalSet GetFunction(Dictionary <IDimension, System.Decimal> inputs, IDimension variableInput)
        {
            if (variableInput == this._dimension)
            {
                return(_intervals);    //we will built the function for this dimension as a variable
            }
            else
            {
                if (variableInput is IContinuousDimension)
                {
                    IntervalSet result = new IntervalSet(variableInput);
                    result.AddInterval(new Interval(result, ((IContinuousDimension)variableInput).MinValue, ((IContinuousDimension)variableInput).MaxValue, this.IsMember(inputs[_dimension])));
                    return(result);
                }
                else
                {
                    IDiscreteDimension dim = (IDiscreteDimension)variableInput;

                    IntervalSet result = new IntervalSet(dim);

                    for (uint i = 1; i <= dim.MemberCount; i++)
                    {
                        result.AddInterval(new Interval(result, i, i, this.IsMember(inputs[_dimension])));
                    }

                    return(result);
                }
            }
        }
Esempio n. 2
0
        protected void buildFruitsSet()
        {
            product            = new DiscreteDimension("Product", "Product being offered");
            fruits             = new DiscreteSet(product, "Fruits");
            product.DefaultSet = fruits;

            apple        = new Fruit(product, "Apple");
            pear         = new Fruit(product, "Pear");
            tomato       = new Fruit(product, "Tomato");
            blueberry    = new Fruit(product, "Blueberry");
            blackberry   = new Fruit(product, "Blackberry");
            blackCurrant = new Fruit(product, "Black-currant");
            strawberry   = new Fruit(product, "Strawberry");
            lemon        = new Fruit(product, "Lemon");
            melon        = new Fruit(product, "Melon");
            broccoli     = new Fruit(product, "Broccoli");

            fruits.AddMember(apple, (double)trackBar1.Value / 100);
            fruits.AddMember(pear, (double)trackBar2.Value / 100);
            fruits.AddMember(lemon, (double)trackBar3.Value / 100);
            fruits.AddMember(melon, (double)trackBar4.Value / 100);
            fruits.AddMember(tomato, (double)trackBar5.Value / 100);
            fruits.AddMember(blackCurrant, (double)trackBar6.Value / 100);
            fruits.AddMember(blackberry, (double)trackBar7.Value / 100);
            fruits.AddMember(strawberry, (double)trackBar8.Value / 100);
            fruits.AddMember(blueberry, (double)trackBar9.Value / 100);
            fruits.AddMember(broccoli, (double)trackBar10.Value / 100);

            RelationImage imgFruits = new RelationImage(fruits);
            Bitmap        bmpFruits = new Bitmap(pictureBoxFruits.Width, pictureBoxFruits.Height);

            imgFruits.DrawImage(Graphics.FromImage(bmpFruits));
            pictureBoxFruits.Image = bmpFruits;
        }
Esempio n. 3
0
        public override string ToString()
        {
            string result = "";

            if (this.Coefficients.Length == 1 || (this.Coefficients.Length > 0 && Coefficients[0] != 0))
            {
                result = Coefficients[0].ToString("F5");
            }

            if (this.Coefficients.Length > 1 && Coefficients[1] != 0)
            {
                if (result != "" && !result.Substring(0, 1).Equals("-"))
                {
                    result = "+" + result;
                }
                result = String.Format("{0:F5}x", Coefficients[1]) + result;
            }


            for (UInt16 i = 2; i < this.Coefficients.Length; i++)
            {
                if (Coefficients[i] != 0)
                {
                    if (result != "" && !result.Substring(0, 1).Equals("-"))
                    {
                        result = "+" + result;
                    }
                    result = String.Format("{0:F5}x^{1:F0}", Coefficients[i], i) + result;
                }
            }

            if (LowerBound != UpperBound)
            {
                result += String.Format(" for xϵ{2}{0:F5},{1:F5}{3}", LowerBound, UpperBound, IsLeftOpen ? "(" : "<", IsRightOpen ? ")" : ">");
            }
            else
            {
                if (this.Parent.Dimension is IContinuousDimension)
                {
                    result += String.Format(" for x={0:F5}", LowerBound);
                }
                else
                {
                    IDiscreteDimension dim = (IDiscreteDimension)this.Parent.Dimension;
                    if (dim.DefaultSet != null)
                    {
                        result += String.Format(" for x is {0}", dim.DefaultSet.GetMember(LowerBound).Caption);
                    }
                    else
                    {
                        result += String.Format(" for x is #{0:F0}", LowerBound);
                    }
                }
            }


            return(result);
        }
Esempio n. 4
0
 public DiscreteSet(IDiscreteDimension dimension, string caption)
     : base(dimension, caption)
 {
     _intervals = new IntervalSet(dimension);
 }
Esempio n. 5
0
 public DiscreteSet(IDiscreteDimension dimension, IntervalSet intervals)
     : base(dimension)
 {
     _intervals = intervals;
 }
Esempio n. 6
0
 public stockFuzzy(IDiscreteDimension dimension, string caption)
     : base(dimension, caption)
 {
 }
        public void DrawImage(System.Drawing.Graphics graphics)
        {
            float width  = graphics.VisibleClipBounds.Width;
            float height = graphics.VisibleClipBounds.Height;

            Pen penGrid = new Pen(ColorGrid, 1);



            graphics.FillRectangle(BrushBackground, 0, 0, width, height);

            #region Horizontal Grid
            for (int i = 0; i < 5; i++)
            {
                float y = (height - MarginTop - MarginBottom) / 4 * i + MarginTop;
                graphics.DrawLine(penGrid, MarginLeft, y, width - MarginRight, y);

                string t = "";

                switch (4 - i)
                {
                case 0: t = "0"; break;

                case 1: t = "¼"; break;

                case 2: t = "½"; break;

                case 3: t = "¾"; break;

                case 4: t = "1"; break;
                }

                graphics.DrawString(t, FontGrid, new SolidBrush(ColorGrid), MarginLeft / 2, y - 4);
            }

            graphics.DrawString("µ", FontGrid, new SolidBrush(ColorGrid), MarginLeft / 8, MarginTop - 4);

            #endregion

            #region Vertical grid


            if (_variableDimension is IContinuousDimension)
            {
                IContinuousDimension dim = (IContinuousDimension)_variableDimension;

                if (dim.Unit != "")
                {
                    SizeF size = graphics.MeasureString(dim.Unit, FontGrid);
                    graphics.DrawString(dim.Unit, FontGrid, new SolidBrush(ColorGrid), width - MarginRight - size.Width, height - MarginBottom + (float)(size.Height * 1.25));
                }
            }


            decimal minValue;
            decimal maxValue;

            List <decimal> significantValues = _variableDimension.SignificantValues.ToList <decimal>();

            if (this.SupportOnly)
            {
                if (_variableDimension is IContinuousDimension)
                {
                    IContinuousDimension dim = (IContinuousDimension)_variableDimension;
                    decimal ls       = _relation.GetLowerSupportBound(inputsWithoutVariableInput);
                    decimal us       = _relation.GetUpperSupportBound(inputsWithoutVariableInput);
                    decimal distance = us - ls;

                    ls = ls - (distance * (decimal)(SupportSurroundings / 100));
                    us = us + (distance * (decimal)(SupportSurroundings / 100));
                    if (ls < dim.MinValue)
                    {
                        ls = dim.MinValue;
                    }
                    if (us > dim.MaxValue)
                    {
                        us = dim.MaxValue;
                    }

                    //If there is too little left, though, use at least two.
                    while (significantValues.Count > 2)
                    {
                        if (significantValues[1] < ls)
                        {
                            significantValues.RemoveAt(0);
                        }
                        else if (significantValues[significantValues.Count - 2] > us)
                        {
                            significantValues.RemoveAt(significantValues.Count - 1);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    int valuesLeft = significantValues.Count;
                    for (int i = significantValues.Count - 1; i >= 0; i--)
                    {
                        if (isMember(significantValues[i]) == 0)
                        {
                            significantValues.Remove(significantValues[i]);
                            valuesLeft--;
                            if (valuesLeft <= 3)
                            {
                                break;
                            }
                        }
                    }
                }
            }


            if (_variableDimension is IContinuousDimension)
            {
                minValue = significantValues[0];
                maxValue = significantValues[significantValues.Count - 1];
            }
            else
            {
                minValue = 0;
                maxValue = significantValues.Count - 1;
            }

            bool toggledMode = MaxValueCountInSingleRow < significantValues.Count;
            bool oddCount    = ((significantValues.Count % 2) == 1);



            uint c = 0;
            foreach (decimal gridValue in significantValues)
            {
                decimal value;
                c++;
                bool sub = (((c % 2) == 0) && oddCount) || (((c % 2) == 1) && !oddCount);

                string label;
                if (_variableDimension is IContinuousDimension)
                {
                    label = gridValue.ToString();
                    value = gridValue;
                }
                else
                {
                    IDiscreteDimension dim = (IDiscreteDimension)_variableDimension;
                    if (dim.DefaultSet != null)
                    {
                        label = dim.DefaultSet.GetMember(gridValue).Caption;
                    }
                    else
                    {
                        label = "#" + gridValue.ToString("F0");
                    }
                    value = c - 1;
                }

                float x = ((width - MarginLeft - MarginRight) / ((float)(maxValue - minValue))) * ((float)(value - minValue)) + MarginLeft;

                graphics.DrawLine(penGrid, x, MarginTop, x, height - MarginBottom);
                SizeF size = graphics.MeasureString(label, FontGrid);
                graphics.DrawString(label, FontGrid, new SolidBrush(ColorGrid), x - size.Width / 2, height - MarginBottom + size.Height / 4 + (sub ? size.Height : 0));


                #region Memberships for discrete set
                if (_variableDimension is IDiscreteDimension)
                {
                    graphics.DrawLine(PenLine, x, MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - isMember(gridValue)), x, height - MarginBottom);

                    if (FullySpecified && gridValue == SpecifiedValue.Value)
                    {
                        graphics.DrawLine(PenValue, x, MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - isMember(gridValue)), x, height - MarginBottom);
                        graphics.DrawLine(PenValue, MarginLeft, MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - isMember(gridValue)), x, MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - isMember(gridValue)));
                    }
                }
                #endregion
            }

            #endregion

            #region Line for continuous dimension

            if (_variableDimension is IContinuousDimension)
            {
                IntervalSet intervals = _relation.GetFunction(inputsWithoutVariableInput);

                foreach (Interval interval in intervals.Intervals)
                {
                    if
                    (
                        //(interval.LowerBound <= minValue && interval.UpperBound >= maxValue) ||
                        (interval.LowerBound >= minValue && interval.UpperBound <= maxValue) ||
                        (interval.LowerBound <= minValue && interval.UpperBound >= minValue) ||
                        (interval.LowerBound <= maxValue && interval.UpperBound >= maxValue)
                    )
                    {
                        decimal intervalMinValue = (interval.LowerBound < minValue ? minValue : interval.LowerBound);
                        decimal intervalMaxValue = (interval.UpperBound > maxValue ? maxValue : interval.UpperBound);

                        float intervalMinX = MarginLeft + ((width - MarginLeft - MarginRight) / (float)(maxValue - minValue)) * ((float)(intervalMinValue - minValue));
                        float intervalMaxX = MarginLeft + ((width - MarginLeft - MarginRight) / (float)(maxValue - minValue)) * ((float)(intervalMaxValue - minValue));

                        for (float x = intervalMinX; x <= intervalMaxX; x++)
                        {
                            decimal percentage;
                            if ((intervalMaxX - intervalMinX) == 0)
                            {
                                percentage = 0;
                            }
                            else
                            {
                                percentage = (decimal)((x - intervalMinX) / (intervalMaxX - intervalMinX));
                            }

                            decimal value = ((intervalMaxValue - intervalMinValue) * percentage) + intervalMinValue;

                            double membership = isMember(value);
                            //note that if y1 == y2 && x1 == x2, no point is plotted.
                            graphics.DrawLine(PenLine, x, MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - membership), x, height - MarginBottom);
                        }
                    }
                }

                if (FullySpecified)
                {
                    decimal percentage;
                    if (SpecifiedValue.Value - minValue == 0)
                    {
                        percentage = 0;
                    }
                    else
                    {
                        percentage = (SpecifiedValue.Value - minValue) / (maxValue - minValue);
                    }
                    float x = (width - MarginLeft - MarginRight) * (float)percentage + MarginLeft;
                    float y = MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - SpecifiedMembership.Value);

                    graphics.DrawLine(PenValue, x, y, x, height - MarginBottom);
                    graphics.DrawLine(PenValue, MarginLeft, y, x, y);
                    //graphics.DrawLine(PenValue, 0, 0, 100, 100);
                }
            }



            #endregion
        }
 public DiscreteMember(IDiscreteDimension dimension)
 {
     _dimension = dimension;
     _caption = this.GetType().Name;
     generateValue();
 }
 public DiscreteMember(IDiscreteDimension dimension, string caption)
 {
     _dimension = dimension;
     _caption = caption;
     generateValue();
 }
Esempio n. 10
0
 public DiscreteMember(IDiscreteDimension dimension)
 {
     _dimension = dimension;
     _caption   = this.GetType().Name;
     generateValue();
 }
Esempio n. 11
0
        /*
         * bool IConvertible.ToBoolean(IFormatProvider provider)
         * {
         *  return Convert.ToBoolean(this.ToDecimal(provider));
         * }
         *
         * byte IConvertible.ToByte(IFormatProvider provider)
         * {
         *  return Convert.ToByte(this.ToDecimal(provider));
         * }
         *
         * char IConvertible.ToChar(IFormatProvider provider)
         * {
         *  return Convert.ToChar(this.ToDecimal(provider));
         * }
         *
         * DateTime IConvertible.ToDateTime(IFormatProvider provider)
         * {
         *  return Convert.ToDateTime(this.ToDecimal(provider));
         * }
         *
         * decimal IConvertible.ToDecimal(IFormatProvider provider)
         * {
         *  return ToDecimal(provider);
         * }
         *
         * double IConvertible.ToDouble(IFormatProvider provider)
         * {
         *  return Convert.ToDouble(this.ToDecimal(provider));
         * }
         *
         * short IConvertible.ToInt16(IFormatProvider provider)
         * {
         *  return Convert.ToInt16(this.ToDecimal(provider));
         * }
         *
         * int IConvertible.ToInt32(IFormatProvider provider)
         * {
         *  return Convert.ToInt32(this.ToDecimal(provider));
         * }
         *
         * long IConvertible.ToInt64(IFormatProvider provider)
         * {
         *  return Convert.ToInt64(this.ToDecimal(provider));
         * }
         *
         * sbyte IConvertible.ToSByte(IFormatProvider provider)
         * {
         *  return Convert.ToSByte(this.ToDecimal(provider));
         * }
         *
         * float IConvertible.ToSingle(IFormatProvider provider)
         * {
         *  return Convert.ToSingle(this.ToDecimal(provider));
         * }
         *
         * string IConvertible.ToString(IFormatProvider provider)
         * {
         *  return Convert.ToString(this.ToDecimal(provider));
         * }
         *
         * object IConvertible.ToType(Type conversionType, IFormatProvider provider)
         * {
         *  return Convert.ChangeType(this.ToDecimal(provider), conversionType);
         * }
         *
         * ushort IConvertible.ToUInt16(IFormatProvider provider)
         * {
         *  return Convert.ToUInt16(this.ToDecimal(provider));
         * }
         *
         * uint IConvertible.ToUInt32(IFormatProvider provider)
         * {
         *  return Convert.ToUInt32(this.ToDecimal(provider));
         * }
         *
         * ulong IConvertible.ToUInt64(IFormatProvider provider)
         * {
         *  return Convert.ToUInt64(this.ToDecimal(provider));
         * }
         *
         * public TypeCode GetTypeCode()
         * {
         *  return TypeCode.Object;
         * }
         */



        #endregion

        #region public members
        public DiscreteMember(IDiscreteDimension dimension, string caption)
        {
            _dimension = dimension;
            _caption   = caption;
            generateValue();
        }
Esempio n. 12
0
        /// <summary>
        /// Method to be invoked recursively to build the whole tree
        /// </summary>
        /// <param name="nodeCollection"></param>
        /// <param name="pictureBox"></param>
        /// <param name="label"></param>
        protected void buildSubTree(FuzzyRelation subrelation, TreeNodeCollection nodeCollection, PictureBox pictureBox, Label label)
        {
            TreeNode tnThis;


            if (subrelation is FuzzySet)
            {
                FuzzySet fs = (FuzzySet)subrelation;
                tnThis = new TreeNode();
                if (!String.IsNullOrEmpty(fs.Caption))
                {
                    tnThis.Text = fs.Caption;
                }
                else
                {
                    tnThis.Text = "Fuzzy Set";
                }
                tnThis.ImageKey         = "fuzzySet";
                tnThis.SelectedImageKey = "fuzzySet";

                TreeNode tnDimType = new TreeNode("Type: " + (fs.Dimensions[0] is IContinuousDimension ? "Continuous" : "Discrete"));
                tnDimType.ImageKey         = "dimensionType";
                tnDimType.SelectedImageKey = "dimensionType";
                tnThis.Nodes.Add(tnDimType);
            }
            else
            {
                NodeFuzzyRelation nfr = (NodeFuzzyRelation)subrelation;
                tnThis                  = new TreeNode("Multidimensional Relation");
                tnThis.ImageKey         = "nodeFuzzyRelation";
                tnThis.SelectedImageKey = "nodeFuzzyRelation";

                TreeNode tnSubrelations = new TreeNode(nfr.Operator.Caption);
                tnSubrelations.ImageKey         = "subrelations";
                tnSubrelations.SelectedImageKey = "subrelations";
                tnSubrelations.ForeColor        = OperatorFontColor;
                tnThis.Nodes.Add(tnSubrelations);

                //Find all operands. Several commutative operands of same type from different nested levels will be displayed together
                List <FuzzyRelation> nestedSubrelations = new List <FuzzyRelation>();
                findNestedOperands(nfr, nestedSubrelations);

                foreach (FuzzyRelation nestedSubrelation in nestedSubrelations)
                {
                    buildSubTree(nestedSubrelation, tnSubrelations.Nodes, pictureBox, label);
                }
            }

            #region Dimensions

            TreeNode tnDimensions = new TreeNode("Dimension" + ((subrelation.Dimensions.Count() > 1) ? "s" : ""));
            tnDimensions.ImageKey         = "dimensions";
            tnDimensions.SelectedImageKey = "dimensions";
            tnThis.Nodes.Add(tnDimensions);

            foreach (IDimension dimension in subrelation.Dimensions)
            {
                bool  blnKnown      = _inputs.ContainsKey(dimension);
                bool  blnContinuous = dimension is IContinuousDimension;
                Color fontColor;

                string strDimCaption = String.IsNullOrEmpty(dimension.Name) ? "Dimension" : dimension.Name;

                if (blnKnown)
                {
                    if (blnContinuous)
                    {
                        strDimCaption += String.Format("={0:F5} {1}", _inputs[dimension], ((IContinuousDimension)dimension).Unit);
                    }
                    else
                    {
                        IDiscreteDimension discreteDim = (IDiscreteDimension)dimension;
                        if (discreteDim.DefaultSet != null)
                        {
                            strDimCaption += "=" + discreteDim.DefaultSet.GetMember(_inputs[dimension]).Caption;
                        }
                        else
                        {
                            strDimCaption += String.Format("=#{0:F0}", _inputs[dimension]);
                        }
                    }
                    fontColor = SpecifiedDimensionFontColor;
                }
                else
                {
                    fontColor = UnspecifiedDimensionFontColor;
                }

                if (dimension == _variableDimension)
                {
                    fontColor = VariableDimensionFontColor;
                }

                string imageKey = String.Format("dimension{0}{1}", blnContinuous ? "Continuous" : "Discrete", blnKnown ? "Known" : "Unknown");

                TreeNode tnDimension = new TreeNode(strDimCaption);
                tnDimension.ImageKey         = imageKey;
                tnDimension.SelectedImageKey = imageKey;
                tnDimension.ForeColor        = fontColor;
                addToolTip(tnDimension, dimension.Description);

                tnDimensions.Nodes.Add(tnDimension);
            }
            #endregion

            #region Function
            if (allInputDimensionsAvailable(subrelation))
            {
                IDimension realVariableDimension;
                if (subrelation.Dimensions.Count() == 1)
                {
                    realVariableDimension = subrelation.Dimensions[0];
                }
                else
                {
                    realVariableDimension = _variableDimension;
                }

                Dictionary <IDimension, decimal> copyInputs = new Dictionary <IDimension, decimal>(_inputs);

                foreach (KeyValuePair <IDimension, decimal> item in _inputs)
                {
                    if (!subrelation.Dimensions.Contains(item.Key))
                    {
                        copyInputs.Remove(item.Key);
                    }
                }

                if (copyInputs.ContainsKey(realVariableDimension))
                {
                    copyInputs.Remove(realVariableDimension);
                }

                if (subrelation.Dimensions.Count() > copyInputs.Count())
                {
                    IntervalSet intervals = subrelation.GetFunction(copyInputs);

                    string strIntervals = intervals.ToString();

                    string[] arrLines = strIntervals.Split(new char[] { '\n' });

                    TreeNode tnFunction = new TreeNode("Function");
                    tnFunction.ImageKey         = "function";
                    tnFunction.SelectedImageKey = "function";
                    foreach (string line in arrLines)
                    {
                        if (!String.IsNullOrWhiteSpace(line))
                        {
                            TreeNode tnLine = new TreeNode(line);
                            tnLine.ImageKey         = "spacer";
                            tnLine.SelectedImageKey = "spacer";
                            tnFunction.Nodes.Add(tnLine);
                        }
                    }

                    tnThis.Nodes.Add(tnFunction);
                }
            }

            #endregion

            tnThis.ForeColor = MainNodeFontColor;
            tnThis.Tag       = subrelation;
            nodeCollection.Add(tnThis);
        }
Esempio n. 13
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;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Method to be invoked recursively to build the whole tree
        /// </summary>
        /// <param name="nodeCollection"></param>
        /// <param name="pictureBox"></param>
        /// <param name="label"></param>
        protected void buildSubTree(FuzzyRelation subrelation, TreeNodeCollection nodeCollection, PictureBox pictureBox, Label label)
        {
            TreeNode tnThis;

            if (subrelation is FuzzySet)
            {
                FuzzySet fs = (FuzzySet)subrelation;
                tnThis = new TreeNode();
                if (!String.IsNullOrEmpty(fs.Caption))
                {
                    tnThis.Text = fs.Caption;
                }
                else
                {
                    tnThis.Text      = "Fuzzy Set";
                    tnThis.ForeColor = UnnamedNodeFontColor;
                }
                tnThis.ImageKey         = "fuzzySet";
                tnThis.SelectedImageKey = "fuzzySet";

                TreeNode tnDimType = new TreeNode("Type: " + (fs.Dimensions[0] is IContinuousDimension ? "Continuous" : "Discrete"));
                tnDimType.ImageKey         = "dimensionType";
                tnDimType.SelectedImageKey = "dimensionType";
                tnThis.Nodes.Add(tnDimType);
            }
            else
            {
                NodeFuzzyRelation nfr = (NodeFuzzyRelation)subrelation;
                tnThis                  = new TreeNode("Multidimensional Relation");
                tnThis.ForeColor        = UnnamedNodeFontColor;
                tnThis.ImageKey         = "nodeFuzzyRelation";
                tnThis.SelectedImageKey = "nodeFuzzyRelation";

                TreeNode tnSubrelations = new TreeNode(nfr.Operator.Caption);
                tnSubrelations.ImageKey         = "subrelations";
                tnSubrelations.SelectedImageKey = "subrelations";
                tnSubrelations.ForeColor        = OperatorFontColor;
                tnThis.Nodes.Add(tnSubrelations);

                //Find all operands. Several commutative operands of same type from different nested levels will be displayed together
                List <FuzzyRelation> nestedSubrelations = new List <FuzzyRelation>();
                findNestedOperands(nfr, nestedSubrelations);

                foreach (FuzzyRelation nestedSubrelation in nestedSubrelations)
                {
                    buildSubTree(nestedSubrelation, tnSubrelations.Nodes, pictureBox, label);
                }
            }

            #region Dimensions;

            TreeNode tnDimensions = new TreeNode("Dimension" + ((subrelation.Dimensions.Count() > 1) ? "s" : ""));
            tnDimensions.ImageKey         = "dimensions";
            tnDimensions.SelectedImageKey = "dimensions";
            tnThis.Nodes.Add(tnDimensions);

            foreach (IDimension dimension in subrelation.Dimensions)
            {
                bool  blnKnown      = _inputs.ContainsKey(dimension);
                bool  blnContinuous = dimension is IContinuousDimension;
                Color fontColor;

                string strDimCaption = String.IsNullOrEmpty(dimension.Name) ? "Dimension" : dimension.Name;

                if (blnKnown)
                {
                    if (blnContinuous)
                    {
                        strDimCaption += String.Format("={0:F5} {1}", _inputs[dimension], ((IContinuousDimension)dimension).Unit);
                    }
                    else
                    {
                        IDiscreteDimension discreteDim = (IDiscreteDimension)dimension;
                        if (discreteDim.DefaultSet != null)
                        {
                            strDimCaption += "=" + discreteDim.DefaultSet.GetMember(_inputs[dimension]);
                        }
                        else
                        {
                            strDimCaption += String.Format("=#{0:F0}", _inputs[dimension]);
                        }
                    }
                    fontColor = SpecifiedDimensionFontColor;
                }
                else
                {
                    fontColor = UnspecifiedDimensionFontColor;
                }

                if (dimension == _variableDimension)
                {
                    fontColor = VariableDimensionFontColor;
                }

                string imageKey = String.Format("dimension{0}{1}", blnContinuous ? "Continuous" : "Discrete", blnKnown ? "Known" : "Unknown");

                TreeNode tnDimension = new TreeNode(strDimCaption);
                tnDimension.ImageKey         = imageKey;
                tnDimension.SelectedImageKey = imageKey;
                tnDimension.ForeColor        = fontColor;
                addToolTip(tnDimension, dimension.Description);

                tnDimensions.Nodes.Add(tnDimension);
            }
            #endregion

            #region Function

            #endregion
            nodeCollection.Add(tnThis);
        }
Esempio n. 15
0
 public DiscreteSet(IDiscreteDimension dimension, IntervalSet intervals)
     : base(dimension)
 {
     _intervals = intervals;
 }
Esempio n. 16
0
 public DiscreteSet(IDiscreteDimension dimension, string caption)
     : base(dimension, caption)
 {
     _intervals = new IntervalSet(dimension);
 }
Esempio n. 17
0
 /// <summary>
 /// Represents member of fuzzy set Fruits
 /// </summary>
 /// <param name="dimension">Dimension of the set. In this case, it is "product".</param>
 /// <param name="caption">Short description of the member</param>
 public Fruit(IDiscreteDimension dimension, string caption) : base(dimension, caption)
 {
 }