Beispiel #1
0
        private void Button_Calc(object sender, RoutedEventArgs e)
        {
            string tag        = (sender as Button).Tag.ToString().ToLower().Trim();
            bool   isCalcMode = (bool)checkboxCalculator.IsChecked;

            if (this._fuzzySets.Count < 1)
            {
                this.ShowPopup("It won't work!", "To perform the operation, it is required to add at least one fuzzy set.");
                return;
            }
            else if (this._fuzzySets.Count > 128)
            {
                this.ShowPopup("Tranquilo amigo!", "The program cannot operate with such a large number of sets.");
                return;
            }

#if DEBUG
            System.Diagnostics.Debug.WriteLine("Calc tag is: " + tag);
#endif
            switch (tag)
            {
            case "complement":
                this.ShowPopup("Calculating", "Computing complements of fuzzy sets.");

                FuzzySet        complement;
                List <FuzzySet> tempSets = new List <FuzzySet> {
                };

                for (int i = 0; i < this._fuzzySets.Count; i++)
                {
#if DEBUG
                    System.Diagnostics.Debug.WriteLine("Complemented FuzzySet #" + i + ", Type: " + this._fuzzySets[i].Type.ToString());
#endif

                    complement = this._fuzzySets[i].Complement();
                    this.DrawSet("Complement #" + (i + 1), complement.GetPlot());

                    if (isCalcMode)
                    {
                        //Delete the currently complemented fuzzy set in favor of the newly created one
                        this._fuzzySets.RemoveAt(i);
                        this.SeriesCollection.RemoveAt(i);
                    }

                    tempSets.Add(complement);
                }

                foreach (FuzzySet set in tempSets)
                {
                    this._fuzzySets.Add(set);
                }

                break;

            case "sum":

                if (this._fuzzySets.Count < 2)
                {
                    this.ShowPopup("It won't work!", "To perform the summation operation, more than one fuzzy set must be specified.", 5000);
                    return;
                }
                FuzzySet summary = this._fuzzySets[0];

                if (isCalcMode)
                {
                    //Delete the currently complemented fuzzy set in favor of the newly created one
                    this._fuzzySets.RemoveAt(0);
                    this.SeriesCollection.RemoveAt(0);
                }

                for (int i = 1; i < this._fuzzySets.Count; i++)
                {
                    summary = summary.Sum(this._fuzzySets[i]);
                    if (isCalcMode)
                    {
                        //Delete the currently complemented fuzzy set in favor of the newly created one
                        this._fuzzySets.RemoveAt(i);
                        this.SeriesCollection.RemoveAt(i);
                    }
                }

                this.ShowPopup("Processing...", "The sum of the fuzzy sets is being calculated.", 1000);



                this.DrawSet("Summary #" + (this._fuzzySets.Count + 2), summary.GetPlot());
                this._fuzzySets.Add(summary);
                break;

            default:
                break;
            }
        }