Пример #1
0
        public void Visit(AndStatement statement)
        {
            var expression = VisitChild(statement.Expression);

            var orStatements = ProcessBinary(statement.Statements, CodeBinaryOperatorType.BooleanOr);

            if (orStatements == null)
            {
                _codeStack.Peek().Expression = expression.Expression;
            }
            else
            {
                _codeStack.Peek().Expression = new CodeBinaryOperatorExpression(expression.Expression, CodeBinaryOperatorType.BooleanOr, orStatements);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var points = new LinguisticType("Рейтинговые баллы");

            points.CreateTerm("Мало", 20, 5, TermType.Left);
            points.CreateTerm("Средне", 40, 20);
            points.CreateTerm("Много", 70, 10, TermType.Right);

            var skips = new LinguisticType("Пропуски");

            skips.CreateTerm("Мало", 0, 10, TermType.Left);
            skips.CreateTerm("Средне", 5, 5);
            skips.CreateTerm("Много", 10, 10, TermType.Right);

            var studentPoints = points.CreateVariable("Баллы студента");

            studentPoints.Value = points.GetValue(10.0);
            var studentSkips = skips.CreateVariable("Пропуски студента");

            studentSkips.Value = skips.GetValue(20.0);

            var statement1 = new OrStatement(
                new AtomicStatement(studentPoints, points["Мало"]),
                new AtomicStatement(studentSkips, skips["Много"]));


            var call = new LinguisticType("Необходимость звонка", 0, 10);

            call.CreateTerm("Срочно звонить", 0, 4, TermType.Left);
            call.CreateTerm("Поговорить на собрании", 5, 4);
            call.CreateTerm("Не звонить", 10, 4, TermType.Right);

            var statement2 = new AndStatement(
                new AtomicStatement(studentPoints, points["Много"]),
                new AtomicStatement(studentSkips, skips["Мало"]));

            var ruleset = new MISORuleSet(call);

            ruleset.AddRule(statement1, call["Срочно звонить"]);
            ruleset.AddRule(statement2, call["Не звонить"]);

            Console.WriteLine(studentPoints);
            Console.WriteLine(studentSkips);

            Console.WriteLine(ruleset);
            Console.WriteLine(call.GetValue(ruleset.GetResult().Defuzzify()));
        }
        /// <summary>
        /// Parses a logical parameter from a string.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        private LogicalParameter Parse(string s)
        {
            List <LogicalParameter> components = new List <LogicalParameter>();
            bool   inOr         = false;
            string currentTrait = "";

            foreach (char c in s)
            {
                if (c == '(')
                {
                    inOr = true;
                }
                else if (c == ')')
                {
                    inOr = false;
                    AndStatement and = (AndStatement)Parse(currentTrait);
                    OrStatement  or  = new OrStatement(and.Components);
                    components.Add(or);
                    currentTrait = "";
                }
                else if (c == ' ' && !inOr)
                {
                    components.Add(new Atom(currentTrait));
                    currentTrait = "";
                }
                else
                {
                    currentTrait += c;
                }
            }

            if (currentTrait != "")
            {
                components.Add(new Atom(currentTrait));
            }

            return(new AndStatement(components));
        }
Пример #4
0
 public void Visit(AndStatement statement, CommonTree tree)
 {
     Parent(tree).Children.Add(statement);
     VisitChildren(tree);
 }