Exemple #1
0
        public string ProcessMessageLocal(Command msgObj, SyftController ctrl)
        {
            switch (msgObj.functionCall)
            {
            case "sample":
            {
                var input  = ctrl.floatTensorFactory.Get(int.Parse(msgObj.tensorIndexParams[0]));
                var result = this.Sample(input);
                return(result.Id + "");
            }

            case "hook_reward":
            {
                var reward = ctrl.floatTensorFactory.Get(int.Parse(msgObj.tensorIndexParams[0]));
                this.HookReward(reward);
                return(this.Id + "");
            }

            case "deploy":
            {
                // 1234 is a special id that Unit watches for
                controller.setAgentId(id, 1234);
                return("1234");
            }

            case "get_history":
            {
                if (history.Count < 0)
                {
                    string indices = "[";
                    string reward_str;
                    string loss_str;
                    for (int i = 0; i < history.Count; i++)
                    {
                        if (history[i][0] != null)
                        {
                            loss_str = history[i][0].Id + "";
                        }
                        else
                        {
                            loss_str = "-1";
                        }

                        if (history[i][1] != null)
                        {
                            reward_str = history[i][1].Id + "";
                        }
                        else
                        {
                            reward_str = "-1";
                        }

                        indices += "[" + loss_str + "," + reward_str + "],";
                    }

                    return(indices.Substring(0, indices.Length - 2) + "]");
                }
                else
                {
                    return("");
                }
            }

            case "learn":
            {
                Learn();
                return(this.Id + "");
            }

            default:
            {
                return("Policy.processMessage not Implemented:" + msgObj.functionCall);
            }
            }
        }