public void ReadConditionsFromXmlStringTest()
        {
            var result = ProblemConditionsHelper.ReadConditionsFromXmlString(Resources.input);

            Assert.IsTrue(result.Success);
            Assert.IsNotNull(result.Data);

            Assert.AreEqual(result.Data.Variables.Count, 3);
            Assert.AreEqual(result.Data.Rules.Count, 12);

            Assert.IsTrue(result.Data.Variables.Any(x => x.Name == "X1"));
            Assert.IsTrue(result.Data.Variables.Any(x => x.Name == "X1" && x.Terms.Any(t => t.Name == "низкий")));

            Assert.IsTrue(result.Data.Variables.Any(x => x.Name == "Y" && x.IsResult) && result.Data.Variables.Where(x => x.Name != "Y").All(x => !x.IsResult));

            Assert.IsTrue(result.Data.Rules.All(x => x.Conditions.Any(c => c.FuzzyVariable.Name == "X1") &&
                                                x.Conditions.Any(c => c.FuzzyVariable.Name == "X2") &&
                                                x.Conclusion.FuzzyVariable.Name == "Y"));
        }
        public void MamdaniServiceTestMethod1()
        {
            var solveResultPattern       = 0.34375;
            var result                   = ProblemConditionsHelper.ReadConditionsFromXmlString(Resources.input);
            var mamdaniService           = new MamdaniService();
            ProblemConditions conditions = new ProblemConditions()
            {
                Rules = result.Data.Rules, Variables = result.Data.Variables
            };

            var problem = new Problem()
            {
                InputData         = new double[] { 0.6, 0.8 },
                ProblemConditions = conditions
            };

            var solveResult = mamdaniService.SolveProblem(problem);

            Assert.IsTrue(Math.Abs(solveResult.Data - solveResultPattern) < 1e-3);
        }
Example #3
0
        private void task1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var result = ProblemConditionsHelper.ReadConditionsFromXmlString(Resources.input1);

            if (!result.Success)
            {
                MessageBox.Show("Во время загрузки задачи возникли непридвиденные ошибки", "Ошибка",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            _variables.Clear();
            _variables.AddRange(result.Data.Variables);

            _rules.Clear();
            _rules.AddRange(result.Data.Rules);

            inputDataTextBox.Text = "";

            RefreshVariablesListView();
            RefreshRulesListView();
        }