⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fuzzyrule.cs

📁 在.net环境下用C#开发的模糊控制函数库
💻 CS
字号:
/*
 * 
 * fuzzynet: Fuzzy Logic Library for Microsoft .NET
 * Copyright (C) 2008 Dmitry Kaluzhny  (kaluzhny_dmitrie@mail.ru)
 * 
 * */

using System;
using System.Collections.Generic;

namespace AI.Fuzzy.Library
{
    /// <summary>
    /// And/Or operator type
    /// </summary>
    public enum OperatorType
    {
        And,
        Or
    }

    /// <summary>
    /// Hedge modifiers
    /// </summary>
    public enum HedgeType
    {
        None,
        Slightly,   // cube root
        Somewhat,   // square root
        Very,       // square
        Extremely   // cube
    }

    /// <summary>
    /// Interface of conditions used in the 'if' expression
    /// </summary>
    public interface ICondition
    {
    }

    /// <summary>
    /// Single condition
    /// </summary>
    public class SingleCondition : ICondition
    {
        FuzzyVariable _var = null;
        bool _not = false;
        FuzzyTerm _term = null;


        /// <summary>
        /// Default constructor
        /// </summary>
        public SingleCondition()
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="var">A linguistic variable to which the condition is related</param>
        /// <param name="func">A term in expression 'var is term'</param>
        public SingleCondition(FuzzyVariable var, FuzzyTerm term)
        {
            _var = var;
            _term = term;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="var">A linguistic variable to which the condition is related</param>
        /// <param name="func">A term in expression 'var is term'</param>
        /// <param name="not">Does condition contain 'not'</param>
        public SingleCondition(FuzzyVariable var, FuzzyTerm term, bool not) : this(var, term)
        {
            _not = not;
        }

        /// <summary>
        /// A linguistic variable to which the condition is related
        /// </summary>
        public FuzzyVariable Var
        {
            get { return _var; }
            set { _var = value; }
        }

        /// <summary>
        /// Is MF inverted
        /// </summary>
        public bool Not
        {
            get { return _not; }
            set { _not = value; }
        }

        /// <summary>
        /// A term in expression 'var is term'
        /// </summary>
        public FuzzyTerm Term
        {
            get { return _term; }
            set { _term = value; }
        }
    }

    /// <summary>
    /// Several conditions linked by or/and operators
    /// </summary>
    public class Conditions : ICondition
    {
        bool _not = false;
        OperatorType _op = OperatorType.And;
        List<ICondition> _conditins = new List<ICondition>();

        /// <summary>
        /// Is MF inverted
        /// </summary>
        public bool Not
        {
            get { return _not; }
            set { _not = value; }
        }

        /// <summary>
        /// Operator that links expressions (and/or)
        /// </summary>
        public OperatorType Op
        {
            get { return _op; }
            set { _op = value; }
        }

        /// <summary>
        /// A list of conditions (single or multiples)
        /// </summary>
        public List<ICondition> Conditins
        {
            get { return _conditins; }
        }
    }

    /// <summary>
    /// Fuzzy rule
    /// </summary>
    public class FuzzyRule
    {
        List<FuzzyVariable> _input = new List<FuzzyVariable>();
        List<FuzzyVariable> _output = new List<FuzzyVariable>();

        Conditions _condition = new Conditions();
        SingleCondition _conclusion = new SingleCondition();
        double _weight = 1.0;

        /// <summary>
        /// Constructor. NOTE: a rule cannot be created directly, only throw FuzzySystem::NewRule method.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        internal FuzzyRule(List<FuzzyVariable> input, List<FuzzyVariable> output)
        {
            _input = input;
            _output = output;
        }

        /// <summary>
        /// Condition (IF) part
        /// </summary>
        public Conditions Condition
        {
            get { return _condition; }
            set { _condition = value; }
        }

        /// <summary>
        /// Conclusion (THEN) part
        /// </summary>
        public SingleCondition Conclusion
        {
            get { return _conclusion; }
            set { _conclusion = value; }
        }

        /// <summary>
        /// Weight of the rule
        /// </summary>
        public double Weight
        {
            get { return _weight; }
            set { _weight = value; }
        }

        #region Rule parsing

        internal static FuzzyRule Parse(string rule, List<FuzzyVariable> input, List<FuzzyVariable> output)
        {
            return RuleParser.Parse(rule, input, output);
        }

        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -