Пример #1
0
        static void Primjer12()
        {
            IDomain d = Domain.IntRange(0, 11); // {0,1,...,10}
            //Debug1.Print(d, "Elementi domene d1:");

            IFuzzySet set1 = new MutableFuzzySet(d)
                             .Set(DomainElement.Of(0), 1.0)
                             .Set(DomainElement.Of(1), 0.8)
                             .Set(DomainElement.Of(2), 0.6)
                             .Set(DomainElement.Of(3), 0.4)
                             .Set(DomainElement.Of(4), 0.2);

            Debug1.Print(set1, "Set1:");

            IDomain   d2   = Domain.IntRange(-5, 6); // {-5,-4,...,4,5}
            IFuzzySet set2 = new CalculatedFuzzySet(
                d2,
                StandardFuzzySets.LambdaFunction(
                    d2.IndexOfElement(DomainElement.Of(-4)),
                    d2.IndexOfElement(DomainElement.Of(0)),
                    d2.IndexOfElement(DomainElement.Of(4))
                    )
                );

            Debug1.Print(set2, "Set2:");
        }
Пример #2
0
        static void Primjer13()
        {
            IDomain   d    = Domain.IntRange(0, 11);
            IFuzzySet set1 = new MutableFuzzySet(d)
                             .Set(DomainElement.Of(0), 1.0)
                             .Set(DomainElement.Of(1), 0.8)
                             .Set(DomainElement.Of(2), 0.6)
                             .Set(DomainElement.Of(3), 0.4)
                             .Set(DomainElement.Of(4), 0.2);

            Debug1.Print(set1, "Set1:");

            IFuzzySet notSet1 = Operations.Operations.UnaryOperation(
                set1, Operations.Operations.ZadehNot());

            Debug1.Print(notSet1, "notSet1:");



            IFuzzySet union = Operations.Operations.BinaryOperation(
                set1, notSet1, Operations.Operations.ZadehOr());

            Debug1.Print(union, "Set1 union notSet1:");

            IFuzzySet hinters = Operations.Operations.BinaryOperation(
                set1, notSet1, Operations.Operations.HamacherTNorm(1.0));

            Debug1.Print(hinters, "Set1 intersection with notSet1 using parameterised Hamacher T norm with parameter 1.0:");

            IFuzzySet presjek = Operations.Operations.BinaryOperation(set1, notSet1, Operations.Operations.ZadehAnd());

            Debug1.Print(presjek, "Set1 presjek notSet1:");
        }
Пример #3
0
        public static void Primjer23()
        {
            IDomain   u = Domain.IntRange(1, 5); // {1,2,3,4}
            IFuzzySet r = new MutableFuzzySet(Domain.Combine(u, u))
                          .Set(DomainElement.Of(1, 1), 1)
                          .Set(DomainElement.Of(2, 2), 1)
                          .Set(DomainElement.Of(3, 3), 1)
                          .Set(DomainElement.Of(4, 4), 1)
                          .Set(DomainElement.Of(1, 2), 0.3)
                          .Set(DomainElement.Of(2, 1), 0.3)
                          .Set(DomainElement.Of(2, 3), 0.5)
                          .Set(DomainElement.Of(3, 2), 0.5)
                          .Set(DomainElement.Of(3, 4), 0.2)
                          .Set(DomainElement.Of(4, 3), 0.2);

            IFuzzySet r2 = r;

            Console.WriteLine("Početna relacija je neizrazita relacija ekvivalencije? " + Relations.Relations.IsFuzzyEquivalence(r2));
            Console.WriteLine();

            for (int i = 1; i <= 3; i++)
            {
                r2 = Relations.Relations.CompositionOfBinaryRelations(r2, r, Operations.Operations.ZadehAnd(), Operations.Operations.ZadehOr());
                Console.WriteLine("Broj odrađenih kompozicija: " + i + ". Relacija je:");
                foreach (DomainElement e in r2.GetDomain())
                {
                    Console.WriteLine("mu(" + e + ")=" + r2.GetValueAt(e));
                }
                Console.WriteLine("Ova relacija je neizrazita relacija ekvivalencije? " + Relations.Relations.IsFuzzyEquivalence(r2));
                Console.WriteLine();
            }
        }
Пример #4
0
        public static IFuzzySet CompositionOfBinaryRelations(IFuzzySet relation1, IFuzzySet relation2, IBinaryFunction tNorm, IBinaryFunction sNorm)    //zadatak ne specificira koristi li se max-min kompozicija
        {                                                                                                                                               //stoga je konfigurabilno
            MutableFuzzySet compositeRelation = new MutableFuzzySet(Domain.Combine(relation1.GetDomain().GetComponent(0), relation2.GetDomain().GetComponent(1)));

            if (relation1 == relation2)             //jer ugnjezdjeni foreach nad istom 'relation' instancom stvara probleme
            {
                relation2 = DeepCopy(relation1);
            }

            foreach (DomainElement element1 in compositeRelation.GetDomain())
            {
                int    x        = element1.GetComponentValue(0);
                int    z        = element1.GetComponentValue(1);
                double funccomp = compositeRelation.GetValueAt(DomainElement.Of(x, z));
                double Max      = 0;

                foreach (DomainElement element_a in relation1.GetDomain())          //funca
                {
                    foreach (DomainElement element_b in relation2.GetDomain())      //funcb
                    {
                        if (element_a.GetComponentValue(1) == element_b.GetComponentValue(0))
                        {
                            int y = element_a.GetComponentValue(1);                 //y
                            Max = sNorm.ValueAt(tNorm.ValueAt(relation1.GetValueAt(DomainElement.Of(x, y)), relation2.GetValueAt(DomainElement.Of(y, z))), Max);
                        }
                    }
                }

                compositeRelation.Set(DomainElement.Of(x, z), Max);
            }

            return(compositeRelation);
        }
Пример #5
0
        static void Main(string[] args)
        {
            IDomain u1 = Domain.IntRange(1, 5);  // {1,2,3,4}
            IDomain u2 = Domain.IntRange(1, 4);  // {1,2,3}
            IDomain u3 = Domain.IntRange(1, 5);  // {1,2,3,4}

            IFuzzySet r1 = new MutableFuzzySet(Domain.Combine(u1, u2))
                           .Set(DomainElement.Of(1, 1), 0.3)
                           .Set(DomainElement.Of(1, 2), 1)
                           .Set(DomainElement.Of(3, 3), 0.5)
                           .Set(DomainElement.Of(4, 3), 0.5);

            IFuzzySet r2 = new MutableFuzzySet(Domain.Combine(u2, u3))
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 1), 0.5)
                           .Set(DomainElement.Of(2, 2), 0.7)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(3, 4), 0.4);

            IFuzzySet r1r2 = Relations.CompositionOfBinaryRelations(r1, r2);

            Console.WriteLine(r1r2);

            Console.ReadKey();
        }
Пример #6
0
        private static void PrintExample5()
        {
            Console.WriteLine("EXAMPLE 5");
            IDomain   u1 = IDomain.IntRange(1, 5); // {1,2,3,4}
            IDomain   u2 = IDomain.IntRange(1, 4); // {1,2,3}
            IDomain   u3 = IDomain.IntRange(1, 5); // {1,2,3,4}
            IFuzzySet r1 = new MutableFuzzySet(IDomain.Combine(u1, u2))
                           .Set(DomainElement.Of(1, 1), 0.3)
                           .Set(DomainElement.Of(1, 2), 1)
                           .Set(DomainElement.Of(3, 3), 0.5)
                           .Set(DomainElement.Of(4, 3), 0.5);
            IFuzzySet r2 = new MutableFuzzySet(IDomain.Combine(u2, u3))
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 1), 0.5)
                           .Set(DomainElement.Of(2, 2), 0.7)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(3, 4), 0.4);
            IFuzzySet r1r2 = Relations.CompositionOfBinaryRelations(r1, r2) !;

            foreach (var element in r1r2.GetDomain())
            {
                Console.WriteLine($"mu({element}) = {r1r2.GetValueAt(element)}");
            }
            Console.WriteLine("---------------------------------------");
            Console.WriteLine();
        }
Пример #7
0
        private static void Main()
        {
            var d = Domain.IntRange(0, 11); // {0,1,...,10}

            IFuzzySet set1 = new MutableFuzzySet(d)
                             .Set(DomainElement.Of(0), 1.0)
                             .Set(DomainElement.Of(1), 0.8)
                             .Set(DomainElement.Of(2), 0.6)
                             .Set(DomainElement.Of(3), 0.4)
                             .Set(DomainElement.Of(4), 0.2);

            Console.WriteLine("Set 1:");
            Console.WriteLine(set1);
            Console.WriteLine();

            var       d2   = Domain.IntRange(-5, 6); // {-5,-4,...,4,5}
            IFuzzySet set2 = new CalculatedFuzzySet(
                d2,
                StandardFuzzySets.LambdaFunction(
                    d2.IndexOfElement(DomainElement.Of(-4)),
                    d2.IndexOfElement(DomainElement.Of(0)),
                    d2.IndexOfElement(DomainElement.Of(4))
                    )
                );

            Console.WriteLine("Set 2:");
            Console.WriteLine(set2);
            Console.WriteLine();

            Console.ReadKey();
        }
Пример #8
0
        public static IFuzzySet CompositionOfBinaryRelations(IFuzzySet r1, IFuzzySet r2)
        {
            IDomain xDomain = r1.GetDomain()[0];
            IDomain yDomain = r1.GetDomain()[1];
            IDomain zDomain = r2.GetDomain()[1];

            var result = new MutableFuzzySet(Domain.Combine(xDomain, zDomain));
            var or     = Operations.ZadehOr();
            var and    = Operations.ZadehAnd();

            foreach (var x in xDomain)
            {
                foreach (var z in zDomain)
                {
                    var value = 0.0;

                    foreach (var y in yDomain)
                    {
                        var value1 = r1.GetValueAt(DomainElement.Of(x[0], y[0]));
                        var value2 = r2.GetValueAt(DomainElement.Of(y[0], z[0]));

                        value = or(value, and(value1, value2));
                    }

                    result.Set(DomainElement.Of(x[0], z[0]), value);
                }
            }

            return(result);
        }
Пример #9
0
        private static void PrintExample3()
        {
            Console.WriteLine("EXAMPLE 3");
            IDomain d = IDomain.IntRange(0, 11);

            IFuzzySet set1 = new MutableFuzzySet(d).Set(DomainElement.Of(0), 1.0)
                             .Set(DomainElement.Of(1), 0.8)
                             .Set(DomainElement.Of(2), 0.6)
                             .Set(DomainElement.Of(3), 0.4)
                             .Set(DomainElement.Of(4), 0.2);

            PrintFuzzySet(set1, "Set1: ");

            IFuzzySet notSet1 = Operations.UnaryOperation(set1, Operations.ZadehNot());

            PrintFuzzySet(notSet1, "notSet1: ");

            IFuzzySet union = Operations.BinaryOperation(set1, notSet1, Operations.ZadehOr());

            PrintFuzzySet(union, "Set1 U notSet1: ");

            IFuzzySet hinters = Operations.BinaryOperation(set1, notSet1, Operations.HamacherTNorm(1.0));

            PrintFuzzySet(hinters, "Set1 Intersection with notSet1 using parameterised Hamacher T norm with parameter 1.0: ");
            Console.WriteLine("---------------------------------------");
            Console.WriteLine();
        }
Пример #10
0
        private static void Main()
        {
            var d = Domain.IntRange(0, 11); // {0,1,...,10}

            IFuzzySet set1 = new MutableFuzzySet(d)
                             .Set(DomainElement.Of(0), 0.4)
                             .Set(DomainElement.Of(1), 0.8)
                             .Set(DomainElement.Of(2), 0.6)
                             .Set(DomainElement.Of(3), 0.4)
                             .Set(DomainElement.Of(4), 0.2);

            Console.WriteLine("Set 1:");
            Console.WriteLine(set1);
            Console.WriteLine();

            var notSet1 = Operations.UnaryOperation(set1, Operations.ZadehNot());

            Console.WriteLine("notSet 1:");
            Console.WriteLine(notSet1);
            Console.WriteLine();

            var union = Operations.BinaryOperation(set1, notSet1, Operations.ZadehOr());

            Console.WriteLine("Set1 union notSet1:");
            Console.WriteLine(union);
            Console.WriteLine();

            var hinters = Operations.BinaryOperation(set1, notSet1, Operations.HamacherTNorm(1.0));

            Console.WriteLine("Set1 intersection with notSet1 using parameterised Hamacher T norm with parameter 1.0:");
            Console.WriteLine(hinters);
            Console.WriteLine();

            Console.ReadKey();
        }
        public static IFuzzySet?CompositionOfBinaryRelations(IFuzzySet A, IFuzzySet B)
        {
            if (!AreRelationsMultiplicative(A, B))
            {
                return(null);
            }

            var rowAComponent    = A.GetDomain().GetComponent(0);
            var columnAComponent = A.GetDomain().GetComponent(1);
            var rowBComponent    = B.GetDomain().GetComponent(0);
            var columnBComponent = B.GetDomain().GetComponent(1);

            var rowsA = rowAComponent.GetCardinality();
            var colsA = columnAComponent.GetCardinality();

            var colsB = columnBComponent.GetCardinality();

            var fuzzySet = new MutableFuzzySet(new CompositeDomain(new SimpleDomain[]
            {
                (SimpleDomain)rowAComponent,
                (SimpleDomain)columnBComponent
            }));

            for (var i = 0; i < rowsA; i++)
            {
                for (var j = 0; j < colsB; j++)
                {
                    var maxValue = 0.0;
                    for (var k = 0; k < colsA; k++)
                    {
                        var iElement = rowAComponent.ElementForIndex(i).GetComponentValue(0);
                        var jElement = columnBComponent.ElementForIndex(j).GetComponentValue(0);
                        var kElement = rowAComponent.ElementForIndex(k).GetComponentValue(0);

                        var ikElement = new DomainElement(iElement, kElement);
                        var kjElement = new DomainElement(kElement, jElement);

                        var ikElementValue  = A.GetValueAt(ikElement);
                        var kjElementValue  = B.GetValueAt(kjElement);
                        var newElementValue = Math.Min(ikElementValue, kjElementValue);

                        if (maxValue < newElementValue)
                        {
                            maxValue = newElementValue;
                        }
                    }
                    var iiElement = rowAComponent.ElementForIndex(i).GetComponentValue(0);
                    var jjElement = columnBComponent.ElementForIndex(j).GetComponentValue(0);

                    var ijElement = new DomainElement(iiElement, jjElement);
                    fuzzySet.Set(ijElement, maxValue);
                }
            }

            return(fuzzySet);
        }
