コード例 #1
0
        private Policy FitPolicy(Policy currentPolicy, List <Episode> trainingSet)
        {
            Stopwatch fittingStopwatch = Stopwatch.StartNew();

            Console.WriteLine(string.Format("Fitting policy..."));
            Policy newPolicy;

            {
                Policy fitPolicy = _policyLearner.FitPolicy(trainingSet);
                newPolicy = currentPolicy.Clone();
                foreach (HeroType hero in fitPolicy.Root.Keys)
                {
                    newPolicy.Root[hero] = fitPolicy.Root[hero];
                }
            }

            Console.WriteLine(string.Format("Policy generated in {0:F1} seconds", fittingStopwatch.Elapsed.TotalSeconds));

            Stopwatch verifyingStopwatch = Stopwatch.StartNew();

            Console.WriteLine(string.Format("Verifying policy..."));
            double policyAccuracy = CalculatePolicyAccuracy(trainingSet, newPolicy);

            Console.WriteLine(string.Format("Policy accuracy: {0}", policyAccuracy));
            return(newPolicy);
        }
        public void WhenTheEventIsReceivedItIsEvaluatedButNotApplicable(ManagementChargeAppliedData eventData, Policy view)
        {
            var expectedView = view.Clone();
            var target       = new ManagementChargeAppliedEvaluator();

            target.Evaluate(view, null, eventData);

            view.Should().BeEquivalentTo(expectedView);
        }
        public void WhenTheEventIsReceivedItIsEvaluated(Policy view)
        {
            var fixture      = new Fixture();
            var target       = new ManagementChargeAppliedEvaluator();
            var expectedView = view.Clone();
            var fundId       = view.Funds.Keys.First();
            var eventData    = fixture.Build <ManagementChargeAppliedData>().With(t => t.FundId, fundId).Create();

            target.Evaluate(view, null, eventData);

            for (var index = 0; index < view.Funds[fundId].Count; index++)
            {
                Assert.Equal(expectedView.Funds[fundId][index].Units * eventData.ChargeFactor, view.Funds[fundId][index].Units);
            }
        }
コード例 #4
0
        public void RemoveRoleMember_NoRole()
        {
            var policy = new Policy
            {
                Bindings =
                {
                    new Binding {
                        Role = "other", Members ={ "x",                   "y", "z" }
                    },
                }
            };
            var expected = policy.Clone();

            Assert.False(policy.RemoveRoleMember("target", "d"));
            Assert.Equal(expected, policy);
        }
コード例 #5
0
        public void AddRoleMember_RoleExists_MemberExists()
        {
            var policy = new Policy
            {
                Bindings =
                {
                    new Binding {
                        Role = "other", Members ={ "x",                   "y", "z" }
                    },
                    new Binding {
                        Role = "target", Members ={ "a",                   "b", "c" }
                    },
                }
            };
            var expected = policy.Clone();

            Assert.False(policy.AddRoleMember("target", "b"));
            Assert.Equal(expected, policy); // No change
        }