diff options
Diffstat (limited to 'examples/examples-adaptive/src/main')
-rw-r--r-- | examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java b/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java index d60b04c00..32387d047 100644 --- a/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java +++ b/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/model/java/AutoLearnPolicyDecideTaskSelectionLogic.java @@ -119,17 +119,7 @@ public class AutoLearnPolicyDecideTaskSelectionLogic { closestdowni = i; } } - if (closestupi == -1 || closestdowni == -1) { - return r; - } - if (closestupi == closestdowni) { - return closestupi; - } - if (Math.abs(closestdown - diff) > Math.abs(closestup - diff)) { - return closestupi; - } else { - return closestdowni; - } + return calculateReturnValue(diff, r, closestupi, closestdowni, closestup, closestdown); } /** @@ -154,4 +144,30 @@ public class AutoLearnPolicyDecideTaskSelectionLogic { autoLearn.setAvDiffs(Arrays.asList(avdiffs)); autoLearn.setCounts(Arrays.asList(counts)); } + + + /** + * Calculate the return value of the learning + * @param diff the difference + * @param r the random value + * @param closestupi closest to i upwards + * @param closestdowni closest to i downwards + * @param closestup closest up value + * @param closestdown closest down value + * @return the return value + */ + private int calculateReturnValue(final double diff, final int r, int closestupi, int closestdowni, double closestup, + double closestdown) { + if (closestupi == -1 || closestdowni == -1) { + return r; + } + if (closestupi == closestdowni) { + return closestupi; + } + if (Math.abs(closestdown - diff) > Math.abs(closestup - diff)) { + return closestupi; + } else { + return closestdowni; + } + } } |