Beispiel #1
0
        public bool FuzzyGenerateRulesAndGetResultFLLComparison(GetRuleDTO rules, double inputValue1, double inputValue2, int rate)
        {
            FuzzySystemResultDTO system = new FuzzySystemResultDTO();

            system      = GenerateSystem(rules, inputValue1);
            _fsSoil     = system.System;
            inputValue1 = system.InputValue;

            FuzzyVariable fvInput1  = _fsSoil.InputByName(rules.VariableList.FirstOrDefault(d => d.DegiskenTipID == (byte)Enums.VariableType.Input).DegiskenGorunenAdi);
            FuzzyVariable fvOutput1 = _fsSoil.OutputByName(rules.VariableList.FirstOrDefault(d => d.DegiskenTipID == (byte)Enums.VariableType.Output).DegiskenGorunenAdi);

            Dictionary <FuzzyVariable, double> inputValues1 = new Dictionary <FuzzyVariable, double>();

            inputValues1.Add(fvInput1, inputValue1);

            Dictionary <FuzzyVariable, double> result1 = _fsSoil.Calculate(inputValues1);

            _fsSoil.DefuzzificationMethod = DefuzzificationMethod.Bisector;

            double outputValue1 = result1[fvOutput1];

            _fsSoil     = null;
            system      = GenerateSystem(rules, inputValue2);
            _fsSoil     = system.System;
            inputValue2 = system.InputValue;

            FuzzyVariable fvInput2  = _fsSoil.InputByName(rules.VariableList.FirstOrDefault(d => d.DegiskenTipID == (byte)Enums.VariableType.Input).DegiskenGorunenAdi);
            FuzzyVariable fvOutput2 = _fsSoil.OutputByName(rules.VariableList.FirstOrDefault(d => d.DegiskenTipID == (byte)Enums.VariableType.Output).DegiskenGorunenAdi);

            Dictionary <FuzzyVariable, double> inputValues2 = new Dictionary <FuzzyVariable, double>();

            inputValues2.Add(fvInput2, inputValue2);

            Dictionary <FuzzyVariable, double> result2 = _fsSoil.Calculate(inputValues2);

            _fsSoil.DefuzzificationMethod = DefuzzificationMethod.Centroid;

            double outputValue2 = result2[fvOutput2];

            var result = GetResultForProximity(outputValue1, outputValue2, rate);

            return(result);
        }
Beispiel #2
0
        private string GetResultForCloseLine(GetRuleDTO rules, double outputValue)
        {
            string sonuc = "";

            var variableId = rules.VariableList.FirstOrDefault(dl => dl.DegiskenTipID == (byte)Enums.VariableType.Output).DegiskenID;
            var OutputList = _variableItemService.Queryable().Where(d => d.DegiskenID == variableId).ToList();

            for (int i = 0; i < OutputList.Count; i++)
            {
                if (i == OutputList.Count - 1)
                {
                    //if (outputValue >= OutputList[i].MinDeger && outputValue <= OutputList[i].MaxDeger)
                    //{
                    sonuc = OutputList[i].DegiskenItemAdi;
                    break;
                    //}
                }
                else
                {
                    if (OutputList[i].MaxDeger > OutputList[i + 1].MinDeger) //Means that has intersection with next definition range (Bir sonraki tanım aralığı ile kesişimi var demektir)
                    {
                        if (outputValue <= OutputList[i].MaxDeger && outputValue >= OutputList[i + 1].MinDeger)
                        {
                            sonuc = Math.Abs(outputValue - OutputList[i].MaxDeger) > Math.Abs(outputValue - OutputList[i + 1].MinDeger) ? OutputList[i].DegiskenItemAdi : OutputList[i + 1].DegiskenItemAdi;
                            break;
                        }
                    }
                    else
                    {
                        if (outputValue >= OutputList[i].MinDeger && outputValue <= OutputList[i].MaxDeger)
                        {
                            sonuc = OutputList[i].DegiskenItemAdi;
                            break;
                        }
                    }
                }
            }


            return(sonuc);
        }
