Ejemplo n.º 1
0
        public void RuleSetReportingSizeCheckMultiTop()
        {
            RuleMSX rmsx = new RuleMSX();

            string newRuleSetName = "TestRuleSet";

            RuleSet rs = rmsx.createRuleSet(newRuleSetName);

            rs.AddRule(new Rule("TestRule1", new GenericBoolRule(true), rmsx.createAction("TestAction1", new GenericAction("TestAction1"))));
            Rule r2 = new Rule("TestRule2", new GenericBoolRule(false), rmsx.createAction("TestAction4", new GenericAction("TestAction4")));

            rs.AddRule(r2);
            r2.AddRule(new Rule("TestRule5", new GenericBoolRule(true), rmsx.createAction("TestAction3", new GenericAction("TestAction3"))));
            r2.AddRule(new Rule("TestRule6", new GenericBoolRule(false), rmsx.createAction("TestAction5", new GenericAction("TestAction5"))));
            rs.AddRule(new Rule("TestRule3", new GenericBoolRule(false)));
            Rule r4 = new Rule("TestRule4", new GenericBoolRule(true), rmsx.createAction("TestAction2", new GenericAction("TestAction2")));

            rs.AddRule(r4);
            r4.AddRule(new Rule("TestRule7", new GenericBoolRule(false), rmsx.createAction("TestAction6", new GenericAction("TestAction6"))));
            r4.AddRule(new Rule("TestRule8", new GenericBoolRule(true), rmsx.createAction("TestAction7", new GenericAction("TestAction7"))));

            string report = rs.report();

            System.Console.WriteLine(report);

            Assert.That(report.Length, Is.EqualTo(664));
        }
Ejemplo n.º 2
0
    void Start()
    {
        vector       = new Vector();
        savedVectors = new List <Vector>();

        allRules = new List <RuleSet>();

        axiom = Rule.GetRulesFromString("I");

        sizeLine         = Random.Range(2f, 7.5f);
        widthLine        = Random.Range(sizeLine / 2, sizeLine * 2);
        angle            = Random.Range(40f, 80f);
        widthScaleFactor = Random.Range(0.9f, 0.98f);

        rules = new RuleSet();
        rules.AddRule('I', "FS");
        rules.AddRule('S', "[[F-F+&SF*]F&[^F+F-FS]]");
        allRules.Add(rules);

        rules = new RuleSet();
        rules.AddRule('I', "FFS");
        rules.AddRule('S', "F[+F&-F+F-F^F*][-^&F+[F-F^F&+^F*]*]");
        allRules.Add(rules);

        foreach (Rule r in axiom)
        {
            r.Run(this);
        }
    }
Ejemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        List <Variable> vars = new List <Variable>();

        vars.Add(new Variable('S', branchTime));
        vars.Add(new Variable('X', branchTime));
        vars.Add(new Variable('F', maxStemAge));

        RuleSet rules   = new RuleSet();
        Symbol  maxSSym = new Symbol('S', branchTime);
        Symbol  maxXSym = new Symbol('X', branchTime);

        rules.AddRule(maxSSym, 0.3f, new SymbolString("[@[@/@/@+@FAXA]@\\@+@FAXA]@\\@-@FAXA"));
        rules.AddRule(maxSSym, 0.3f, new SymbolString("[@\\@+@FAXA]@\\@-@FAXA"));
        rules.AddRule(maxSSym, 0.2f, new SymbolString("FAXA"));

        rules.AddRule(maxXSym, 0.16f, new SymbolString("[@[@\\@\\@+@FAXA]@/@+@FAXA]@/@-@FAXA"));
        rules.AddRule(maxXSym, 0.16f, new SymbolString("[@[@/@/@+@FAXA]@\\@+@FAXA]@\\@-@FAXA"));
        rules.AddRule(maxXSym, 0.32f, new SymbolString("[@\\@+@FAXA]@\\@-@FAXA"));
        rules.AddRule(maxXSym, 0.32f, new SymbolString("[@/@+@FAXA]@/@-@FAXA"));
        rules.AddRule(maxXSym, 0.03f, new SymbolString("\\@-@FAXA"));
        rules.AddRule(maxXSym, 0.03f, new SymbolString("/@-@FAXA"));

        this.lSystem = new LSystem(vars, new Symbol('S', 10), rules, yaw, pitch, roll, numIterations);
        if (root == null)
        {
            root     = Instantiate <Stem>(stemPrefab, transform.position, transform.rotation);
            root.age = 1;
        }
    }
