From 060741bfdc4c956347ba7f9508c5d15ff88601ed Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 24 Nov 2018 19:17:30 -0800 Subject: [PATCH] fixes --- .../QuantizedTaskPriorityAllocationCache.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/tenor/java/tenor/QuantizedTaskPriorityAllocationCache.java b/src/tenor/java/tenor/QuantizedTaskPriorityAllocationCache.java index 531ce56c7..d556dc5b4 100644 --- a/src/tenor/java/tenor/QuantizedTaskPriorityAllocationCache.java +++ b/src/tenor/java/tenor/QuantizedTaskPriorityAllocationCache.java @@ -51,29 +51,53 @@ public abstract class QuantizedTaskPriorityAllocationCache extends QuantizedTask for (int i = 0; i < costs.length; i++) { costs[i] = children.get(i).cost().value(quantity); } + applyAllocation(alloc, costs); + return alloc; + } + + protected void applyAllocation(Allocation alloc, double[] childCosts) { // overridable switch (type) { case ANY_ONE_OF: // by default, give it all to the lowest cost // this is stable int lowestInd = 0; - for (int i = 1; i < costs.length; i++) { - if (costs[i] < costs[lowestInd]) { + for (int i = 1; i < childCosts.length; i++) { + if (childCosts[i] < childCosts[lowestInd]) { lowestInd = i; } } alloc.givePriority(lowestInd, alloc.unallocated()); - return alloc; + case SERIAL: + // give it all to the first nonzero cost? maybe? + for (int i = 1; i < childCosts.length; i++) { + if (childCosts[i] > 0) { + alloc.givePriority(i, alloc.unallocated()); + return; + } + } + break; default: throw new UnsupportedOperationException("Not implemented yet"); } } + protected Allocation blend(Allocation previous, Allocation current) { // overridable + if (previous.priorities.length != current.priorities.length) { + return current; + } + Allocation blended = new Allocation(current.total); + for (int i = 0; i < current.priorities.length; i++) { + blended.givePriority(i, current.priorities[i] * 0.1d + previous.priorities[i] * 0.9d); + } + return blended; + } + protected double effectiveAllocationSize(int quantity) { // overridable return priority().value(quantity); } protected class Allocation { - private final double[] priorities; + private final double[] priorities; // always sums up to 1 or less private final double total; public Allocation(double total) { @@ -82,7 +106,7 @@ public abstract class QuantizedTaskPriorityAllocationCache extends QuantizedTask } public double unallocated() { - return total - allocated(); + return 1 - allocated(); } public double allocated() {