Beispiel #3
0
        public GetRuleDTO GetRule(long kuralID)
        {
            GetRuleDTO          getRule          = new GetRuleDTO();
            List <DegiskenItem> variableItemList = new List <DegiskenItem>();
            var rule         = _ruleService.Queryable().FirstOrDefault(k => k.KuralID == kuralID && k.AktifMi == true);
            var ruleListText = rule.KuralListTexts.ToList();
            var variables    = rule.Degiskens.ToList();

            foreach (var item in variables)
            {
                var degiskenItems = _variableItemService.Queryable().Where(d => d.DegiskenID == item.DegiskenID).ToList();
                variableItemList.AddRange(degiskenItems);
            }

            getRule.Rule             = rule;
            getRule.RuleListText     = ruleListText;
            getRule.VariableList     = variables;
            getRule.VariableItemList = variableItemList;

            return(getRule);
        }
Beispiel #4
0
        private FuzzySystemResultDTO GenerateSystem(GetRuleDTO rules, double inputValue)
        {
            FuzzySystemResultDTO result = new FuzzySystemResultDTO();
            MamdaniFuzzySystem   fsSoil = new MamdaniFuzzySystem();

            foreach (var variable in rules.VariableList)
            {
                if (variable.DegiskenTipID == (byte)Enums.VariableType.Input)
                {
                    FuzzyVariable fvInput       = new FuzzyVariable(variable.DegiskenGorunenAdi, 0.0, 1000.0);
                    var           variableItems = rules.VariableItemList.Where(k => k.DegiskenID == variable.DegiskenID).ToList();
                    for (int i = 0; i < variableItems.Count; i++)
                    {
                        if (inputValue == variableItems[i].MinDeger)
                        {
                            inputValue++;
                        }
                        double maxValue;
                        if (i != variableItems.Count - 1)
                        {
                            if (variableItems[i].MaxDeger == variableItems[i + 1].MinDeger)
                            {
                                maxValue = variableItems[i].MaxDeger - 1;
                            }
                            else
                            {
                                maxValue = variableItems[i].MaxDeger;
                            }
                        }
                        else
                        {
                            maxValue = variableItems[i].MaxDeger;
                        }

                        fvInput.Terms.Add(new FuzzyTerm(variableItems[i].DegiskenItemGorunenAdi, new TriangularMembershipFunction(variableItems[i].MinDeger, (variableItems[i].MinDeger + variableItems[i].MaxDeger) / 2, maxValue)));
                    }
                    fsSoil.Input.Add(fvInput);
                }
                else
                {
                    FuzzyVariable fvOutput      = new FuzzyVariable(variable.DegiskenGorunenAdi, 0.0, 1000.0);
                    var           variableItems = rules.VariableItemList.Where(k => k.DegiskenID == variable.DegiskenID).ToList();
                    for (int i = 0; i < variableItems.Count; i++)
                    {
                        double maxValue;
                        if (i != variableItems.Count - 1)
                        {
                            if (variableItems[i].MaxDeger == variableItems[i + 1].MinDeger)
                            {
                                maxValue = variableItems[i].MaxDeger - 1;
                            }
                            else
                            {
                                maxValue = variableItems[i].MaxDeger;
                            }
                        }
                        else
                        {
                            maxValue = variableItems[i].MaxDeger;
                        }

                        fvOutput.Terms.Add(new FuzzyTerm(variableItems[i].DegiskenItemGorunenAdi, new TriangularMembershipFunction(variableItems[i].MinDeger, (variableItems[i].MinDeger + variableItems[i].MaxDeger) / 2, maxValue)));
                    }
                    fsSoil.Output.Add(fvOutput);
                }
            }

            foreach (var ruleText in rules.RuleListText)
            {
                MamdaniFuzzyRule rule = fsSoil.ParseRule(ruleText.KuralText);
                fsSoil.Rules.Add(rule);
            }

            result.System     = fsSoil;
            result.InputValue = inputValue;
            return(result);
        }
