public IFuzzySet SingleRuleConclusionProduct(int L, int D, int LK, int DK, int V, int S)       //TODO napravi varijantu i za StrojMinimum i za StrojProdukt
        {
            double[] antecMembershipFunctions = new double[] {
                _antec1.GetValueAt(DomainElement.Of(L)),
                _antec2.GetValueAt(DomainElement.Of(D)),
                _antec3.GetValueAt(DomainElement.Of(LK)),
                _antec4.GetValueAt(DomainElement.Of(DK)),
                _antec5.GetValueAt(DomainElement.Of(V)),
                _antec6.GetValueAt(DomainElement.Of(S))
            };

            double prodMembershipFunc = 1;

            foreach (double var in antecMembershipFunctions)
            {
                prodMembershipFunc *= var;
            }

            IFuzzySet antecedents = new CalculatedFuzzySet(                                     //mjere pripadnosti su na minimumu mj.pripadnosti antecedenata
                _conseq.GetDomain(),
                StandardFuzzySets.UniversalFunction(prodMembershipFunc)
                );


            //KormiloFuzzySystemMin.Print(antecedents, "antecedents:");
            //KormiloFuzzySystemMin.Print(_conseq, "_conseq:");
            //KormiloFuzzySystemMin.Print(_antec5, "_antec:");


            IFuzzySet conclusion = Operations.Operations.BinaryOperation(antecedents, _conseq, Operations.Operations.AlgProduct());

            //KormiloFuzzySystemMin.Print(conclusion, "conclusion:");

            return(conclusion);
        }
예제 #2
0
        public static void Test33()
        {
            double[] antecMembershipFunctions = new double[] {
                0.8, 0.8, 0.7, 1, 0.7, 0.9
            };

            double minMembershipFunc = antecMembershipFunctions.Min();

            IDomain u = Domain.IntRange(-5, 6);

            IFuzzySet _conseq = new CalculatedFuzzySet(
                u,
                StandardFuzzySets.LambdaFunction(
                    u.IndexOfElement(DomainElement.Of(-5)),
                    u.IndexOfElement(DomainElement.Of(-3)),
                    u.IndexOfElement(DomainElement.Of(0))
                    )
                );

            Debug1.Print(_conseq, "Konsekv1:");


            IFuzzySet antecedents = new CalculatedFuzzySet(                                     //mjere pripadnosti su na minimumu mj.pripadnosti antecedenata
                _conseq.GetDomain(),
                StandardFuzzySets.UniversalFunction(minMembershipFunc)
                );

            IFuzzySet conclusion = Operations.Operations.BinaryOperation(antecedents, _conseq, Operations.Operations.ZadehAnd());

            Debug1.Print(conclusion, "Zakljucak1:");
        }
        private void KormiloRuleBook()
        {
            KormiloRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LambdaFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(35)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(60)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleConsequensKor(StandardFuzzySets.LambdaFunction(
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-60)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-45)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-30))) //umjeren udesno
                                                    )
                    )
                );


            KormiloRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(50)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.GammaFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(70)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(90)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LambdaFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(35)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(75)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(135)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleConsequensKor(StandardFuzzySets.LambdaFunction(
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-90)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-80)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-55))) //ostro udesno
                                                    )
                    )
                );



            KormiloRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LambdaFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(35)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(60)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleConsequensKor(StandardFuzzySets.LambdaFunction(
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(30)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(45)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(60))) //umjeren ulijevo
                                                    )
                    )
                );


            KormiloRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.GammaFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(70)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(90)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(50)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LambdaFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(35)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(75)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(135)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleConsequensKor(StandardFuzzySets.LambdaFunction(
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(55)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(80)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(90))) //ostro ulijevo
                                                    )
                    )
                );



            KormiloRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(30)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(50)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(30)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(60)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleConsequensKor(StandardFuzzySets.LFunction(
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-80)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-25))) //ostro udesno vrlo blizu lijevo neovisno o brzini
                                                    )
                    )
                );


            KormiloRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(30)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(50)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(30)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(60)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleConsequensKor(StandardFuzzySets.GammaFunction(
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(25)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(80))) //ostro ulijevo vrlo blizu desno neovisno o brzini
                                                    )
                    )
                );


            KormiloRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LambdaFunction(
                                                     Rule.UKOR.IndexOfElement(DomainElement.Of(-2)),
                                                     Rule.UKOR.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UKOR.IndexOfElement(DomainElement.Of(1)))
                                                 ),

                    Rule.MakeFuzzyRuleConsequensAcc(StandardFuzzySets.LambdaFunction(
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-90)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-85)),
                                                        Rule.UKOR.IndexOfElement(DomainElement.Of(-80)))
                                                    )                                       //rotiraj
                    )
                );
        }
        private void AkcelRuleBook()
        {
            AkcelRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(50)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(75)))
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleConsequensAcc(StandardFuzzySets.LambdaFunction(
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(0)),
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(10)),
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(20)))
                                                    )                                               //ubrzaj do 75
                    )
                );

            AkcelRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)))
                                                 ), //vrlo blizu obali lijevo

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ), //nebitno desno

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)))
                                                 ), //vrlo blizu LK

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.GammaFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(200)))
                                                 ), //umjereno blizu LK

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LambdaFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(35)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(65)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(135))) //do cca 90 px/s
                                                 ),                                                     //velika brzina

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ), //nebitno S??     //TODO mozda popraviti domenu od S

                    Rule.MakeFuzzyRuleConsequensAcc(StandardFuzzySets.LambdaFunction(
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(-30)),
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(-22)),
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(0)))
                                                    )                                       //zavoj
                    )
                );

            AkcelRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ), //nebitno lijevo

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)))
                                                 ), //umjereno blizu desno

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.GammaFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(200)))
                                                 ), //umjereno blizu LK

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(80)))
                                                 ), //umjereno blizu DK

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LambdaFunction(
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(35)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(65)),
                                                     Rule.UANTEC.IndexOfElement(DomainElement.Of(135))) //do cca 90 px/s
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ), //nebitno S??     //TODO mozda popraviti domenu od S

                    Rule.MakeFuzzyRuleConsequensAcc(StandardFuzzySets.LambdaFunction(
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(-30)),
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(-22)),
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(0)))
                                                    )                                       //zavoj
                    )
                );

            AkcelRules.Add(
                new Rule(
                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.UniversalFunction(
                                                     1)
                                                 ),

                    Rule.MakeFuzzyRuleAntecedent(StandardFuzzySets.LambdaFunction(
                                                     Rule.UKOR.IndexOfElement(DomainElement.Of(-1)),
                                                     Rule.UKOR.IndexOfElement(DomainElement.Of(0)),
                                                     Rule.UKOR.IndexOfElement(DomainElement.Of(1)))
                                                 ),

                    Rule.MakeFuzzyRuleConsequensAcc(StandardFuzzySets.LambdaFunction(
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(-30)),
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(-22)),
                                                        Rule.UACC.IndexOfElement(DomainElement.Of(0)))
                                                    )                                       //rotiraj
                    )
                );
        }