Exemplo n.º 1
0
        internal void Count_WhenNoRulesInRulebase_ReturnsZero()
        {
            // Arrange
            var rulebase = new Rulebase();

            // Act
            // Assert
            Assert.Equal(0, rulebase.Count);
        }
Exemplo n.º 2
0
        internal void GetRules_WhenNoRuleInRulebase_ReturnsDictionaryWithCountZero()
        {
            // Arrange
            var rulebase = new Rulebase();

            // Act
            var result = rulebase.GetAllRules().Count;

            // Assert
            Assert.Equal(0, result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new Fuzzy <see cref="InferenceSystem"/>.
        /// </summary>
        ///
        /// <param name="defuzzifier">A defuzzyfier method used to evaluate the numeric otput
        /// of the system.</param>
        /// <param name="normOperator">A <see cref="INorm"/> operator used to evaluate the norms
        /// in the <see cref="InferenceSystem"/>. For more information of the norm evaluation see <see cref="Rule"/>.</param>
        /// <param name="conormOperator">A <see cref="ICoNorm"/> operator used to evaluate the
        /// conorms in the <see cref="InferenceSystem"/>. For more information of the conorm evaluation see <see cref="Rule"/>.</param>
        ///
        public InferenceSystem(DefuzzificationMethod defuzzificationMethod, INorm normOperator, ICoNorm conormOperator)
        {
            this.defuzzificationMethod = defuzzificationMethod;
            this.normOperator          = normOperator;
            this.conormOperator        = conormOperator;

            this.database        = new Database();
            this.rulebase        = new Rulebase();
            this.inputVariables  = new HashSet <string>();
            this.outputVariables = new HashSet <string>();
        }
Exemplo n.º 4
0
        internal void Add_AddsRuleToRulebase()
        {
            // Arrange
            var rulebase = new Rulebase();
            var rule     = StubFuzzyRuleFactory.Create("Rule1");

            // Act
            rulebase.AddRule(rule);

            // Assert
            Assert.Equal(1, rulebase.Count);
        }
Exemplo n.º 5
0
        internal void GetRule_WhenRuleInRulebase_ReturnsExpectedCountOfRules()
        {
            // Arrange
            var rulebase = new Rulebase();
            var rule     = StubFuzzyRuleFactory.Create("Rule1");

            rulebase.AddRule(rule);

            // Act
            var result = rulebase.GetRule(Label.Create("Rule1"));

            // Assert
            Assert.Equal(rule, result);
        }
        public Session CreateSession()
        {
            if (Rulebase == null)
            {
                using (var stream = _rulebaseStreamProvider.GetStream())
                {
                    using (var rulebaseStream = new InputStreamAdapter(stream))
                    {
                        Rulebase = Engine.INSTANCE.GetRulebase(rulebaseStream);
                    }
                }
            }

            return(Engine.INSTANCE.CreateSession(Rulebase));
        }
Exemplo n.º 7
0
        internal void GetRules_RulesInRulebase_ReturnsDictionaryWithCountZero()
        {
            // Arrange
            var rulebase = new Rulebase();
            var rule1    = StubFuzzyRuleFactory.Create("Rule1");
            var rule2    = StubFuzzyRuleFactory.Create("Rule2");

            rulebase.AddRule(rule1);
            rulebase.AddRule(rule2);

            // Act
            var result = rulebase.GetAllRules();

            // Assert
            Assert.Equal(2, result.Count);
        }
Exemplo n.º 8
0
        internal void DeleteRule_WhenRuleInRulebase_ReturnsExpectedCountOfRules()
        {
            // Arrange
            var rulebase = new Rulebase();
            var rule     = StubFuzzyRuleFactory.Create("Rule1");

            rulebase.AddRule(rule);
            var countAfterAddingRule = rulebase.Count;

            // Act
            rulebase.DeleteAllRules();

            // Assert
            Assert.Equal(1, countAfterAddingRule);
            Assert.Equal(0, rulebase.Count);
        }
        /// <summary>
        /// Run, this is the command action for rulebase execution.
        /// the interaction state will become 'is busy'
        /// </summary>
        public async void Run()
        {
            using (State.BusyScope())
            {
                Emitter.Publish(CommonLocalised.LineDivider);
                Emitter.Publish(CommonLocalised.CommencingRunFormat, DateTime.Now.AsUKDatetime());
                Emitter.Publish(CommonLocalised.LineDivider);

                var session = SessionFactory.Create(RuleSet.SelectedRules, Prepared.SelectedSource);

                var context = ContextFactory.Create(
                    Prepared.SQLInstance,
                    Prepared.DBUser,
                    Prepared.DBPassword,
                    Prepared.SelectedSource,
                    Prepared.RunMode,
                    Prepared.UseSourceForResults,
                    Prepared.DepositRulebaseArtefacts,
                    Prepared.SelectedReturnPeriod);

                await Rulebase.Run(session, context, Boolean.Parse(Prepared.SaveResults));
            }
        }