private bool checkSuccessStoryCriterionForLastPair(TimeAndReward currentTimeAndReward) { if (checkpoints.Count < 2) { return(true); } int index = checkpoints.Count - 1; bool isCriterionValidForThisPair = isCriterionValidForPair(checkpoints[index - 1], checkpoints[index], currentTimeAndReward); return(isCriterionValidForThisPair); }
public void invokeCheckpoint(Checkpoint <Type> currentCheckpoint, TimeAndReward currentTimeAndReward) { bool successStoryCriterionSatisfiedForLastPair; while (!(successStoryCriterionSatisfiedForLastPair = checkSuccessStoryCriterionForLastPair(currentTimeAndReward))) { // undo all changes made since last recent checkpoint and remove checkpoint int lastIndex = checkpoints.Count - 1; undoAllPolicyModificationsSinceCheckpoint(checkpoints[lastIndex]); checkpoints.RemoveAt(lastIndex); } checkpoints.Add(currentCheckpoint); }
private static double calcRatio(Checkpoint <Type> checkpoint, TimeAndReward currentTimeAndReward) { return((currentTimeAndReward.reward - checkpoint.timeAndReward.reward) / (currentTimeAndReward.time - checkpoint.timeAndReward.time)); }
private static bool isCriterionValidForPair(Checkpoint <Type> a, Checkpoint <Type> b, TimeAndReward currentTimeAndReward) { double ratioForB = calcRatio(b, currentTimeAndReward), ratioForA = calcRatio(a, currentTimeAndReward); return(ratioForB > ratioForA); }