Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
        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);
        }
Esempio n. 4
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);
        }
Esempio n. 6
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));
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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));
        }