Ejemplo n.º 4
0
        //TESTING/DEMO ONLY!!!
        public string FireMergeEngine()
        {
            var readyToMerge = S3Interface.GetReadyToMerge();

            foreach (var m in readyToMerge)
            {
                var ccdList  = S3Interface.GetMergeSetCcds(Guid.Parse(m)).Select(x => XDocument.Parse(x)).ToList();
                var sRuleSet = S3Interface.GetMergeSetRules(Guid.Parse(m));

                RuleSet ruleSet;

                if (!sRuleSet.Contains("{\"UseDefault\": \"true\"}"))
                {
                    ruleSet = new RuleSet(sRuleSet);
                }
                else
                {
                    ruleSet = new RuleSet();
                    ruleSet.AddRule("StripText", 0, RuleType.PreFormat);
                    ruleSet.AddRule("PrimaryMergeRuleWithValidation", 0, RuleType.Primary);
                    ruleSet.AddRule("MedicationRule1", 0, RuleType.DeDuplication);
                    ruleSet.AddRule("AlertsSection", 0, RuleType.DeDuplication);
                    ruleSet.AddRule("SocialHistory_EtohUser", 0, RuleType.DeDuplication);
                    ruleSet.AddRule("SocialHistory_SmokingConsolidation", 0, RuleType.DeDuplication);
                    ruleSet.AddRule("TestProblemsDedup", 0, RuleType.DeDuplication);
                    ruleSet.AddRule("AddFormatedText", 0, RuleType.PostFormat);
                }


                S3Interface.AddMergedZip(Guid.Parse(m), RunMerge.runMergeWithRuleSet(ccdList, ruleSet, Guid.Parse(m), ""));
            }

            return(string.Empty);
        }
Ejemplo n.º 5
0
 public void ShouldForwardChainRules()
 {
     var ruleBase = new RuleBase<Target>();
     var ruleSet = new RuleSet<Target>();
     var rule = new Rule<Target>("rule 1", "description of rule 1", t => t.Number == 0, t => t.Number = 1);
     var rule2 = new Rule<Target>("rule 2", "", t => t.Number == 1, t => t.Number = 2);
     ruleSet.AddRule(rule);
     ruleSet.AddRule(rule2);
     ruleBase.AddRuleSet(ruleSet);
     var target = new Target();
     var ruleEngine = new RuleEngine<Target>(ruleBase);
     ruleEngine.Execute(target);
     Assert.Equal(2, target.Number);
 }
Ejemplo n.º 6
0
        private void BuildRules()
        {
            log("Building rules...");

            log("Creating RuleSet rsAutoRouteFromIOI");
            RuleSet rsAutoRouteFromIOI = this.rmsx.CreateRuleSet("AutoRouteFromIOI");

            log("Creating rule for ValidIOI");
            Rule ruleValidIOI = rsAutoRouteFromIOI.AddRule("ValidIOI");

            /* ioi must be instrument type 'stock'
             * ioi must not be expired */

            ruleValidIOI.AddRuleCondition(new RuleCondition("IsStockInstrumentType", new GenericStringMatch("ioitype", "stock")));
            ruleValidIOI.AddRuleCondition(new RuleCondition("IsNotExpired", new IsIOINotExpired()));

            ruleValidIOI.AddAction(this.rmsx.CreateAction("MarkIOIValid", ActionType.ON_TRUE, new MarkIOIValid()));

            Action purgeDataSet = this.rmsx.CreateAction("PurgeDataSet", ActionType.ON_FALSE, new PurgeDataSet(rsAutoRouteFromIOI));

            ruleValidIOI.AddAction(purgeDataSet);

            log("Creating rule for ValidOrder");
            Rule ruleValidOrder = rsAutoRouteFromIOI.AddRule("ValidOrder");

            /* Order must be for Equity */

            ruleValidOrder.AddRuleCondition(new RuleCondition("IsEquity", new GenericStringMatch("orderAssetClass", "Equity")));

            ruleValidOrder.AddAction(this.rmsx.CreateAction("MarkOrderValid", ActionType.ON_TRUE, new MarkOrderValid()));
            ruleValidOrder.AddAction(purgeDataSet);

            log("Creating rule for ValidPair");
            Rule ruleValidPair = rsAutoRouteFromIOI.AddRule("ValidPair");

            /* both order and ioi must be valid
             * matching side
             */

            ruleValidPair.AddRuleCondition(new RuleCondition("IOIAndOrderReady", new IOIAndOrderReady()));
            ruleValidPair.AddRuleCondition(new RuleCondition("MatchingTicker", new MatchingTicker()));
            ruleValidPair.AddRuleCondition(new RuleCondition("MatchingSide", new MatchingSideAndAmount()));

            /* Create new route */

            ruleValidPair.AddAction(this.rmsx.CreateAction("CreateRoute", ActionType.ON_TRUE, new CreateRoute(this)));
            ruleValidOrder.AddAction(purgeDataSet);
        }
