Пример #1
0
        public static DecisionServiceJsonSingleton Create(DecisionServiceJsonConfiguration config)
        {
            if (instance == null)
            {
                lock (syncRoot)
                {
                    if (instance == null)
                    {
                        instance = new DecisionServiceJsonSingleton(config);
                    }
                }
            }

            return instance;
        }
Пример #2
0
        public static void SampleCodeUsingASAWithJsonContext()
        {
            // Create configuration for the decision service
            var serviceConfig = new DecisionServiceJsonConfiguration( // specify that context types are Json-formatted
                authorizationToken: "json-code",
                explorer: new EpsilonGreedyExplorer<string>(new DefaultJsonPolicy(), epsilon: 0.8f))
            {
                PollingForModelPeriod = TimeSpan.MinValue,
                PollingForSettingsPeriod = TimeSpan.MinValue,
                EventHubConnectionString = "",
                EventHubInputName = ""
            };

            var service = new DecisionServiceJson(serviceConfig);

            string uniqueKey = "json-key-";

            var rg = new Random(uniqueKey.GetHashCode());

            for (int i = 1; i < 20; i++)
            {
                int numActions = rg.Next(5, 10);

                DateTime timeStamp = DateTime.UtcNow;
                string key = uniqueKey + Guid.NewGuid().ToString();

                var context = ExpandedContext.CreateRandom(numActions, rg);
                string contextJson = JsonConvert.SerializeObject(context);
                uint[] action = service.ChooseAction(new UniqueEventID { Key = key, TimeStamp = timeStamp }, contextJson, (uint)numActions);
                service.ReportReward(i / 100f, new UniqueEventID { Key = key, TimeStamp = timeStamp });

                System.Threading.Thread.Sleep(1);
            }

            service.Flush();
        }
Пример #3
0
 private DecisionServiceJsonSingleton(DecisionServiceJsonConfiguration config)
     : base(config) { }