Пример #12
0
        public static IFuzzySet UnaryOperation(IFuzzySet fuzzySet, IUnaryFunction unary)
        {
            MutableFuzzySet A = new MutableFuzzySet(fuzzySet.GetDomain());

            foreach (DomainElement e in fuzzySet.GetDomain())
            {
                A.Set(e, unary.ValueAt(fuzzySet.GetValueAt(e)));
            }
            return(A);
        }
        public static IFuzzySet UnaryOperation(IFuzzySet set, IUnaryFunction function)
        {
            var newSet = new MutableFuzzySet(set.GetDomain());

            foreach (var element in newSet.GetDomain())
            {
                newSet.Set(element, function.ValueAt(set.GetValueAt(element)));
            }

            return(newSet);
        }
Пример #14
0
        public AkcelFuzzySystem(Defuzzifier defuzzifier)
        {
            this.defuzzifier = defuzzifier;

            IDomain acceleration = Domain.IntRange(-5, 6);
            IDomain direction    = Domain.IntRange(0, 2);
            IDomain distance     = Domain.IntRange(0, 1301);
            IDomain velocity     = Domain.IntRange(0, 100);

            MutableFuzzySet Id = new MutableFuzzySet(distance);
            MutableFuzzySet Iv = new MutableFuzzySet(velocity);

            foreach (var element in distance)
            {
                Id.Set(element, 1);
            }
            foreach (var element in velocity)
            {
                Iv.Set(element, 1);
            }

            IFuzzySet Slow   = new CalculatedFuzzySet(velocity, StandardFuzzySets.LFunction(0, 40));
            IFuzzySet Medium = new CalculatedFuzzySet(velocity, StandardFuzzySets.LambdaFunction(37, 45, 55));
            IFuzzySet Fast   = new CalculatedFuzzySet(velocity, StandardFuzzySets.GammaFunction(48, 60));

            IFuzzySet CriticalClose = new CalculatedFuzzySet(distance, StandardFuzzySets.LFunction(10, 30));
            IFuzzySet Close         = new CalculatedFuzzySet(distance, StandardFuzzySets.LFunction(25, 50));
            IFuzzySet Far           = new CalculatedFuzzySet(distance, StandardFuzzySets.GammaFunction(70, 100));

            IFuzzySet Backward = new MutableFuzzySet(direction).Set(DomainElement.Of(0), 1);
            IFuzzySet Forward  = new MutableFuzzySet(direction).Set(DomainElement.Of(1), 1);

            IFuzzySet SpeedUp = new MutableFuzzySet(acceleration)
                                .Set(DomainElement.Of(5), 1)
                                .Set(DomainElement.Of(4), 0.6)
                                .Set(DomainElement.Of(3), 0.3);
            IFuzzySet Neutral  = new MutableFuzzySet(acceleration).Set(DomainElement.Of(0), 1);
            IFuzzySet SlowDown = new MutableFuzzySet(acceleration)
                                 .Set(DomainElement.Of(-5), 1)
                                 .Set(DomainElement.Of(-4), 0.6)
                                 .Set(DomainElement.Of(-3), 0.3);

            // L, D, LK, RK, V, S
            rules = new List <Rule>();
            rules.Add(new Rule(new[] { Id, Id, CriticalClose, Id, Iv, Forward }, Neutral, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, Id, CriticalClose, Iv, Forward }, Neutral, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, CriticalClose, Id, Iv, Backward }, Neutral, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, Id, CriticalClose, Iv, Backward }, Neutral, tNorm, implication));

            rules.Add(new Rule(new[] { Id, Id, Id, Id, Fast, Forward }, SlowDown, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, Id, Id, Medium, Forward }, Neutral, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, Id, Id, Slow, Forward }, SpeedUp, tNorm, implication));
        }
Пример #15
0
        private static void Main(string[] args)
        {
            SimpleDomain sd = new SimpleDomain(-4, 5);

            PrintDomain(sd, "sd: ");

            IDomain cd = IDomain.Combine(sd, sd);

            PrintDomain(cd, "cd: ");

            IDomain   d    = IDomain.IntRange(0, 11);
            IFuzzySet set1 = new MutableFuzzySet(d).Set(DomainElement.Of(0), 1.0);

            PrintFuzzySet(set1, "set1: ");

            IDomain   d2   = IDomain.IntRange(-5, 6);
            IFuzzySet set2 = new CalculatedFuzzySet(d2,
                                                    StandardFuzzySets.LambdaFunction(d2.IndexOfElement(DomainElement.Of(-4)),
                                                                                     d2.IndexOfElement(DomainElement.Of(0)),
                                                                                     d2.IndexOfElement(DomainElement.Of(4))));

            PrintFuzzySet(set2, "set2: ");


            IDomain d7 = IDomain.IntRange(0, 11);

            IFuzzySet set3 = new MutableFuzzySet(d7).Set(DomainElement.Of(0), 1.0)
                             .Set(DomainElement.Of(1), 0.8)
                             .Set(DomainElement.Of(2), 0.6)
                             .Set(DomainElement.Of(3), 0.4)
                             .Set(DomainElement.Of(4), 0.2);

            PrintFuzzySet(set3, "set3: ");

            IFuzzySet notSet3 = Operations.UnaryOperation(set3, Operations.ZadehNot());

            PrintFuzzySet(notSet3, "notSet3: ");

            IFuzzySet union = Operations.BinaryOperation(set3, notSet3, Operations.ZadehOr());

            PrintFuzzySet(union, "Set3 U notSet3: ");

            IFuzzySet hinters = Operations.BinaryOperation(set3, notSet3, Operations.HamacherTNorm(1.0));

            PrintFuzzySet(hinters, "Set3 Intersection with notSet3 using parameterised Hamacher T norm with parameter 1.0: ");
        }
Пример #16
0
        public static IFuzzySet BinaryOperation(IFuzzySet fuzzySetA, IFuzzySet fuzzySetB, IBinaryFunction binary)
        {
            MutableFuzzySet A = new MutableFuzzySet(fuzzySetA.GetDomain());

            //if (fuzzySetA.GetDomain() != fuzzySetB.GetDomain())
            //{
            //    if (fuzzySetA.GetDomain().GetComponent(fuzzySetA.GetDomain().GetNumberOfComponents() - 1) != fuzzySetB.GetDomain().GetComponent(fuzzySetB.GetDomain().GetNumberOfComponents() - 1))
            //    {
            //        Console.WriteLine("Can't do binary operation on sets with different domains");
            //        return A;
            //    }

            //}

            foreach (DomainElement e in fuzzySetA.GetDomain())
            {
                A.Set(e, binary.ValueAt(fuzzySetA.GetValueAt(e), fuzzySetB.GetValueAt(e)));
            }
            return(A);
        }
Пример #17
0
        public IFuzzySet Accept(int[] inputs)
        {
            IDomain         domain   = consequent.GetDomain();
            MutableFuzzySet solution = new MutableFuzzySet(domain);

            foreach (var element in domain)
            {
                //Console.Error.WriteLine(antecedent[1]);
                //Console.Error.WriteLine(inputs[0]);
                double tmp = antecedent[0].GetValueAt(DomainElement.Of(inputs[0]));

                for (int i = 1; i < antecedent.Length; ++i)
                {
                    tmp = tNorm(tmp, antecedent[i].GetValueAt(DomainElement.Of(inputs[i])));
                }
                solution.Set(element, implication(tmp, consequent.GetValueAt(element)));
            }

            return(solution);
        }
Пример #18
0
        private static void PrintExample2()
        {
            Console.WriteLine("EXAMPLE 2");
            IDomain   d    = IDomain.IntRange(0, 11);
            IFuzzySet set1 = new MutableFuzzySet(d)
                             .Set(DomainElement.Of(0), 1.0)
                             .Set(DomainElement.Of(1), 0.8)
                             .Set(DomainElement.Of(2), 0.6)
                             .Set(DomainElement.Of(3), 0.4)
                             .Set(DomainElement.Of(4), 0.2);

            PrintFuzzySet(set1, "Set1: ");

            IDomain   d2   = IDomain.IntRange(-5, 6);
            IFuzzySet set2 = new CalculatedFuzzySet(d2,
                                                    StandardFuzzySets.LambdaFunction(d2.IndexOfElement(DomainElement.Of(-4)),
                                                                                     d2.IndexOfElement(DomainElement.Of(0)),
                                                                                     d2.IndexOfElement(DomainElement.Of(4))));

            PrintFuzzySet(set2, "Set2: ");
            Console.WriteLine("---------------------------------------");
            Console.WriteLine();
        }
Пример #19
0
        private static void PrintExample6()
        {
            Console.WriteLine("EXAMPLE 6");
            IDomain   uFinal = IDomain.IntRange(1, 5); // {1,2,3,4}
            IFuzzySet r      = new MutableFuzzySet(IDomain.Combine(uFinal, uFinal))
                               .Set(DomainElement.Of(1, 1), 1)
                               .Set(DomainElement.Of(2, 2), 1)
                               .Set(DomainElement.Of(3, 3), 1)
                               .Set(DomainElement.Of(4, 4), 1)
                               .Set(DomainElement.Of(1, 2), 0.3)
                               .Set(DomainElement.Of(2, 1), 0.3)
                               .Set(DomainElement.Of(2, 3), 0.5)
                               .Set(DomainElement.Of(3, 2), 0.5)
                               .Set(DomainElement.Of(3, 4), 0.2)
                               .Set(DomainElement.Of(4, 3), 0.2);
            IFuzzySet r2 = r;

            Console.WriteLine($"Pocetna relacija je neizrazita relacija ekvivalencija? {Relations.IsFuzzyEquivalence(r2)}");
            Console.WriteLine();

            for (var i = 0; i < 3; i++)
            {
                r2 = Relations.CompositionOfBinaryRelations(r2, r) !;

                Console.WriteLine($"Broj odradenih kompozicija je: {i + 1}. Relacija je: ");

                foreach (var element in r2.GetDomain())
                {
                    Console.WriteLine($"mu({element}) = {r2.GetValueAt(element)}");
                }

                Console.WriteLine($"Ova relacija je neizrazita relacija ekvivalencije? {Relations.IsFuzzyEquivalence(r2)}");
                Console.WriteLine();
            }
            Console.WriteLine("---------------------------------------");
            Console.WriteLine();
        }