Ejemplo n.º 7
0
        public void RuleSet(params RuleExpression <TTarget>[] ruleExpressions)
        {
            var ruleSet = new RuleSet <TTarget>();

            ruleExpressions.ToList().ForEach(ruleExpression => ruleSet.AddRule(ruleExpression));
            _ruleBaseExpression.AddRuleSet(ruleSet);
        }
Ejemplo n.º 8
0
        public void SingleRuleITest()
        {
            Log.logLevel = Log.LogLevels.DETAILED;
            RuleMSX rmsx = new RuleMSX();

            string newRuleSetName = "SingleIterationRuleSet";
            string newDataSetName = "SingleIterationDataSet";
            string newRuleName    = "IsBooleanTrue";
            string actionMessage  = "ActionMessage";

            RuleSet rs = rmsx.createRuleSet(newRuleSetName);
            DataSet ds = rmsx.createDataSet(newDataSetName);

            RuleAction rai = rmsx.createAction("RuleActionIn", new GenericAction(actionMessage));

            Rule r = new Rule(newRuleName, new GenericBoolRule(true), rai);

            rs.AddRule(r);

            ds.addDataPoint("TestDataPoint", new StringDataPoint("test_data_point"));

            rs.Execute(ds);

            // We have to wait for the action to take place. Under normal circumstances there
            // would be no interation with the data from outside the evaluators/actions.
            System.Threading.Thread.Sleep(100);

            GenericAction rao = (GenericAction)rai.getExecutor();

            Assert.That(rao.getOutgoing(), Is.EqualTo(actionMessage));
        }
Ejemplo n.º 9
0
        private void BuildRules()
        {
            log("Building rules...");

            log("Creating RuleCondition condRouteFillOccurred");
            RuleCondition condRouteFillOccurred = new RuleCondition("RouteFillOccurred", new RouteFillOccurred(this));

            log("RuleCondition condRouteFillOccurred created.");

            log("Creating Action actShowRouteFill");
            Action actShowRouteFill = this.rmsx.CreateAction("ShowRouteFill", new ShowRouteFill(this));

            log("Action actShowRouteFill created");

            log("Creating RuleSet demoRouteRuleSet");
            RuleSet demoRouteRuleSet = this.rmsx.CreateRuleSet("DemoRouteRuleSet");

            log("RuleSet demoRouteRuleSet created");

            log("Creating Rule ruleRouteFilled");
            Rule ruleRouteFilled = demoRouteRuleSet.AddRule("RouteFilled");

            log("Rule ruleRouteFilled created");

            log("Assign RuleCondition condRouteFillOccurred to Rule ruleRouteFilled");
            ruleRouteFilled.AddRuleCondition(condRouteFillOccurred);

            log("Assign Action actShowRouteFill to Rule ruleRouteFilled");
            ruleRouteFilled.AddAction(actShowRouteFill);

            log("Rules built.");
        }
