fix priority allocation method
This commit is contained in:
@@ -37,12 +37,14 @@ public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider,
|
|||||||
public void reallocate() {
|
public void reallocate() {
|
||||||
List<IQuantizedChildTaskRelationship> parents = parentTasks();
|
List<IQuantizedChildTaskRelationship> parents = parentTasks();
|
||||||
|
|
||||||
allocation.clear();
|
allocation = null;
|
||||||
|
HashMap<IQuantizedChildTaskRelationship, Integer> tmp = new HashMap<>();
|
||||||
int amountToAllocate = getCurrentQuantityInInventory();
|
int amountToAllocate = getCurrentQuantityInInventory();
|
||||||
int[] newAmounts = ScarceParentPriorityAllocator.priorityAllocation(amountToAllocate, parents);
|
int[] newAmounts = ScarceParentPriorityAllocator.priorityAllocation(amountToAllocate, parents).getSecond();
|
||||||
for (int i = 0; i < parents.size(); i++) {
|
for (int i = 0; i < parents.size(); i++) {
|
||||||
allocation.put(parents.get(i), newAmounts[i]);
|
tmp.put(parents.get(i), newAmounts[i]);
|
||||||
}
|
}
|
||||||
|
allocation = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentQuantityInInventory() {
|
public int getCurrentQuantityInInventory() {
|
||||||
@@ -50,18 +52,8 @@ public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQuantityRelationship priority() {
|
public IQuantityRelationship priority() { // TODO cache
|
||||||
return x -> {
|
return x -> ScarceParentPriorityAllocator.priorityAllocation(x, parentTasks()).getFirst();
|
||||||
double sum = 0;
|
|
||||||
for (Map.Entry<IQuantizedChildTaskRelationship, Integer> entry : allocation.entrySet()) {
|
|
||||||
|
|
||||||
IQuantizedChildTaskRelationship parentRelationship = entry.getKey();
|
|
||||||
int quantityAssigned = entry.getValue();
|
|
||||||
|
|
||||||
sum += parentRelationship.allocatedPriority(quantityAssigned);
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -72,6 +64,10 @@ public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider,
|
|||||||
@Override
|
@Override
|
||||||
public double priorityAllocatedTo(IQuantizedParentTaskRelationship child, int quantity) {
|
public double priorityAllocatedTo(IQuantizedParentTaskRelationship child, int quantity) {
|
||||||
// how much of our priority would go to this child if it could provide us with quantity of the item we need
|
// how much of our priority would go to this child if it could provide us with quantity of the item we need
|
||||||
return priority().value(quantity);
|
|
||||||
|
// here's the thing honey, we *already have* some, so you're really asking what's the priority of getting quantity MORE
|
||||||
|
int curr = allocation.entrySet().stream().mapToInt(Map.Entry::getValue).sum();
|
||||||
|
|
||||||
|
return priority().value(quantity + curr) - priority().value(curr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,14 @@
|
|||||||
|
|
||||||
package tenor;
|
package tenor;
|
||||||
|
|
||||||
|
import net.minecraft.util.Tuple;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ScarceParentPriorityAllocator {
|
public class ScarceParentPriorityAllocator {
|
||||||
public static int[] priorityAllocation(int quantity, List<IQuantizedChildTaskRelationship> parents) {
|
public static Tuple<Double, int[]> priorityAllocation(int quantity, List<IQuantizedChildTaskRelationship> parents) {
|
||||||
if (quantity == 0) {
|
if (quantity == 0) {
|
||||||
return new int[parents.size()];
|
return new Tuple<>(0D, new int[parents.size()]);
|
||||||
}
|
}
|
||||||
double[][] priorities = new double[parents.size()][quantity];
|
double[][] priorities = new double[parents.size()][quantity];
|
||||||
for (int i = 0; i < parents.size(); i++) {
|
for (int i = 0; i < parents.size(); i++) {
|
||||||
@@ -51,7 +53,7 @@ public class ScarceParentPriorityAllocator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bestParent == -1) {
|
if (bestParent == -1) {
|
||||||
return taken;
|
return new Tuple<>(totalPriority, taken);
|
||||||
}
|
}
|
||||||
taken[bestParent] += bestQuantity;
|
taken[bestParent] += bestQuantity;
|
||||||
filled += bestQuantity;
|
filled += bestQuantity;
|
||||||
|
|||||||
Reference in New Issue
Block a user