From fbe21f9f4b9ca5e6042e1cf92783561c3c62a6e3 Mon Sep 17 00:00:00 2001 From: Diego Pino Garcia Date: Mon, 27 Dec 2010 09:23:26 +0100 Subject: [PATCH] Refactor code for allocating previously unscheduled elements Once all new allocations are done, originally unschedule elements are unschedule/schedule again, to force dependencies are satisfy FEA: ItEr66OTS03AlgoritmosLimitantesItEr65OTS05 --- .../LimitingResourceQueueModel.java | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/limitingresources/LimitingResourceQueueModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/limitingresources/LimitingResourceQueueModel.java index 87aa01364..375a7b383 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/limitingresources/LimitingResourceQueueModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/limitingresources/LimitingResourceQueueModel.java @@ -433,10 +433,33 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { .getPotentiallyAffectedByInsertion(externalQueueElement), requirements.getElement(), allocation); result.addAll(moved); + result.addAll(scheduleUnscheduledElementsIfNeeded(allocation)); + + return result; + } + + private Collection scheduleUnscheduledElementsIfNeeded( + AllocationSpec allocation) { + + List result = new ArrayList(); - // Return all moved tasks (including the allocated one) if (allocation.isAppropriative()) { - result.addAll(scheduleElements(allocation.getUnscheduledElements())); + checkAllocationIsAppropriative(false); + + // Assign all unscheduled elements + List unscheduled = allocation.getUnscheduledElements(); + for (LimitingResourceQueueElement each: unscheduled) { + result.addAll(assignLimitingResourceQueueElement(each)); + } + + // Only for those originally unscheduled elements, unschedule and + // schedule them again to force dependencies are satisfied + for (LimitingResourceQueueElement each: unscheduled) { + unschedule(each); + assignLimitingResourceQueueElement(each); + } + + checkAllocationIsAppropriative(true); } return result; } @@ -780,24 +803,8 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel { queuesState.getPotentiallyAffectedByInsertion(element), requirements.getElement(), allocation); result.addAll(moved); + result.addAll(scheduleUnscheduledElementsIfNeeded(allocation)); - // Return all moved tasks (including the allocated one) - if (allocation.isAppropriative()) { - result.addAll(scheduleElements(allocation.getUnscheduledElements())); - } - return result; - } - - private List scheduleElements( - List unscheduled) { - - List result = new ArrayList(); - - checkAllocationIsAppropriative(false); - for (LimitingResourceQueueElement each: unscheduled) { - result.addAll(assignLimitingResourceQueueElement(each)); - } - checkAllocationIsAppropriative(true); return result; }