Пример #20
0
        static void Main(string[] args)
        {
            IDomain u = Domain.IntRange(1, 5);  // {1,2,3,4}

            IFuzzySet r = new MutableFuzzySet(Domain.Combine(u, u))
                          .Set(DomainElement.Of(1, 1), 1)
                          .Set(DomainElement.Of(2, 2), 1)
                          .Set(DomainElement.Of(3, 3), 1)
                          .Set(DomainElement.Of(4, 4), 1)
                          .Set(DomainElement.Of(1, 2), 0.3)
                          .Set(DomainElement.Of(2, 1), 0.3)
                          .Set(DomainElement.Of(2, 3), 0.5)
                          .Set(DomainElement.Of(3, 2), 0.5)
                          .Set(DomainElement.Of(3, 4), 0.2)
                          .Set(DomainElement.Of(4, 3), 0.2);

            IFuzzySet r2 = r;

            Console.Write("Početna relacija je neizrazita relacija ekvivalencije? ");
            Console.WriteLine(Relations.IsFuzzyEquivalence(r2));
            Console.WriteLine();

            for (int i = 1; i <= 3; i++)
            {
                r2 = Relations.CompositionOfBinaryRelations(r2, r);
                Console.WriteLine("Broj odrađenih kompozicija: " + i + ". Relacija je:");
                Console.Write(r2);

                Console.Write("Ova relacija je neizrazita relacija ekvivalencije? ");
                Console.WriteLine(Relations.IsFuzzyEquivalence(r2));
                Console.WriteLine();
            }


            Console.ReadKey();
        }
Пример #21
0
        public static void Primjer22()
        {
            IDomain   u1 = Domain.IntRange(1, 5); // {1,2,3,4}
            IDomain   u2 = Domain.IntRange(1, 4); // {1,2,3}
            IDomain   u3 = Domain.IntRange(1, 5); // {1,2,3,4}
            IFuzzySet r1 = new MutableFuzzySet(Domain.Combine(u1, u2))
                           .Set(DomainElement.Of(1, 1), 0.3)
                           .Set(DomainElement.Of(1, 2), 1)
                           .Set(DomainElement.Of(3, 3), 0.5)
                           .Set(DomainElement.Of(4, 3), 0.5);
            IFuzzySet r2 = new MutableFuzzySet(Domain.Combine(u2, u3))
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 1), 0.5)
                           .Set(DomainElement.Of(2, 2), 0.7)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(3, 4), 0.4);

            IFuzzySet r1r2 = Relations.Relations.CompositionOfBinaryRelations(r1, r2, Operations.Operations.ZadehAnd(), Operations.Operations.ZadehOr());

            foreach (DomainElement e in r1r2.GetDomain())
            {
                Console.WriteLine("mu(" + e + ")=" + r1r2.GetValueAt(e));
            }
        }
Пример #22
0
        static void Main(string[] args)
        {
            IDomain u  = Domain.IntRange(1, 6);
            IDomain u2 = Domain.Combine(u, u);

            IFuzzySet r1 = new MutableFuzzySet(u2)
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 2), 1)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(4, 4), 1)
                           .Set(DomainElement.Of(5, 5), 1)
                           .Set(DomainElement.Of(3, 1), 0.6)
                           .Set(DomainElement.Of(1, 3), 0.5);

            IFuzzySet r2 = new MutableFuzzySet(u2)
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 2), 1)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(4, 4), 1)
                           .Set(DomainElement.Of(5, 5), 1)
                           .Set(DomainElement.Of(3, 1), 0.5)
                           .Set(DomainElement.Of(1, 3), 0.1);

            IFuzzySet r3 = new MutableFuzzySet(u2)
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 2), 1)
                           .Set(DomainElement.Of(3, 3), 0.3)
                           .Set(DomainElement.Of(4, 4), 1)
                           .Set(DomainElement.Of(5, 5), 1)
                           .Set(DomainElement.Of(1, 2), 0.6)
                           .Set(DomainElement.Of(2, 1), 0.6)
                           .Set(DomainElement.Of(2, 3), 0.7)
                           .Set(DomainElement.Of(3, 2), 0.7)
                           .Set(DomainElement.Of(3, 1), 0.5)
                           .Set(DomainElement.Of(1, 3), 0.5);

            IFuzzySet r4 = new MutableFuzzySet(u2)
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 2), 1)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(4, 4), 1)
                           .Set(DomainElement.Of(5, 5), 1)
                           .Set(DomainElement.Of(1, 2), 0.4)
                           .Set(DomainElement.Of(2, 1), 0.4)
                           .Set(DomainElement.Of(2, 3), 0.5)
                           .Set(DomainElement.Of(3, 2), 0.5)
                           .Set(DomainElement.Of(1, 3), 0.4)
                           .Set(DomainElement.Of(3, 1), 0.4);

            bool test1 = Relations.IsUTimesURelation(r1);

            Console.WriteLine("r1 je definiran nad UxU? " + test1);

            bool test2 = Relations.IsSymmetric(r1);

            Console.WriteLine("r1 je simetrična? " + test2);

            bool test3 = Relations.IsSymmetric(r2);

            Console.WriteLine("r2 je simetrična? " + test3);

            bool test4 = Relations.IsReflexive(r1);

            Console.WriteLine("r1 je refleksivna? " + test4);

            bool test5 = Relations.IsReflexive(r3);

            Console.WriteLine("r3 je refleksivna? " + test5);

            bool test6 = Relations.IsMaxMinTransitive(r3);

            Console.WriteLine("r3 je max-min tranzitivna? " + test6);

            bool test7 = Relations.IsMaxMinTransitive(r4);

            Console.WriteLine("r4 je max-min tranzitivna? " + test7);


            Console.ReadKey();
        }
