Keep using the same AssignmentsAllocator
In order to take into consideration the previous resources used the same AssignmentsAllocator must be used in an allocation. This implies changes in the until filling allocation that was instantiating an AssignmentsAllocator for each day. Now one is instantiated and used for each day until allocating the hours. FEA: ItEr71S07FragmentationDeletionItEr70S09
This commit is contained in:
parent
6e3bc7bea1
commit
e1b61e752a
5 changed files with 84 additions and 59 deletions
|
|
@ -21,8 +21,6 @@
|
|||
|
||||
package org.navalplanner.business.planner.entities;
|
||||
|
||||
import static org.navalplanner.business.workingday.EffortDuration.min;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
|
@ -51,7 +49,6 @@ import org.navalplanner.business.scenarios.entities.Scenario;
|
|||
import org.navalplanner.business.util.deepcopy.OnCopy;
|
||||
import org.navalplanner.business.util.deepcopy.Strategy;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.IntraDayDate.PartialDay;
|
||||
import org.navalplanner.business.workingday.ResourcesPerDay;
|
||||
|
||||
/**
|
||||
|
|
@ -214,7 +211,7 @@ public class GenericResourceAllocation extends
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<GenericDayAssignment> distributeForDay(LocalDate day,
|
||||
public List<GenericDayAssignment> distributeForDay(LocalDate day,
|
||||
EffortDuration effort) {
|
||||
List<GenericDayAssignment> result = new ArrayList<GenericDayAssignment>();
|
||||
for (ResourceWithAssignedDuration each : hoursDistributor
|
||||
|
|
@ -267,16 +264,6 @@ public class GenericResourceAllocation extends
|
|||
return GenericDayAssignment.class;
|
||||
}
|
||||
|
||||
public List<DayAssignment> createAssignmentsAtDay(List<Resource> resources,
|
||||
PartialDay day, ResourcesPerDay resourcesPerDay,
|
||||
final EffortDuration maxLimit) {
|
||||
final EffortDuration durations = min(
|
||||
calculateTotalToDistribute(day, resourcesPerDay), maxLimit);
|
||||
GenericAllocation genericAllocation = new GenericAllocation(resources);
|
||||
return new ArrayList<DayAssignment>(genericAllocation.distributeForDay(
|
||||
day.getDate(), durations));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Resource> getAssociatedResources() {
|
||||
return new ArrayList<Resource>(DayAssignment
|
||||
|
|
@ -392,4 +379,9 @@ public class GenericResourceAllocation extends
|
|||
return super.getAssignedDuration(start, endExclusive);
|
||||
}
|
||||
|
||||
public IEffortDistributor<GenericDayAssignment> createEffortDistributor(
|
||||
List<Resource> resources) {
|
||||
return new GenericAllocation(resources);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -597,7 +597,17 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
|
||||
public abstract IAllocatable withPreviousAssociatedResources();
|
||||
|
||||
protected abstract class AssignmentsAllocator implements IAllocatable {
|
||||
public interface IEffortDistributor<T extends DayAssignment> {
|
||||
/**
|
||||
* It does not add the created assigments to the underlying allocation.
|
||||
* It just distributes them.
|
||||
*
|
||||
*/
|
||||
List<T> distributeForDay(LocalDate day, EffortDuration effort);
|
||||
}
|
||||
|
||||
protected abstract class AssignmentsAllocator implements IAllocatable,
|
||||
IEffortDistributor<T> {
|
||||
|
||||
@Override
|
||||
public final void allocate(ResourcesPerDay resourcesPerDay) {
|
||||
|
|
@ -845,9 +855,6 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
}
|
||||
}
|
||||
|
||||
protected abstract List<T> distributeForDay(LocalDate day,
|
||||
EffortDuration effort);
|
||||
|
||||
}
|
||||
|
||||
private void markAsUnsatisfied() {
|
||||
|
|
@ -1030,7 +1037,7 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
getDayAssignmentsState().removingAssignments(assignments);
|
||||
}
|
||||
|
||||
final EffortDuration calculateTotalToDistribute(PartialDay day,
|
||||
public final EffortDuration calculateTotalToDistribute(PartialDay day,
|
||||
ResourcesPerDay resourcesPerDay) {
|
||||
return getAllocationCalendar().asDurationOn(day, resourcesPerDay);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@
|
|||
|
||||
package org.navalplanner.business.planner.entities;
|
||||
|
||||
import static org.navalplanner.business.workingday.EffortDuration.min;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
|
@ -53,7 +51,6 @@ import org.navalplanner.business.scenarios.entities.Scenario;
|
|||
import org.navalplanner.business.util.deepcopy.OnCopy;
|
||||
import org.navalplanner.business.util.deepcopy.Strategy;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.IntraDayDate.PartialDay;
|
||||
import org.navalplanner.business.workingday.ResourcesPerDay;
|
||||
|
||||
/**
|
||||
|
|
@ -190,7 +187,7 @@ public class SpecificResourceAllocation extends
|
|||
AssignmentsAllocator {
|
||||
|
||||
@Override
|
||||
protected List<SpecificDayAssignment> distributeForDay(LocalDate day,
|
||||
public List<SpecificDayAssignment> distributeForDay(LocalDate day,
|
||||
EffortDuration effort) {
|
||||
return Arrays.asList(SpecificDayAssignment.create(day, effort,
|
||||
resource));
|
||||
|
|
@ -202,6 +199,10 @@ public class SpecificResourceAllocation extends
|
|||
}
|
||||
}
|
||||
|
||||
public IEffortDistributor<SpecificDayAssignment> createEffortDistributor() {
|
||||
return new SpecificAssignmentsAllocator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocateHoursOnInterval onIntervalWithinTask(LocalDate start, LocalDate end) {
|
||||
return new SpecificAssignmentsAllocator().onIntervalWithinTask(start, end);
|
||||
|
|
@ -225,16 +226,6 @@ public class SpecificResourceAllocation extends
|
|||
return SpecificDayAssignment.class;
|
||||
}
|
||||
|
||||
public List<DayAssignment> createAssignmentsAtDay(PartialDay day,
|
||||
ResourcesPerDay resourcesPerDay, EffortDuration limit) {
|
||||
EffortDuration effort = calculateTotalToDistribute(day, resourcesPerDay);
|
||||
SpecificDayAssignment specific = SpecificDayAssignment.create(
|
||||
day.getDate(), min(limit, effort), resource);
|
||||
List<DayAssignment> result = new ArrayList<DayAssignment>();
|
||||
result.add(specific);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAllocatable withPreviousAssociatedResources() {
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
package org.navalplanner.business.planner.entities.allocationalgorithms;
|
||||
|
||||
import static org.navalplanner.business.i18n.I18nHelper._;
|
||||
import static org.navalplanner.business.workingday.EffortDuration.min;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
|
@ -38,7 +39,9 @@ import org.navalplanner.business.planner.entities.AvailabilityCalculator;
|
|||
import org.navalplanner.business.planner.entities.DayAssignment;
|
||||
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation.IEffortDistributor;
|
||||
import org.navalplanner.business.planner.entities.SpecificResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.allocationalgorithms.UntilFillingHoursAllocator.IAssignmentsCreator;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
|
|
@ -79,13 +82,6 @@ public abstract class ResourcesPerDayModification extends
|
|||
.resourcesPerDayFromEndUntil(start).allocate(getGoal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DayAssignment> createAssignmentsAtDay(PartialDay day,
|
||||
EffortDuration limit) {
|
||||
return genericAllocation.createAssignmentsAtDay(getResources(),
|
||||
day, getGoal(), limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AvailabilityTimeLine getAvailability() {
|
||||
return AvailabilityCalculator.buildSumOfAvailabilitiesFor(
|
||||
|
|
@ -120,6 +116,16 @@ public abstract class ResourcesPerDayModification extends
|
|||
return calendar;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceAllocation<?> getResourceAllocation() {
|
||||
return genericAllocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IEffortDistributor<?> toEffortDistributor() {
|
||||
return genericAllocation.createEffortDistributor(getResources());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class OnSpecificAllocation extends
|
||||
|
|
@ -152,13 +158,6 @@ public abstract class ResourcesPerDayModification extends
|
|||
getGoal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DayAssignment> createAssignmentsAtDay(PartialDay day,
|
||||
EffortDuration limit) {
|
||||
return resourceAllocation.createAssignmentsAtDay(day, getGoal(),
|
||||
limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AvailabilityTimeLine getAvailability() {
|
||||
Resource resource = getAssociatedResource();
|
||||
|
|
@ -184,6 +183,16 @@ public abstract class ResourcesPerDayModification extends
|
|||
return calendarFor(getAssociatedResource());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceAllocation<?> getResourceAllocation() {
|
||||
return resourceAllocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IEffortDistributor<?> toEffortDistributor() {
|
||||
return resourceAllocation.createEffortDistributor();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static ResourcesPerDayModification create(
|
||||
|
|
@ -249,8 +258,28 @@ public abstract class ResourcesPerDayModification extends
|
|||
|
||||
public abstract void applyAllocationFromEndUntil(LocalDate start);
|
||||
|
||||
public abstract List<DayAssignment> createAssignmentsAtDay(PartialDay day,
|
||||
EffortDuration limit);
|
||||
public IAssignmentsCreator createAssignmentsCreator() {
|
||||
|
||||
return new IAssignmentsCreator() {
|
||||
|
||||
final IEffortDistributor<?> effortDistributor = toEffortDistributor();
|
||||
|
||||
@Override
|
||||
public List<? extends DayAssignment> createAssignmentsAtDay(
|
||||
PartialDay day,
|
||||
EffortDuration limit) {
|
||||
EffortDuration toDistribute = getResourceAllocation()
|
||||
.calculateTotalToDistribute(day, getGoal());
|
||||
EffortDuration effortLimited = min(limit, toDistribute);
|
||||
return effortDistributor.distributeForDay(day.getDate(),
|
||||
effortLimited);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract ResourceAllocation<?> getResourceAllocation();
|
||||
|
||||
protected abstract IEffortDistributor<?> toEffortDistributor();
|
||||
|
||||
public abstract AvailabilityTimeLine getAvailability();
|
||||
|
||||
|
|
|
|||
|
|
@ -110,6 +110,12 @@ public abstract class UntilFillingHoursAllocator {
|
|||
toBeAssigned);
|
||||
}
|
||||
|
||||
public interface IAssignmentsCreator {
|
||||
|
||||
List<? extends DayAssignment> createAssignmentsAtDay(PartialDay day,
|
||||
EffortDuration limit);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dateFromWhichToAllocate
|
||||
|
|
@ -123,10 +129,13 @@ public abstract class UntilFillingHoursAllocator {
|
|||
EffortDuration taken = zero();
|
||||
EffortDuration biggestLastAssignment = zero();
|
||||
IntraDayDate current = dateFromWhichToAllocate;
|
||||
IAssignmentsCreator assignmentsCreator = resourcesPerDayModification
|
||||
.createAssignmentsCreator();
|
||||
while (effortRemaining.compareTo(zero()) > 0) {
|
||||
PartialDay day = calculateDay(current);
|
||||
Pair<EffortDuration, EffortDuration> pair = assignForDay(
|
||||
resourcesPerDayModification, day, effortRemaining);
|
||||
resourcesPerDayModification, assignmentsCreator, day,
|
||||
effortRemaining);
|
||||
taken = pair.getFirst();
|
||||
biggestLastAssignment = pair.getSecond();
|
||||
effortRemaining = effortRemaining.minus(taken);
|
||||
|
|
@ -244,27 +253,24 @@ public abstract class UntilFillingHoursAllocator {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param resourcesPerDayModification
|
||||
* @return a pair composed of the effort assigned and the biggest assignment
|
||||
* done.
|
||||
*/
|
||||
private Pair<EffortDuration, EffortDuration> assignForDay(
|
||||
ResourcesPerDayModification resourcesPerDayModification,
|
||||
IAssignmentsCreator assignmentsCreator,
|
||||
PartialDay day, EffortDuration remaining) {
|
||||
List<DayAssignment> newAssignments = createAssignmentsAtDay(
|
||||
resourcesPerDayModification, day, remaining);
|
||||
List<? extends DayAssignment> newAssignments = assignmentsCreator
|
||||
.createAssignmentsAtDay(day, remaining);
|
||||
resultAssignments.get(resourcesPerDayModification).addAll(
|
||||
newAssignments);
|
||||
return Pair.create(DayAssignment.sum(newAssignments),
|
||||
getMaxAssignment(newAssignments));
|
||||
}
|
||||
|
||||
private List<DayAssignment> createAssignmentsAtDay(
|
||||
ResourcesPerDayModification allocation, PartialDay day,
|
||||
EffortDuration limit) {
|
||||
return allocation.createAssignmentsAtDay(day, limit);
|
||||
}
|
||||
|
||||
private EffortDuration getMaxAssignment(List<DayAssignment> newAssignments) {
|
||||
private EffortDuration getMaxAssignment(
|
||||
List<? extends DayAssignment> newAssignments) {
|
||||
if (newAssignments.isEmpty()) {
|
||||
return zero();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue