Apply backwards forces too
It takes into account the constraints on tasks' end date. FEA: ItEr64OTS03PlanificacionHaciaAtras
This commit is contained in:
parent
46fedd3478
commit
4a5a7aba4e
2 changed files with 33 additions and 2 deletions
|
|
@ -1012,7 +1012,7 @@ public class GanttDiagramGraph<V, D extends IDependency<V>> implements
|
|||
private boolean taskChangesPosition() {
|
||||
ChangeTracker tracker = trackTaskChanges();
|
||||
Constraint.initialValue(noRestrictions())
|
||||
.withConstraints(new ForwardForces())
|
||||
.withConstraints(new BackwardsForces(), new ForwardForces())
|
||||
.apply();
|
||||
return tracker.taskHasChanged();
|
||||
}
|
||||
|
|
@ -1055,6 +1055,12 @@ public class GanttDiagramGraph<V, D extends IDependency<V>> implements
|
|||
ComparisonType.BIGGER_OR_EQUAL_THAN, start, end);
|
||||
}
|
||||
|
||||
DatesBasedPositionRestrictions lessThan(GanttDate start, GanttDate end) {
|
||||
return new DatesBasedPositionRestrictions(
|
||||
ComparisonType.LESS_OR_EQUAL_THAN_RIGHT_FLOATING, start,
|
||||
end);
|
||||
}
|
||||
|
||||
class DatesBasedPositionRestrictions extends PositionRestrictions {
|
||||
|
||||
private Constraint<GanttDate> startConstraint;
|
||||
|
|
@ -1270,6 +1276,28 @@ public class GanttDiagramGraph<V, D extends IDependency<V>> implements
|
|||
|
||||
}
|
||||
|
||||
class BackwardsForces extends Forces {
|
||||
|
||||
@Override
|
||||
PositionRestrictions enforceUsingPreviousRestrictions(
|
||||
PositionRestrictions restrictions) {
|
||||
GanttDate result = Constraint.<GanttDate> initialValue(null)
|
||||
.withConstraints(restrictions.getEndConstraints())
|
||||
.withConstraints(adapter.getEndConstraintsFor(task))
|
||||
.apply();
|
||||
if (result != null) {
|
||||
return moveToEnd(result);
|
||||
}
|
||||
return restrictions;
|
||||
}
|
||||
|
||||
private PositionRestrictions moveToEnd(GanttDate newEnd) {
|
||||
adapter.setEndDateFor(task, newEnd);
|
||||
return lessThan(adapter.getStartDate(task), newEnd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder()
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class ConstraintOnComparableValues<T extends Comparable<T>> extends
|
|||
}
|
||||
|
||||
public enum ComparisonType {
|
||||
LESS_OR_EQUAL_THAN, BIGGER_OR_EQUAL_THAN, EQUAL_TO;
|
||||
LESS_OR_EQUAL_THAN, LESS_OR_EQUAL_THAN_RIGHT_FLOATING, BIGGER_OR_EQUAL_THAN, EQUAL_TO;
|
||||
}
|
||||
|
||||
private final T comparisonValue;
|
||||
|
|
@ -75,6 +75,8 @@ public class ConstraintOnComparableValues<T extends Comparable<T>> extends
|
|||
switch (comparisonType) {
|
||||
case LESS_OR_EQUAL_THAN:
|
||||
return min(comparisonValue, value);
|
||||
case LESS_OR_EQUAL_THAN_RIGHT_FLOATING:
|
||||
return comparisonValue;
|
||||
case BIGGER_OR_EQUAL_THAN:
|
||||
return max(comparisonValue, value);
|
||||
case EQUAL_TO:
|
||||
|
|
@ -96,6 +98,7 @@ public class ConstraintOnComparableValues<T extends Comparable<T>> extends
|
|||
public boolean isSatisfiedBy(T value) {
|
||||
switch (comparisonType) {
|
||||
case LESS_OR_EQUAL_THAN:
|
||||
case LESS_OR_EQUAL_THAN_RIGHT_FLOATING:
|
||||
return value.compareTo(comparisonValue) <= 0;
|
||||
case BIGGER_OR_EQUAL_THAN:
|
||||
return value.compareTo(comparisonValue) >= 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue