Exemple #1
0
        private void ButtonDivide_Click(object sender, RoutedEventArgs e)
        {
            plotView.Model.Series.Clear();
            FuzzyNumber result = new FuzzyNumber();
            int         scale;

            ParseFNTextBoxes();
            TryParse(textBoxDiscretization.Text, out var disPara);
            FuzzyNumber fuzzyNumberA = new FuzzyNumber(a1, a2, a3, a4, disPara);
            FuzzyNumber fuzzyNumberB = new FuzzyNumber(b1, b2, b3, b4, disPara);

            result = FNAlgebra.divideAB(fuzzyNumberA, fuzzyNumberB);
            if (fuzzyNumberA.detectFailureChange(result))
            {
                textBoxOutput.Text = "You can't divide by 0";
            }
            else
            {
                resultToContinue   = result;
                textBoxOutput.Text = "{ " + result + "}";
                scale = result.findMaxValueOfFuzzyNumber(fuzzyNumberA, fuzzyNumberB, result);
                PlotModelDefine.ScalePlotOFN(plotView.Model, scale);

                plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumber(fuzzyNumberA, disPara, "Number A"));
                plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumber(fuzzyNumberB, disPara, "Number B"));
                plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumber(result, disPara, "Result"));
                plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumberOrder(fuzzyNumberA, disPara, "Number A"));
                plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumberOrder(fuzzyNumberB, disPara, "Number B"));
                plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumberOrder(result, disPara, "Result"));
                plotView.InvalidatePlot();
            }
        }
Exemple #2
0
        public void drawFuzzyNumber(Canvas canvas, FuzzyNumber fuzzyNumber, Color colorBrush)
        {
            var upLine         = new Line();
            var horizontalLine = new Line();
            var downLine       = new Line();

            upLine.Stroke                  = new SolidColorBrush(colorBrush);
            upLine.StrokeThickness         = 3;
            horizontalLine.Stroke          = new SolidColorBrush(colorBrush);
            horizontalLine.StrokeThickness = 3;
            downLine.Stroke                = new SolidColorBrush(colorBrush);
            downLine.StrokeThickness       = 3;


            upLine.X1 = converterX(fuzzyNumber.Pos1, fuzzyNumber);
            upLine.Y1 = converterY(0);
            upLine.X2 = converterX(fuzzyNumber.Pos2, fuzzyNumber);
            upLine.Y2 = converterY(VALUE_OF_ONE);

            horizontalLine.X1 = converterX(fuzzyNumber.Pos2, fuzzyNumber);
            horizontalLine.Y1 = converterY(VALUE_OF_ONE);
            horizontalLine.X2 = converterX(fuzzyNumber.Pos3, fuzzyNumber);
            horizontalLine.Y2 = converterY(VALUE_OF_ONE);

            downLine.X1 = converterX(fuzzyNumber.Pos3, fuzzyNumber);
            downLine.Y1 = converterY(VALUE_OF_ONE);
            downLine.X2 = converterX(fuzzyNumber.Pos4, fuzzyNumber);
            downLine.Y2 = converterY(0);


            canvas.Children.Add(upLine);
            canvas.Children.Add(horizontalLine);
            canvas.Children.Add(downLine);
        }
Exemple #3
0
        public static FuzzyNumber subtractAminusB(FuzzyNumber fuzzyNumberA, FuzzyNumber fuzzyNumberB)
        {
            FuzzyNumber fuzzy = new FuzzyNumber();
            int         i     = 0;

            fuzzy.Pos1 = fuzzyNumberA.Pos1 - fuzzyNumberB.Pos1;
            fuzzy.Pos2 = fuzzyNumberA.Pos2 - fuzzyNumberB.Pos2;
            fuzzy.Pos3 = fuzzyNumberA.Pos3 - fuzzyNumberB.Pos3;
            fuzzy.Pos4 = fuzzyNumberA.Pos4 - fuzzyNumberB.Pos4;

            foreach (double x in fuzzyNumberA.Up)
            {
                var upHelper = x - fuzzyNumberB.Up[i];
                fuzzy.Up.Add(upHelper);
                i++;
            }
            i = 0;
            foreach (double x in fuzzyNumberA.Down)
            {
                var downHelper = x - fuzzyNumberB.Down[i];
                fuzzy.Down.Add(downHelper);
                i++;
            }

            return(fuzzy);
        }
