Skip to content

Commit

Permalink
Round Robin requesters (#1225)
Browse files Browse the repository at this point in the history
* Round Robin requesters

When a delivery task has been assigned to a requester we move that
requester to the end of its list so that if another requester frame
requests the same item type, it will be selected for the task the next
time around.

See #1203
  • Loading branch information
johalun authored and desht committed Sep 25, 2023
1 parent 6d9cefb commit 50bc83a
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public PriorityQueue<LogisticsTask> getTasks(Object holdingStack, boolean droneA
FluidStack fluid = holdingStack instanceof FluidStack ? (FluidStack) holdingStack : FluidStack.EMPTY;
PriorityQueue<LogisticsTask> tasks = new PriorityQueue<>();
for (int priority = logistics.size() - 1; priority >= 0; priority--) {
for (AbstractLogisticsFrameEntity requester : logistics.get(priority)) {
for (int requesterId = 0; requesterId < logistics.get(priority).size(); requesterId++) {
AbstractLogisticsFrameEntity requester = logistics.get(priority).get(requesterId);
if (droneAccess && requester.isObstructed(PathComputationType.AIR)) continue;
for (int i = 0; i < priority; i++) {
for (AbstractLogisticsFrameEntity provider : logistics.get(i)) {
Expand All @@ -82,7 +83,15 @@ public PriorityQueue<LogisticsTask> getTasks(Object holdingStack, boolean droneA
// it could be that the drone is carrying some item or fluid it can't drop off right now
// however it might still be able to transfer the other resource type (i.e. transfer items if
// it's holding a fluid, and vice versa)
int taskCount = tasks.size();
tryProvide(provider, requester, tasks, item.isEmpty(), fluid.isEmpty());

// if we provided something to the requester, move the requester to last in its list
// so another requester gets the next delivery, effectively round robin.
List<AbstractLogisticsFrameEntity> requesters = logistics.get(priority);
if (tasks.size() > taskCount && requesters.size() > 1) {
requesters.add(requesters.remove(requesterId));
}
}
}
}
Expand Down

0 comments on commit 50bc83a

Please sign in to comment.