Ejemplo n.º 10
0
        private static void AddDefaultRuleSet(List <RuleExpression <TTarget> > ruleExpressions, RuleBase <TTarget> ruleBase)
        {
            var defaultRuleSet = new RuleSet <TTarget>();

            ruleExpressions.ForEach(ruleBuilder => defaultRuleSet.AddRule(ruleBuilder));
            ruleBase.AddRuleSet(defaultRuleSet);
        }
        public void ShouldForwardChainRules()
        {
            var ruleBase = new RuleBase <Target>();
            var ruleSet  = new RuleSet <Target>();
            var rule     = new Rule <Target>("rule 1", "description of rule 1", t => t.Number == 0, t => t.Number = 1);
            var rule2    = new Rule <Target>("rule 2", "", t => t.Number == 1, t => t.Number = 2);

            ruleSet.AddRule(rule);
            ruleSet.AddRule(rule2);
            ruleBase.AddRuleSet(ruleSet);
            var target     = new Target();
            var ruleEngine = new RuleEngine <Target>(ruleBase);

            ruleEngine.Execute(target);
            Assert.Equal(2, target.Number);
        }
        private void AddRulesToRuleSet(List <RuleExpression <T> > ruleExpressions)
        {
            var ruleSet = new RuleSet <T>();

            ruleExpressions.ForEach(ruleExpression => ruleSet.AddRule(ruleExpression));
            AddRuleSet(ruleSet);
        }
Ejemplo n.º 13
0
        public void RuleSetAddRuleGetRuleShouldReturnNewRule()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";
            string  newRuleName    = "Rule1";
            RuleSet rs             = rmsx.CreateRuleSet(newRuleSetName);

            rs.AddRule(newRuleName);
            Assert.That(rs.GetRule(newRuleName).GetName(), Is.EqualTo(newRuleName));
        }
Ejemplo n.º 14
0
        public static RuleSet GetDefaultRuleset()
        {
            var retVal = new RuleSet();

            retVal.AddRule("StripText", 0, RuleType.PreFormat);
            retVal.AddRule("PrimaryMergeRuleWithValidation", 0, RuleType.Primary);
            retVal.AddRule("Author", 0, RuleType.DeDuplication);
            retVal.AddRule("Confidentiality", 0, RuleType.DeDuplication);
            retVal.AddRule("MedicationRule1", 0, RuleType.DeDuplication);
            retVal.AddRule("SocialHisotry_EtohUse", 0, RuleType.DeDuplication);
            retVal.AddRule("SocialHistory_SmokingConsolidation", 0, RuleType.DeDuplication);
            retVal.AddRule("TestProblemsDedup", 0, RuleType.DeDuplication);
            retVal.AddRule("AddFormatedText", 0, RuleType.PostFormat);

            return(retVal);
        }
        public void TestInitialize()
        {
            _ruleset = new RuleSet();
            Tuple <char, int>[] itemCountPairList = new Tuple <char, int>[]
            {
                new Tuple <char, int>('C', 1),
                new Tuple <char, int>('D', 1)
            };
            _ruleset.AddRule(new PromoRule(itemCountPairList, 30));

            _ruleset.AddRule(new PromoRule('A', 3, 130));
            _ruleset.AddRule(new PromoRule('B', 2, 45));

            _itemPricePair = new Dictionary <char, int>()
            {
                { 'A', 50 },
                { 'B', 30 },
                { 'C', 20 },
                { 'D', 15 }
            };
        }
Ejemplo n.º 16
0
        public void GetRulesReturnsCorrectListOfRules()
        {
            RuleMSX     rmsx           = new RuleMSX();
            string      newRuleSetName = "NewRuleSet";
            string      newRuleName    = "NewRuleName";
            RuleSet     rs             = rmsx.CreateRuleSet(newRuleSetName);
            Rule        ri             = rs.AddRule(newRuleName);
            List <Rule> rl             = rs.GetRules();
            Rule        ro             = rl[0];

            Assert.That(ro.GetName(), Is.EqualTo(newRuleName));
        }
Ejemplo n.º 17
0
        static void De_Duplicate()
        {
            //Create a ccd list of XDocuments



            Stopwatch sw = new Stopwatch();
            RuleSet   ruleSet;

            ruleSet = new RuleSet();
            // ruleSet.AddRule("StripText", 0, RuleType.PreFormat);
            ruleSet.AddRule("PrimaryMergeRuleWithValidation", 0, RuleType.Primary);
            ruleSet.AddRule("Author", 0, RuleType.DeDuplication);
            ruleSet.AddRule("Confidentiality", 0, RuleType.DeDuplication);
            ruleSet.AddRule("MedicationRule1", 0, RuleType.DeDuplication);
            ruleSet.AddRule("AlertsSection", 0, RuleType.DeDuplication);
            //ruleSet.AddRule("SocialHistory_DailyCaffeine", 0, RuleType.DeDuplication);
            //ruleSet.AddRule("SocialHistory_EtohUser", 0, RuleType.DeDuplication);
            //ruleSet.AddRule("SocialHistory_SmokingConsolidation", 0, RuleType.DeDuplication);
            ruleSet.AddRule("VitalSigns", 0, RuleType.DeDuplication);
            ruleSet.AddRule("TestProblemsDedup", 0, RuleType.DeDuplication);
            // ruleSet.AddRule("AddFormatedText", 0, RuleType.PostFormat);

            string guid = "{3F2504E0-4F89-41D3-9A0C-0305E82C3301}";


            foreach (string folder in Directory.GetDirectories(folderPath))
            {
                string fileName = Path.GetFileName(folder);

                var ccdList = new List <XDocument>();
                foreach (string file in Directory.GetFiles(folder))
                {
                    ccdList.Add(XDocument.Load(file));
                }



                sw.Start();
                Stream ms = RunMerge.runMergeWithRuleSet(ccdList, ruleSet, Guid.Parse(guid), fileName);
                sw.Stop();
            }
            Console.WriteLine("------------------ Consolidation is done! --------------------------");

            Console.WriteLine("CountDedup.txt", "Vital Count: " + DeDupRule.vitalDedupCount);
            Console.WriteLine("Problem Count: " + DeDupRule.problemsDedupCount);
            Console.WriteLine("Alert Count: " + DeDupRule.alertDedupCount);
            Console.WriteLine("Medication Count: " + DeDupRule.medicationDedupCount);
            Console.WriteLine("Confidentiality Count: " + DeDupRule.confidentialityDedupCount);
            Console.WriteLine("Author Count: " + DeDupRule.authorDedupCount);
            Console.WriteLine("Overall deduplication time: " + sw.Elapsed);


            Console.ReadKey();
        }
Ejemplo n.º 18
0
        public void RuleSet_Simple()
        {
            RuleSet <bool> rs = new RuleSet <bool>(TestSetup.BoolRegistrySimple);

            rs.AddRule(RuleNames.R001); //True
            rs.AddRule(RuleNames.R002); //False
            rs.AddRule(RuleNames.R003); //True
            rs.AddRule(RuleNames.R004); //False
            rs.AddRule(RuleNames.R005); //True
            rs.AddRule(RuleNames.R006); //False

            var results = rs.Execute();

            IRuleResult <bool> result;

            result = results[RuleNames.R001];
            Assert.IsTrue(result.Result);

            result = results[RuleNames.R002];
            Assert.IsFalse(result.Result);

            result = results[RuleNames.R003];
            Assert.IsTrue(result.Result);

            result = results[RuleNames.R004];
            Assert.IsFalse(result.Result);

            result = results[RuleNames.R005];
            Assert.IsTrue(result.Result);

            result = results[RuleNames.R006];
            Assert.IsFalse(result.Result);
        }
Ejemplo n.º 19
0
        private void BuildRules()
        {
            log("Building rules...");

            log("Creating RuleSet rsOrderStates");
            RuleSet rsOrderStates = this.rmsx.CreateRuleSet("OrderStates");

            log("Creating rule for ORDER_NEW");
            Rule ruleOrderNew = rsOrderStates.AddRule("OrderNew");

            ruleOrderNew.AddRuleCondition(new RuleCondition("OrderNew", new OrderNew()));
            ruleOrderNew.AddAction(this.rmsx.CreateAction("ShowOrderNew", new ShowOrderState(this, "New Order")));
        }
        public void RuleGetEvaluatorReturnsCorrectEvaluator()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";
            string  newDataSetName = "NewDataSet";
            string  newRuleName    = "Rule1";
            RuleSet rs             = rmsx.createRuleSet(newRuleSetName);
            Rule    r  = new Rule(newRuleName, new GenericBoolRule(true));
            DataSet ds = rmsx.createDataSet(newDataSetName);

            rs.AddRule(r);
            Assert.That(r.GetEvaluator().Evaluate(ds), Is.EqualTo(true));
        }
        public void RuleMSXStopShouldReturnTrueWithActiveRuleSet()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";
            string  newDataSetName = "NewDataSet";
            string  newRuleName    = "Rule1";
            RuleSet rs             = rmsx.createRuleSet(newRuleSetName);
            Rule    r  = new Rule(newRuleName, new GenericBoolRule(true));
            DataSet ds = rmsx.createDataSet(newDataSetName);

            rs.AddRule(r);
            rs.Execute(ds);
            Assert.That(rmsx.Stop(), Is.EqualTo(true));
        }
        public void RuleMSXStopShouldReturnTrueWithUnexecutedRuleSet()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";
            string  newDataSetName = "NewDataSet";
            string  newRuleName    = "Rule1";
            RuleSet rs             = rmsx.createRuleSet(newRuleSetName);
            Rule    r  = new Rule(newRuleName, new GenericBoolRule(true));
            DataSet ds = rmsx.createDataSet(newDataSetName);

            rs.AddRule(r);
            // We are deliberately not executing the ruleset...
            //rs.Execute(ds);
            Assert.That(rmsx.Stop(), Is.EqualTo(true));
        }
Ejemplo n.º 23
0
        public void ShouldExecuteRuleEngineOnSeveralTargets()
        {
            var ruleBase = new RuleBase<Target>();
            var ruleSet = new RuleSet<Target>();
            var rule = new Rule<Target>("rule 1", "", t => t.Number == 0, t => t.Number = 1);
            ruleSet.AddRule(rule);
            ruleBase.AddRuleSet(ruleSet);
            var ruleEngine = new RuleEngine<Target>(ruleBase);

            var target = new Target();
            ruleEngine.Execute(target);
            Assert.Equal(1, target.Number);
            var newTarget = new Target();
            ruleEngine.Execute(newTarget);
            Assert.Equal(1, newTarget.Number);
        }
        public void ShouldExecuteRuleEngineOnSeveralTargets()
        {
            var ruleBase = new RuleBase <Target>();
            var ruleSet  = new RuleSet <Target>();
            var rule     = new Rule <Target>("rule 1", "", t => t.Number == 0, t => t.Number = 1);

            ruleSet.AddRule(rule);
            ruleBase.AddRuleSet(ruleSet);
            var ruleEngine = new RuleEngine <Target>(ruleBase);

            var target = new Target();

            ruleEngine.Execute(target);
            Assert.Equal(1, target.Number);
            var newTarget = new Target();

            ruleEngine.Execute(newTarget);
            Assert.Equal(1, newTarget.Number);
        }
Ejemplo n.º 25
0
        public void AddRuleRangeTest()
        {
            RuleSet rules = RuleSet.FromDirectory(Path.Combine("rules", "valid"), null);

            // Add Range
            RuleSet testRules = new RuleSet();

            testRules.AddRange(rules.ByLanguages(new string[] { "javascript" }));
            Assert.IsTrue(testRules.Count() > 0, "AddRange testRules is empty");

            // Add Rule
            testRules = new RuleSet();
            IEnumerable <Rule> list = rules.ByLanguages(new string[] { "javascript" });

            foreach (Rule r in list)
            {
                testRules.AddRule(r);
            }

            Assert.IsTrue(testRules.Count() > 0, "AddRule testRules is empty");
        }
Ejemplo n.º 26
0
        public void RuleSetReportingSizeCheckSingleRule()
        {
            RuleMSX rmsx = new RuleMSX();

            string newRuleSetName = "TestRuleSet";
            string newDataSetName = "TestDataSet";
            string newRuleName    = "IsBooleanTrue";

            RuleSet rs = rmsx.createRuleSet(newRuleSetName);
            DataSet ds = rmsx.createDataSet(newDataSetName);

            Rule r = new Rule(newRuleName, new GenericBoolRule(true));

            rs.AddRule(r);

            string report = rs.report();

            System.Console.WriteLine(report);

            Assert.That(report.Length, Is.EqualTo(126));
        }
        public void RuleAddActionGetActionReturnsCorrectAction()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";
            string  newDataSetName = "NewDataSet";
            string  newRuleName    = "Rule1";
            string  actionMessage  = "ActionMessage";
            RuleSet rs             = rmsx.createRuleSet(newRuleSetName);
            DataSet ds             = rmsx.createDataSet(newDataSetName);
            Rule    r = new Rule(newRuleName, new GenericBoolRule(true));

            rs.AddRule(r);
            RuleAction rai = rmsx.createAction("RuleActionIn", new GenericAction(actionMessage));

            r.AddAction(rai);
            ActionExecutor rae = r.GetActions()[0].getExecutor();

            rae.Execute(ds);
            GenericAction ga = (GenericAction)rae;

            Assert.That(ga.getOutgoing, Is.EqualTo(actionMessage));
        }
Ejemplo n.º 28
0
        public void IsValid_WhenARuleSetIsValid_ShouldReturnTrue()
        {
            string name        = _fixture.Create <string>();
            string description = _fixture.Create <string>();
            string version     = _fixture.Create <string>();

            RuleSet ruleSet = new RuleSet(name, description, version);

            string code    = _fixture.Create <string>();
            string message = _fixture.Create <string>();

            Rule rule = new Rule(code, message);

            string       leftPredicate  = _fixture.Create <string>();
            OperatorType operatorType   = OperatorType.Equal;
            string       rightPredicate = _fixture.Create <string>();

            RuleItem ruleItem = new ConstantRuleItem(leftPredicate, operatorType, rightPredicate);

            rule.AddRuleItem(ruleItem);
            ruleSet.AddRule(rule);

            ruleSet.IsValid().Should().BeTrue();
        }
Ejemplo n.º 29
0
    //converts from genomes to _rulesets
    public void DecodeGenomes()
    {
        for (int i = 0; i < _childCount; i++)
        {
            var temp = _gaAxioms.Population._genomes[i]._genome[0];

            string evolvedAxiom = _gaAxioms.Encoder.Decode(temp);

            //issue here because the rule keys aren't attached to their rules so the order matters when passing/reversing
            //so all systems currently need to have fghi defined in that order
            string  ruleNames = "FGHI";
            RuleSet rsTemp    = new RuleSet("Fractal", evolvedAxiom, ruleNames, 90f);

            for (int j = 0; j < _gaRules.Population._genomes[i]._genome.Length; j++)
            {
                var    tempGenome = _gaRules.Population._genomes[i]._genome[j];
                string specimen   = _gaRules.Encoder.Decode(tempGenome);
                rsTemp.AddRule(ruleNames[j].ToString(), specimen);
            }

            rsTemp.Validate();
            _rulesets[i] = rsTemp;
        }
    }
Ejemplo n.º 30
0
 public IRuleBasedDataGeneratorConfigurator AddRule(IRule rule)
 {
     _ruleSet.AddRule(rule);
     return(this);
 }
Ejemplo n.º 31
0
        public void RuleSet_Object()
        {
            RuleSet <bool> rs = new RuleSet <bool>(TestSetup.BoolRegistryObject);

            rs.AddRule(RuleNames.R001); //Negative Rule
            rs.AddRule(RuleNames.R002); //Even Rule
            rs.AddRule(RuleNames.R003); //Negative Rule
            rs.AddRule(RuleNames.R004); //NonNegative Rule
            rs.AddRule(RuleNames.R005); //Even Rule
            rs.AddRule(RuleNames.R006); //Odd Rule
            rs.AddRule(RuleNames.R007); //True Rule

            List <TestObject> validationList = new List <TestObject>();

            TestObject obj1 = new TestObject()
            {
                IntegerProperty = -1 //Negative, Odd
            };
            TestObject obj2 = new TestObject()
            {
                IntegerProperty = 2 //NonNegative, Even
            };

            validationList.Add(obj1);
            validationList.Add(obj2);

            var validationMap = new Dictionary <TestObject, Dictionary <string, IRuleResult <bool> > >();

            validationList.ForEach((obj) =>
            {
                var results = rs.Execute((rule) =>
                {
                    //cast IRule to specific rule instance and perform setup before rule execution
                    var genericRule = rule as Rule <TestObject, bool>;

                    if (genericRule != null)
                    {
                        genericRule.Object = obj;
                    }

                    var codedRule = rule as TestObjectRuleBase;

                    if (codedRule != null)
                    {
                        codedRule.ObjectInstance = obj;
                    }
                });

                validationMap.Add(obj, results);
            });

            IRuleResult <bool> result;

            //obj1
            result = validationMap[obj1][RuleNames.R001];
            Assert.IsTrue(result.Result);

            result = validationMap[obj1][RuleNames.R002];
            Assert.IsFalse(result.Result);

            result = validationMap[obj1][RuleNames.R003];
            Assert.IsTrue(result.Result);

            result = validationMap[obj1][RuleNames.R004];
            Assert.IsFalse(result.Result);

            result = validationMap[obj1][RuleNames.R005];
            Assert.IsFalse(result.Result);

            result = validationMap[obj1][RuleNames.R006];
            Assert.IsTrue(result.Result);

            result = validationMap[obj1][RuleNames.R007];
            Assert.IsTrue(result.Result);

            //obj2
            result = validationMap[obj2][RuleNames.R001];
            Assert.IsFalse(result.Result);

            result = validationMap[obj2][RuleNames.R002];
            Assert.IsTrue(result.Result);

            result = validationMap[obj2][RuleNames.R003];
            Assert.IsFalse(result.Result);

            result = validationMap[obj2][RuleNames.R004];
            Assert.IsTrue(result.Result);

            result = validationMap[obj2][RuleNames.R005];
            Assert.IsTrue(result.Result);

            result = validationMap[obj2][RuleNames.R006];
            Assert.IsFalse(result.Result);

            result = validationMap[obj2][RuleNames.R007];
            Assert.IsTrue(result.Result);
        }