Exemple #4
0
        private void ButtonMultiply_Click(object sender, RoutedEventArgs e)
        {
            plotView.Model.Series.Clear();
            FuzzyNumber result;

            ParseFNTextBoxes();
            int disPara;

            TryParse(textBoxDiscretization.Text, out disPara);
            FuzzyNumber fuzzyNumberA = new FuzzyNumber(a1, a2, a3, a4, disPara);
            FuzzyNumber fuzzyNumberB = new FuzzyNumber(b1, b2, b3, b4, disPara);

            result             = FNAlgebra.multiplyAB(fuzzyNumberA, fuzzyNumberB);
            resultToContinue   = result;
            textBoxOutput.Text = "{ " + result + "}";
            var scale = result.findMaxValueOfFuzzyNumber(fuzzyNumberA, fuzzyNumberB, result);

            PlotModelDefine.ScalePlotOFN(plotView.Model, scale);

            plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumber(fuzzyNumberA, disPara, "Number A"));
            plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumber(fuzzyNumberB, disPara, "Number B"));
            plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumber(result, disPara, "Result"));
            plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumberOrder(fuzzyNumberA, disPara, "Number A"));
            plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumberOrder(fuzzyNumberB, disPara, "Number B"));
            plotView.Model.Series.Add(PlotModelDefine.drawFuzzyNumberOrder(result, disPara, "Result"));
            plotView.InvalidatePlot();
        }
Exemple #5
0
        public static FuzzyNumber multiplyAB(FuzzyNumber fuzzyNumberA, FuzzyNumber fuzzyNumberB)
        {
            FuzzyNumber fuzzy = new FuzzyNumber();
            int         i     = 0;

            fuzzy.Pos1 = fuzzyNumberA.Pos1 * fuzzyNumberB.Pos1;
            fuzzy.Pos2 = fuzzyNumberA.Pos2 * fuzzyNumberB.Pos2;
            fuzzy.Pos3 = fuzzyNumberA.Pos3 * fuzzyNumberB.Pos3;
            fuzzy.Pos4 = fuzzyNumberA.Pos4 * fuzzyNumberB.Pos4;
            foreach (double x in fuzzyNumberA.Up)
            {
                var upHelper = x * fuzzyNumberB.Up[i];
                fuzzy.Up.Add(upHelper);
                i++;
            }
            i = 0;
            foreach (double x in fuzzyNumberA.Down)
            {
                var downHelper = x * fuzzyNumberB.Down[i];
                fuzzy.Down.Add(downHelper);
                i++;
            }

            return(fuzzy);
        }
Exemple #6
0
        public static FuzzyNumber addAplusB(FuzzyNumber fuzzyNumberA, FuzzyNumber fuzzyNumberB)
        {
            FuzzyNumber fuzzy = new FuzzyNumber();
            int         i     = 0;

            fuzzy.Pos1 = fuzzyNumberA.Pos1 + fuzzyNumberB.Pos1;
            fuzzy.Pos2 = fuzzyNumberA.Pos2 + fuzzyNumberB.Pos2;
            fuzzy.Pos3 = fuzzyNumberA.Pos3 + fuzzyNumberB.Pos3;
            fuzzy.Pos4 = fuzzyNumberA.Pos4 + fuzzyNumberB.Pos4;

            //adding UP part - //works
            foreach (double x in fuzzyNumberA.Up)
            {
                var upHelper = x + fuzzyNumberB.Up[i];
                fuzzy.Up.Add(upHelper);
                i++;
            }
            //adding DOWN part
            i = 0;
            foreach (double x in fuzzyNumberA.Down)
            {
                var downHelper = x + fuzzyNumberB.Down[i];
                fuzzy.Down.Add(downHelper);
                i++;
            }

            return(fuzzy);
        }