Beispiel #5
0
        public string FuzzyGenerateRulesAndGetResultFLL(GetRuleDTO rules, double inputValue)
        {
            //var ozdirenc = GorunenAdDuzenle(kuralKume.OzdirencList);
            //var toprak = GorunenAdDuzenle(kuralKume.ToprakList);
            FuzzySystemResultDTO system = new FuzzySystemResultDTO();

            system     = GenerateSystem(rules, inputValue);
            _fsSoil    = system.System;
            inputValue = system.InputValue;


            FuzzyVariable fvInput  = _fsSoil.InputByName(rules.VariableList.FirstOrDefault(d => d.DegiskenTipID == (byte)Enums.VariableType.Input).DegiskenGorunenAdi);
            FuzzyVariable fvOutput = _fsSoil.OutputByName(rules.VariableList.FirstOrDefault(d => d.DegiskenTipID == (byte)Enums.VariableType.Output).DegiskenGorunenAdi);

            Dictionary <FuzzyVariable, double> inputValues = new Dictionary <FuzzyVariable, double>();

            inputValues.Add(fvInput, inputValue);

            Dictionary <FuzzyVariable, double> result = _fsSoil.Calculate(inputValues);

            _fsSoil.DefuzzificationMethod = DefuzzificationMethod.Centroid;

            double outputValue = result[fvOutput];
            string outputType  = GetResultForCloseLine(rules, outputValue);

            return(outputType);

            #region FuzzyIslemleri
            //#region Inputs
            //FuzzyVariable fvOzdirenc = new FuzzyVariable("Ozdirenc", 0.0, 1000.0);
            //foreach (var item in ozdirenc)
            //{
            //    fvOzdirenc.Terms.Add(new FuzzyTerm(item.Adi, new TriangularMembershipFunction(item.MinDeger, (item.MinDeger + item.MaxDeger) / 2, item.MaxDeger)));
            //}
            //fsToprak.Input.Add(fvOzdirenc);

            //FuzzyVariable fvMukavemet = new FuzzyVariable("Mukavemet", 0.0, 1000.0);
            //foreach (var item in _commonManager.Mukavemet)
            //{
            //    fvMukavemet.Terms.Add(new FuzzyTerm(item.Adi, new TriangularMembershipFunction(item.MinDeger, (item.MinDeger + item.MaxDeger) / 2, item.MaxDeger)));
            //}
            //fsToprak.Input.Add(fvMukavemet);

            //FuzzyVariable fvDoygunluk = new FuzzyVariable("Doygunluk", 0.0, 10.0);
            //foreach (var item in _commonManager.Doygunluk)
            //{
            //    fvDoygunluk.Terms.Add(new FuzzyTerm(item.Adi, new TriangularMembershipFunction(item.MinDeger, (item.MinDeger + item.MaxDeger) / 2, item.MaxDeger)));
            //}
            //fsToprak.Input.Add(fvDoygunluk);
            //#endregion

            //#region Output
            //FuzzyVariable fvToprak = new FuzzyVariable("Toprak", 0.0, 1000.0);
            //foreach (var item in toprak)
            //{
            //    fvToprak.Terms.Add(new FuzzyTerm(item.Adi, new TriangularMembershipFunction(item.MinDeger, (item.MinDeger + item.MaxDeger) / 2, item.MaxDeger)));
            //}
            //fsToprak.Output.Add(fvToprak);
            //#endregion
            //List<string> kurallar = new List<string>();

            //foreach (var KuralListItem in kuralKume.KuralList)
            //{
            //    string ruleText = KuralOlustur(KuralListItem) + " then (Toprak is " + KuralListItem.Sonuc + ")";
            //    kurallar.Add(ruleText);
            //}
            #endregion
        }