Пример #23
0
        private static void PrintExample4()
        {
            Console.WriteLine("EXAMPLE 4");
            IDomain   u  = IDomain.IntRange(1, 6); // {1,2,3,4,5}
            IDomain   u2 = IDomain.Combine(u, u);
            IFuzzySet r1 = new MutableFuzzySet(u2)
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 2), 1)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(4, 4), 1)
                           .Set(DomainElement.Of(5, 5), 1)
                           .Set(DomainElement.Of(3, 1), 0.5)
                           .Set(DomainElement.Of(1, 3), 0.5);

            IFuzzySet r2 = new MutableFuzzySet(u2)
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 2), 1)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(4, 4), 1)
                           .Set(DomainElement.Of(5, 5), 1)
                           .Set(DomainElement.Of(3, 1), 0.5)
                           .Set(DomainElement.Of(1, 3), 0.1);

            IFuzzySet r3 = new MutableFuzzySet(u2)
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 2), 1)
                           .Set(DomainElement.Of(3, 3), 0.3)
                           .Set(DomainElement.Of(4, 4), 1)
                           .Set(DomainElement.Of(5, 5), 1)
                           .Set(DomainElement.Of(1, 2), 0.6)
                           .Set(DomainElement.Of(2, 1), 0.6)
                           .Set(DomainElement.Of(2, 3), 0.7)
                           .Set(DomainElement.Of(3, 2), 0.7)
                           .Set(DomainElement.Of(3, 1), 0.5)
                           .Set(DomainElement.Of(1, 3), 0.5);

            IFuzzySet r4 = new MutableFuzzySet(u2)
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 2), 1)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(4, 4), 1)
                           .Set(DomainElement.Of(5, 5), 1)
                           .Set(DomainElement.Of(1, 2), 0.4)
                           .Set(DomainElement.Of(2, 1), 0.4)
                           .Set(DomainElement.Of(2, 3), 0.5)
                           .Set(DomainElement.Of(3, 2), 0.5)
                           .Set(DomainElement.Of(1, 3), 0.4)
                           .Set(DomainElement.Of(3, 1), 0.4);

            var test1 = Relations.IsUTimesURelation(r1);

            Console.WriteLine($"r1 je definiran nad UxU? {test1}");

            var test2 = Relations.IsSymmetric(r1);

            Console.WriteLine($"r1 je simetrična? {test2}");

            var test3 = Relations.IsSymmetric(r2);

            Console.WriteLine($"r2 je simetrična? {test3}");

            var test4 = Relations.IsReflexive(r1);

            Console.WriteLine($"r1 je refleksivna? {test4}");

            var test5 = Relations.IsReflexive(r3);

            Console.WriteLine($"r3 je refleksivna? {test5}");

            var test6 = Relations.IsMaxMinTransitive(r3);

            Console.WriteLine($"r3 je max-min tranzitivna? {test6}");

            var test7 = Relations.IsMaxMinTransitive(r4);

            Console.WriteLine($"r4 je max-min tranzitivna? {test7}");
            Console.WriteLine("---------------------------------------");
            Console.WriteLine();
        }