Exemple #7
0
        //For now it may throw a null exception
        private static FuzzyNumber divideABpriv(FuzzyNumber fuzzyNumberA, FuzzyNumber fuzzyNumberB)
        {
            FuzzyNumber fuzzy = new FuzzyNumber();

            if (checkIfNotZero(fuzzyNumberA) && checkIfNotZero(fuzzyNumberB))
            {
                int i = 0;
                fuzzy.Pos1 = fuzzyNumberA.Pos1 / fuzzyNumberB.Pos1;
                fuzzy.Pos2 = fuzzyNumberA.Pos2 / fuzzyNumberB.Pos2;
                fuzzy.Pos3 = fuzzyNumberA.Pos3 / fuzzyNumberB.Pos3;
                fuzzy.Pos4 = fuzzyNumberA.Pos4 / fuzzyNumberB.Pos4;

                foreach (double x in fuzzyNumberA.Up)
                {
                    var upHelper = x / fuzzyNumberB.Up[i];
                    fuzzy.Up.Add(upHelper);
                    i++;
                }
                i = 0;
                foreach (double x in fuzzyNumberA.Down)
                {
                    var downHelper = x / fuzzyNumberB.Down[i];
                    fuzzy.Down.Add(downHelper);
                    i++;
                }

                return(fuzzy);
            }
            else
            {
                return(null);
            }
        }
Exemple #8
0
        public static LineSeries drawFuzzyNumberOrder(FuzzyNumber fuzzyNumber, int discreticaztionParameter, string title)
        {
            if (Math.Abs(discreticaztionParameter - FLOOR) < 0.000001 || discreticaztionParameter.Equals(null))
            {
                discreticaztionParameter = 10;
            }

            double jumpUp    = CEILING / discreticaztionParameter;
            double constJump = jumpUp;
            double jumpDown  = CEILING - CEILING / discreticaztionParameter;

            LineSeries lineSeries = new LineSeries();

            lineSeries.StrokeThickness = 5;

            lineSeries.Points.Add(new DataPoint(fuzzyNumber.Pos1, FLOOR));


            lineSeries.Points.Add(new DataPoint(fuzzyNumber.Pos1, FLOOR));
            foreach (double upper in fuzzyNumber.Up)
            {
                lineSeries.Points.Add(new DataPoint(upper, jumpUp));
                jumpUp += constJump;
            }

            lineSeries.Title = title;
            return(lineSeries);
        }
Exemple #9
0
        public static LineSeries drawFuzzyNumber(FuzzyNumber fuzzyNumber, string title)
        {
            LineSeries lineSeries = new LineSeries();

            lineSeries.Points.Add(new DataPoint(fuzzyNumber.Pos1, FLOOR));
            lineSeries.Points.Add(new DataPoint(fuzzyNumber.Pos2, CEILING));
            lineSeries.Points.Add(new DataPoint(fuzzyNumber.Pos3, CEILING));
            lineSeries.Points.Add(new DataPoint(fuzzyNumber.Pos4, FLOOR));
            lineSeries.Title = title;
            return(lineSeries);
        }
Exemple #10
0
        public static FuzzyNumber divideAB(FuzzyNumber fuzzyNumberA, FuzzyNumber fuzzyNumberB)
        {
            FuzzyNumber fuzzy = new FuzzyNumber();

            try
            {
                fuzzy = divideABpriv(fuzzyNumberA, fuzzyNumberB);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Nie dziel przez 0");
                e.StackTrace.ToString();
            }

            return(fuzzy);
        }
Exemple #11
0
        // returns value referenced to point [0,0] (X), scales canvas
        private double converterX(double XnumberToConvert, FuzzyNumber fuzzyNumber)
        {
            double tempXnumberToConvert = 0;
            double maxFromFuzzyNumber   = Math.Abs(FuzzyNumber.findMaxValueOfFuzzyNumber(fuzzyNumber));
            double scale = 0;

            if (scaleClass == 0)
            {
                scale      = 960 / maxFromFuzzyNumber / 2;
                scaleClass = scale;
            }
            else
            {
                scale = scaleClass;
            }

            //960 = 0 on X
            tempXnumberToConvert = XnumberToConvert * scale + 960;


            return(tempXnumberToConvert);
        }
