コード例 #1
0
 public void AddResult(FuzzyDecisionResult result)
 {
     if (_results.Contains(result) == false)
     {
         _results.Add(result);
     }
 }
コード例 #2
0
        public FuzzyDecisionResult DoDecision(List <float> inputs, FuzzyDecisionFunc func)
        {
            if (inputs.Count != _ranges.Count)
            {
                return(null);
            }

            // 根据输入值计算每个相关range的模糊值
            for (int i = 0; i < inputs.Count; i++)
            {
                _ranges[i].Calc(inputs[i]);
            }

            float retSum = 0;
            float maxRet = float.NegativeInfinity;
            FuzzyDecisionResult decisionRet = null;

            foreach (var result in _results)
            {
                // 根据调用方提供的模糊规则计算有关逻辑结果值
                result.ret = func.ExecRule(_ranges, ref result.id);
                if (result.ret > maxRet)
                {
                    maxRet      = result.ret;
                    decisionRet = result;
                }
                retSum += result.ret;
            }

            if (decisionRet != null)
            {
                // 遍历最终结果的每个解模糊值
                for (int i = 0; i < decisionRet.defuzzyValues.Count; i++)
                {
                    float sum = 0;
                    for (int ii = 0; ii < _results.Count; ii++)
                    {
                        FuzzyDecisionResult eachRet = _results[ii];
                        sum += (eachRet.defuzzyValues[i].value * eachRet.ret);
                    }
                    decisionRet.defuzzyValues[i].value = sum / retSum;
                }
            }

            return(decisionRet);
        }