Пример #1
0
        private double getRuleValue(Rule rule)
        {
            List <double> ruleValues = new List <double>();

            List <RuleItem> ins = rule.InputRules;

            for (int i = 0; i < ins.Count; i++)
            {
                FuzzySet set = searchByLingVariable(ins[i].Variable);
                if (set != null)
                {
                    FuzzyNumber num = set.searchByMemShipValue(ins[i].MemberShipValue);
                    if (num != null)
                    {
                        ruleValues.Add(num.FuzzyValue);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
            }
            return(Logic(ruleValues));
        }
Пример #2
0
        public List <FuzzySet> evaluateRules()
        {
            List <FuzzySet> OutSets = new List <FuzzySet>();

            for (int i = 0; i < _rules.Count; i++)
            {
                List <RuleItem> outrules       = _rules[i].OutputRules;
                double          firingStrength = getRuleValue(_rules[i]);
                if (firingStrength > 0)
                {
                    firedRules.Add(i + 1);
                    for (int j = 0; j < outrules.Count; j++)
                    {
                        String Var = outrules[j].Variable;
                        if (OutSets.Exists(delegate(FuzzySet f) { return(f.Variable == Var); }))
                        {
                            int    index = OutSets.FindIndex(delegate(FuzzySet f) { return(f.Variable == Var); });
                            String Mem   = outrules[j].MemberShipValue;
                            if (OutSets[index].Set.Exists(delegate(FuzzyNumber n) { return(n.MemberShipName == Mem); }))
                            {
                                int index2 = OutSets[index].Set.FindIndex(delegate(FuzzyNumber n) { return(n.MemberShipName == Mem); });
                                OutSets[index].Set[index2].FuzzyValue = Implication(OutSets[index].Set[index2].FuzzyValue, firingStrength);
                            }
                            else
                            {
                                FuzzyNumber num = new FuzzyNumber(Mem, firingStrength);
                                OutSets[index].Set.Add(num);
                            }
                        }
                        else
                        {
                            FuzzySet newset = new FuzzySet(Var);
                            newset.Set.Add(new FuzzyNumber(outrules[j].MemberShipValue, firingStrength));
                            OutSets.Add(newset);
                        }
                    }
                }
            }
            return(OutSets);
        }