Exemple #12
0
 private static bool checkIfNotZero(FuzzyNumber fuzzyNumber)
 {
     if (Math.Abs(fuzzyNumber.Pos1) < 0.000001)
     {
         return(false);
     }
     else if (Math.Abs(fuzzyNumber.Pos2) < 0.000001)
     {
         return(false);
     }
     else if (Math.Abs(fuzzyNumber.Pos3) < 0.000001)
     {
         return(false);
     }
     else if (Math.Abs(fuzzyNumber.Pos4) < 0.000001)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemple #13
0
        private void ButtonMultiplyPolynomials_Click(object sender, RoutedEventArgs e)
        {
            ParsePolynomialTextBoxes();
            PolynomialAlgebra polynomialAlgebra = new PolynomialAlgebra();
            Polynomial        polynomialResult  = new Polynomial();
            PolynomialAlgebra algebra           = new PolynomialAlgebra();
            Polynomial        polynomialA       = new Polynomial(freeValueA, valueXA, valueX2A, valueX3A, valueX4A, valueX5A,
                                                                 valueX6A, valueX7A, valueX8A, valueX9A, valueX10A);
            Polynomial polynomialB = new Polynomial(freeValueB, valueXB, valueX2B, valueX3B, valueX4B, valueX5B,
                                                    valueX6B, valueX7B, valueX8B, valueX9B, valueX10B);

            polynomialResult = PolynomialAlgebra.multiplyPolynomialAB(polynomialA, polynomialB);
            int discretizationValue;

            int.TryParse(textBoxDiscretization.Text.ToString(), out discretizationValue);

            if (comboBoxPartOfPolynomial.SelectedItem != null)
            {
                if (comboBoxPartOfPolynomial.SelectedItem.ToString().Equals("Up"))
                {
                    for (int i = 0; i < plotView.Model.Series.Count; i++)
                    {
                        if (plotView.Model.Series.ElementAt(i).Title.Equals("Up(Fa+Fb)"))
                        {
                            plotView.Model.Series.RemoveAt(i);
                        }

                        if (plotView.Model.Series.ElementAt(i).Title.Equals("Up(Fa)"))
                        {
                            plotView.Model.Series.RemoveAt(i);
                        }

                        if (plotView.Model.Series.ElementAt(i).Title.Equals("Up(Fb)"))
                        {
                            plotView.Model.Series.RemoveAt(i);
                        }
                    }

                    upValuesOfPolynomials.Clear();
                    textBoxResultUpPolynomail.Text = polynomialResult.ToString();
                    plotView.Model.Series.Add(PlotModelDefine.DrawFunction(polynomialResult, "Up(Fa+Fb)",
                                                                           discretizationValue));
                    plotView.Model.Series.Add(PlotModelDefine.DrawFunction(polynomialA, "Up(Fa)", discretizationValue));
                    plotView.Model.Series.Add(PlotModelDefine.DrawFunction(polynomialB, "Up(Fb)", discretizationValue));
                    countUpForAandB(algebra, polynomialA, polynomialB, polynomialResult);
                    upValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialA, 1));
                    upValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialB, 1));
                    upValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialResult, 1));
                    upValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialA, 0));
                    upValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialB, 0));
                    upValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialResult, 0));
                    upValuesOfPolynomials.Sort();
                }
                else
                {
                    for (int i = 0; i < plotView.Model.Series.Count; i++)
                    {
                        if (plotView.Model.Series.ElementAt(i).Title.Equals("Down(Ga+Gb)"))
                        {
                            plotView.Model.Series.RemoveAt(i);
                        }

                        if (plotView.Model.Series.ElementAt(i).Title.Equals("Down(Ga)"))
                        {
                            plotView.Model.Series.RemoveAt(i);
                        }

                        if (plotView.Model.Series.ElementAt(i).Title.Equals("Down(Gb)"))
                        {
                            plotView.Model.Series.RemoveAt(i);
                        }
                    }

                    downValuesOfPolynomials.Clear();
                    textBoxResultDownPolynomail.Text = polynomialResult.ToString();
                    plotView.Model.Series.Add(PlotModelDefine.DrawFunction(polynomialResult, "Down(Ga+Gb)",
                                                                           discretizationValue));
                    plotView.Model.Series.Add(
                        PlotModelDefine.DrawFunction(polynomialA, "Down(Ga)", discretizationValue));
                    plotView.Model.Series.Add(
                        PlotModelDefine.DrawFunction(polynomialB, "Down(Gb)", discretizationValue));
                    countDownforAandB(algebra, polynomialA, polynomialB, polynomialResult);

                    downValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialA, 1));
                    downValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialB, 1));
                    downValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialResult, 1));
                    downValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialA, 0));
                    downValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialB, 0));
                    downValuesOfPolynomials.Add(polynomialAlgebra.countValueFromFunction(polynomialResult, 0));
                    downValuesOfPolynomials.Sort();
                }
            }

            if (upValuesOfPolynomials.Count > 0 && downValuesOfPolynomials.Count > 0)
            {
                if (upValuesOfPolynomials[5] >= downValuesOfPolynomials[5])
                {
                    plotView.Model.Axes.ElementAt(0).AbsoluteMaximum = upValuesOfPolynomials[5] + 5;
                    plotView.Model.Axes.ElementAt(0).Maximum         = upValuesOfPolynomials[5] + 5;
                }
                else
                {
                    plotView.Model.Axes.ElementAt(0).AbsoluteMaximum = downValuesOfPolynomials[5] + 5;
                    plotView.Model.Axes.ElementAt(0).Maximum         = downValuesOfPolynomials[5] + 5;
                }


                if (upValuesOfPolynomials[0] <= downValuesOfPolynomials[0])
                {
                    plotView.Model.Axes.ElementAt(0).AbsoluteMinimum = upValuesOfPolynomials[0] - 5;
                    plotView.Model.Axes.ElementAt(0).Minimum         = upValuesOfPolynomials[0] - 5;
                }
                else
                {
                    plotView.Model.Axes.ElementAt(0).AbsoluteMinimum = downValuesOfPolynomials[0] - 5;
                    plotView.Model.Axes.ElementAt(0).Minimum         = downValuesOfPolynomials[0] - 5;
                }
            }
            else
            {
                if (upValuesOfPolynomials.Count > 0)
                {
                    plotView.Model.Axes.ElementAt(0).AbsoluteMaximum = upValuesOfPolynomials[5] + 5;
                    plotView.Model.Axes.ElementAt(0).Maximum         = upValuesOfPolynomials[5] + 5;
                    plotView.Model.Axes.ElementAt(0).AbsoluteMinimum = upValuesOfPolynomials[0] - 5;
                    plotView.Model.Axes.ElementAt(0).Minimum         = upValuesOfPolynomials[0] - 5;
                }
                else if (downValuesOfPolynomials.Count > 0)
                {
                    plotView.Model.Axes.ElementAt(0).AbsoluteMaximum = downValuesOfPolynomials[5] + 5;
                    plotView.Model.Axes.ElementAt(0).Maximum         = downValuesOfPolynomials[5] + 5;
                    plotView.Model.Axes.ElementAt(0).AbsoluteMinimum = downValuesOfPolynomials[0] - 5;
                    plotView.Model.Axes.ElementAt(0).Minimum         = downValuesOfPolynomials[0] - 5;
                }
            }

            FuzzyNumber res1 = new FuzzyNumber(w1, w2, w3, w4, discretizationValue);

            resultToContinue = res1;


            representResult();
            plotView.InvalidatePlot(true);
        }