Пример #24
0
        public KormiloFuzzySystem(Defuzzifier defuzzifier)
        {
            this.defuzzifier = defuzzifier;

            IDomain angle     = Domain.IntRange(-90, 91);
            IDomain direction = Domain.IntRange(0, 2);
            IDomain distance  = Domain.IntRange(0, 1301);
            IDomain velocity  = Domain.IntRange(0, 100);

            MutableFuzzySet Id = new MutableFuzzySet(distance);
            MutableFuzzySet Iv = new MutableFuzzySet(velocity);

            foreach (var element in distance)
            {
                Id.Set(element, 1);
            }
            foreach (var element in velocity)
            {
                Iv.Set(element, 1);
            }

            //IFuzzySet CriticalClose = new CalculatedFuzzySet(distance, StandardFuzzySets.LFunction(20, 40));
            IFuzzySet Close   = new CalculatedFuzzySet(distance, StandardFuzzySets.LFunction(40, 90));
            IFuzzySet Far     = new CalculatedFuzzySet(distance, StandardFuzzySets.GammaFunction(100, 200));
            IFuzzySet VeryFar = new CalculatedFuzzySet(distance, StandardFuzzySets.GammaFunction(300, 400));
            //IFuzzySet NotFar = Operations.UnaryOperation(Far, Operations.ZadehNot());

            IFuzzySet Backward = new MutableFuzzySet(direction).Set(DomainElement.Of(0), 1);
            IFuzzySet Forward  = new MutableFuzzySet(direction).Set(DomainElement.Of(1), 1);

            IFuzzySet Left = new MutableFuzzySet(angle).Set(DomainElement.Of(90), 1);
            //IFuzzySet Left = new CalculatedFuzzySet(angle, StandardFuzzySets.LambdaFunction(0, 30, 50));
            //IFuzzySet FullLeft = new CalculatedFuzzySet(angle, StandardFuzzySets.LambdaFunction(55, 70, 80));

            IFuzzySet Neutral = new CalculatedFuzzySet(angle, StandardFuzzySets.LambdaFunction(-10, 0, 10));

            //IFuzzySet Right = new CalculatedFuzzySet(angle, StandardFuzzySets.LambdaFunction(-50, -30, 0));
            IFuzzySet Right = new MutableFuzzySet(angle).Set(DomainElement.Of(-90), 1);

            //IFuzzySet FullRight = new CalculatedFuzzySet(angle, StandardFuzzySets.LambdaFunction(-80, -70, -55));


            // L, D, LK, RK, V, S
            rules = new List <Rule>();
            rules.Add(new Rule(new[] { Id, Close, Id, Id, Iv, Forward }, Left, tNorm, implication));
            rules.Add(new Rule(new[] { Close, Id, Id, Id, Iv, Forward }, Right, tNorm, implication));

            rules.Add(new Rule(new[] { Id, Id, Id, Close, Iv, Forward }, Left, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, Close, Id, Iv, Forward }, Right, tNorm, implication));

            rules.Add(new Rule(new[] { VeryFar, Id, Id, Id, Iv, Backward }, Left, tNorm, implication));
            rules.Add(new Rule(new[] { Id, VeryFar, Id, Id, Iv, Backward }, Right, tNorm, implication));


            //rules.Add(new Rule(new[] { Far, Close, Id, Id, Iv, Forward }, Left, tNorm, implication));
            //rules.Add(new Rule(new[] { Id, Close, Id, CriticalClose, Iv, Forward }, FullLeft));
            //rules.Add(new Rule(new[] { Far, Close, Id, Id, Iv, Backward }, Left, tNorm, implication));

            //rules.Add(new Rule(new[] { Far, Far, Id, Id, Iv, Forward }, Neutral));

            //rules.Add(new Rule(new[] { Close, Far, Id, Id, Iv, Forward }, Right, tNorm, implication));
            //rules.Add(new Rule(new[] { Close, Id, CriticalClose, Id, Iv, Forward }, FullRight));
            //rules.Add(new Rule(new[] { Close, Far, Id, Id, Iv, Backward }, Right, tNorm, implication));


            //rules.Add(new Rule(new[] { Far, Id, Close, Close, Iv, Forward }, Left, tNorm, implication));
            //rules.Add(new Rule(new[] { Id, Far, Close, Close, Iv, Forward }, Right, tNorm, implication));
            //rules.Add(new Rule(new[] { VeryFar, VeryFar, Close, Close, Iv, Forward }, Right, tNorm, implication));

            //rules.Add(new Rule(new[] { Far, Id, Close, Close, Iv, Backward }, Right, tNorm, implication));
            ////rules.Add(new Rule(new[] { Id, Far, Close, Close, Iv, Backward }, Left, tNorm, implication));


            //rules.Add(new Rule(new[] { Close, Close, Id, Close, Iv, Forward }, Left, tNorm, implication));
            //rules.Add(new Rule(new[] { Close, Close, Close, Id, Iv, Forward }, Right, tNorm, implication));

            //rules.Add(new Rule(new[] { Id, Id, Id, Id, Iv, Backward }, Right, tNorm, implication));

            //rules.Add(new Rule(new[] { VeryFar, Id, Close, Close, Iv, Forward }, Right, tNorm, implication));
            //rules.Add(new Rule(new[] { Id, VeryFar, Close, Close, Iv, Forward }, Left, tNorm, implication));
        }