Ejemplo n.º 32
0
        public void CounterTest()
        {
            Log.logLevel = Log.LogLevels.BASIC;

            RuleMSX rmsx = new RuleMSX();

            RuleSet ruleSet = rmsx.createRuleSet("CounterTestRuleSet");
            DataSet dataSet = rmsx.createDataSet("CounterTestDataSet");

            dataSet.addDataPoint("counter", new GenericIntDataPointSource(0));

            int maxVal = 10000;

            RuleAction  counterSignalAndStep10   = rmsx.createAction("CounterSignalAndStep10", new CounterSignalAndStep(10));
            RuleAction  counterSignalAndStep100  = rmsx.createAction("CounterSignalAndStep100", new CounterSignalAndStep(100));
            RuleAction  counterSignalAndStep1000 = rmsx.createAction("CounterSignalAndStep1000", new CounterSignalAndStep(1000));
            RuleAction  counterSignalAndStepMax  = rmsx.createAction("CounterSignalAndStepMax", new CounterSignalAndStep(maxVal));
            EqualSignal equalSignal    = new EqualSignal();
            RuleAction  equalSignalMax = rmsx.createAction("EqualSignalMax", equalSignal);

            Rule lessThan10 = new Rule("LessThan10", new IntMinMaxEvaluator(0, 9), counterSignalAndStep10);
            Rule greaterThanOrEqualTo10LessThan100   = new Rule("GreaterThanOrEqualTo10LessThan100", new IntMinMaxEvaluator(10, 99), counterSignalAndStep100);
            Rule greaterThanOrEqualTo100LessThan1000 = new Rule("GreaterThanOrEqualTo100LessThan1000", new IntMinMaxEvaluator(100, 999), counterSignalAndStep1000);
            Rule greaterThanOrEqualTo1000LessThanMax = new Rule("GreaterThanOrEqualTo1000LessThanMax", new IntMinMaxEvaluator(1000, maxVal - 1), counterSignalAndStepMax);
            Rule equalMax = new Rule("EqualMax", new EqualEvaluator(maxVal), equalSignalMax);

            ruleSet.AddRule(lessThan10);
            ruleSet.AddRule(greaterThanOrEqualTo10LessThan100);
            ruleSet.AddRule(greaterThanOrEqualTo100LessThan1000);
            ruleSet.AddRule(greaterThanOrEqualTo1000LessThanMax);
            ruleSet.AddRule(equalMax);

            System.Console.WriteLine(ruleSet.report());

            ruleSet.Execute(dataSet);

            int maxMS = 400000;
            int step  = 10;

            while (maxMS > 0)
            {
                if (equalSignal.fired)
                {
                    System.Console.WriteLine("Target reached");
                    break;
                }
                System.Threading.Thread.Sleep(step);
                maxMS -= step;
            }

            if (maxMS == 0)
            {
                System.Console.WriteLine("Timeout");
            }

            ruleSet.Stop();

            System.Console.WriteLine("Execution Time (ms): " + ruleSet.GetLastCycleExecutionTime());

            Assert.That(equalSignal.fired, Is.EqualTo(true));
        }