private void Step <TOutcome>(RunContext runContext, IOutcomeReporter <TOutcome> outcomeReporter, IStepContext <TOutcome> step) { string eventId = step.EventId; TOutcome outcome = default(TOutcome); if (loopKind == LoopKind.Slates) { if (!liveModel.TryRequestMultiSlotDecision(eventId, step.SlatesContext, runContext.SlatesContainer, runContext.ApiStatusContainer)) { this.SafeRaiseError(runContext.ApiStatusContainer); } int[] actions = runContext.SlatesContainer.Select(slot => slot.ActionId).ToArray(); float[] probs = runContext.SlatesContainer.Select(slot => slot.Probability).ToArray(); outcome = step.GetSlatesOutcome(actions, probs); if (outcome == null) { return; } } else if (loopKind == LoopKind.CA) { if (!liveModel.TryRequestContinuousAction(eventId, step.ContinuousActionContext, runContext.ContinuousActionContainer, runContext.ApiStatusContainer)) { this.SafeRaiseError(runContext.ApiStatusContainer); } float action = runContext.ContinuousActionContainer.ChosenAction; float pdfValue = runContext.ContinuousActionContainer.ChosenActionPdfValue; outcome = step.GetContinuousActionOutcome(action, pdfValue); if (outcome == null) { return; } } else { if (!liveModel.TryChooseRank(eventId, step.DecisionContext, runContext.ResponseContainer, runContext.ApiStatusContainer)) { this.SafeRaiseError(runContext.ApiStatusContainer); } long actionIndex = -1; if (!runContext.ResponseContainer.TryGetChosenAction(out actionIndex, runContext.ApiStatusContainer)) { this.SafeRaiseError(runContext.ApiStatusContainer); } outcome = step.GetOutcome(actionIndex, runContext.ResponseContainer.AsEnumerable()); if (outcome == null) { return; } } if (!outcomeReporter.TryQueueOutcomeEvent(runContext, eventId, outcome)) { this.SafeRaiseError(runContext.ApiStatusContainer); } }
private void Step <TOutcome>(RunContext runContext, IOutcomeReporter <TOutcome> outcomeReporter, IStepContext <TOutcome> step) { string eventId = step.EventId; TOutcome outcome = default(TOutcome); if (loopKind == LoopKind.Slates) { if (!liveModel.TryRequestMultiSlotDecision(eventId, step.SlatesContext, runContext.MultiSlotResponseContainer, runContext.ApiStatusContainer)) { this.SafeRaiseError(runContext.ApiStatusContainer); } int[] actions = runContext.MultiSlotResponseContainer.Select(slot => slot.ActionId).ToArray(); float[] probs = runContext.MultiSlotResponseContainer.Select(slot => slot.Probability).ToArray(); outcome = step.GetSlatesOutcome(actions, probs); if (outcome == null) { return; } } else if (loopKind == LoopKind.CA) { if (!liveModel.TryRequestContinuousAction(eventId, step.ContinuousActionContext, runContext.ContinuousActionContainer, runContext.ApiStatusContainer)) { this.SafeRaiseError(runContext.ApiStatusContainer); } float action = runContext.ContinuousActionContainer.ChosenAction; float pdfValue = runContext.ContinuousActionContainer.ChosenActionPdfValue; outcome = step.GetContinuousActionOutcome(action, pdfValue); if (outcome == null) { return; } } else if (loopKind == LoopKind.CCB) { if (!liveModel.TryRequestDecision(step.DecisionContext, runContext.DecisionResponseContainer, runContext.ApiStatusContainer)) { this.SafeRaiseError(runContext.ApiStatusContainer); } // TODO: Populate actionProbs. Currently GetOutcome() just returns a fixed outcome value, so the values of actionProbs don't matter. ActionProbability[] actionProbs = new ActionProbability[runContext.DecisionResponseContainer.Count]; foreach (var slot in runContext.DecisionResponseContainer) { outcome = step.GetOutcome(slot.ActionId, actionProbs); if (!outcomeReporter.TryQueueOutcomeEvent(runContext, slot.SlotId, outcome)) { this.SafeRaiseError(runContext.ApiStatusContainer); } } return; } else if (loopKind == LoopKind.CCBv2) { if (!liveModel.TryRequestMultiSlotDecisionDetailed(eventId, step.DecisionContext, runContext.MultiSlotResponseDetailedContainer, runContext.ApiStatusContainer)) { this.SafeRaiseError(runContext.ApiStatusContainer); } foreach (var slot in runContext.MultiSlotResponseDetailedContainer) { outcome = step.GetOutcome(slot.ChosenAction, slot); if (!outcomeReporter.TryQueueOutcomeEvent(runContext, eventId, slot.SlotId, outcome)) { this.SafeRaiseError(runContext.ApiStatusContainer); } } return; } else { if (!liveModel.TryChooseRank(eventId, step.DecisionContext, runContext.ResponseContainer, runContext.ApiStatusContainer)) { this.SafeRaiseError(runContext.ApiStatusContainer); } long actionIndex = -1; if (!runContext.ResponseContainer.TryGetChosenAction(out actionIndex, runContext.ApiStatusContainer)) { this.SafeRaiseError(runContext.ApiStatusContainer); } outcome = step.GetOutcome(actionIndex, runContext.ResponseContainer.AsEnumerable()); if (outcome == null) { return; } } if (!outcomeReporter.TryQueueOutcomeEvent(runContext, eventId, outcome)) { this.SafeRaiseError(runContext.ApiStatusContainer); } }