diff --git a/java/food-packaging/src/main/java/org/acme/foodpackaging/domain/Job.java b/java/food-packaging/src/main/java/org/acme/foodpackaging/domain/Job.java index f805ea91b3..10602bdc46 100644 --- a/java/food-packaging/src/main/java/org/acme/foodpackaging/domain/Job.java +++ b/java/food-packaging/src/main/java/org/acme/foodpackaging/domain/Job.java @@ -9,7 +9,6 @@ import ai.timefold.solver.core.api.domain.variable.CascadingUpdateShadowVariable; import ai.timefold.solver.core.api.domain.variable.InverseRelationShadowVariable; import ai.timefold.solver.core.api.domain.variable.NextElementShadowVariable; -import ai.timefold.solver.core.api.domain.variable.PiggybackShadowVariable; import ai.timefold.solver.core.api.domain.variable.PreviousElementShadowVariable; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -45,13 +44,11 @@ public class Job { /** * Start is after cleanup. */ - @CascadingUpdateShadowVariable(targetMethodName = "updateStartCleaningDateTime", sourceVariableNames = {"line", "previousJob"}) + @CascadingUpdateShadowVariable(targetMethodName = "updateStartCleaningDateTime") private LocalDateTime startCleaningDateTime; - - @PiggybackShadowVariable(shadowVariableName = "startCleaningDateTime") + @CascadingUpdateShadowVariable(targetMethodName = "updateStartCleaningDateTime") private LocalDateTime startProductionDateTime; - - @PiggybackShadowVariable(shadowVariableName = "startCleaningDateTime") + @CascadingUpdateShadowVariable(targetMethodName = "updateStartCleaningDateTime") private LocalDateTime endDateTime; // No-arg constructor required for Timefold diff --git a/java/task-assigning/src/main/java/org/acme/taskassigning/domain/Employee.java b/java/task-assigning/src/main/java/org/acme/taskassigning/domain/Employee.java index a08aed5dfd..1b226b671b 100644 --- a/java/task-assigning/src/main/java/org/acme/taskassigning/domain/Employee.java +++ b/java/task-assigning/src/main/java/org/acme/taskassigning/domain/Employee.java @@ -98,11 +98,7 @@ public void setTasks(List tasks) { */ @JsonIgnore public Affinity getAffinity(Customer customer) { - Affinity affinity = customerToAffinity.get(customer); - if (affinity == null) { - affinity = Affinity.NONE; - } - return affinity; + return customerToAffinity.getOrDefault(customer, Affinity.NONE); } @JsonIgnore diff --git a/java/task-assigning/src/main/java/org/acme/taskassigning/domain/Task.java b/java/task-assigning/src/main/java/org/acme/taskassigning/domain/Task.java index 3e3e94a526..20ba718805 100644 --- a/java/task-assigning/src/main/java/org/acme/taskassigning/domain/Task.java +++ b/java/task-assigning/src/main/java/org/acme/taskassigning/domain/Task.java @@ -30,7 +30,7 @@ public class Task { @PreviousElementShadowVariable(sourceVariableName = "tasks") private Task previousTask; @JsonIgnore - @CascadingUpdateShadowVariable(targetMethodName = "updateStartTime", sourceVariableNames = {"employee", "previousTask"}) + @CascadingUpdateShadowVariable(targetMethodName = "updateStartTime") private Integer startTime; // In minutes public Task() { @@ -135,13 +135,12 @@ public void setStartTime(Integer startTime) { private void updateStartTime() { if (employee == null) { startTime = null; - return; + } else if (previousTask == null) { + startTime = minStartTime; + } else { + var previousEndTime = previousTask.getEndTime(); + startTime = Math.max(previousEndTime, minStartTime); } - var previousEndTime = previousTask == null ? Integer.valueOf(0) : previousTask.getEndTime(); - if (previousEndTime == null) { - return; - } - startTime = Math.max(getMinStartTime(), previousEndTime); } @JsonIgnore diff --git a/java/vehicle-routing/src/main/java/org/acme/vehiclerouting/domain/Visit.java b/java/vehicle-routing/src/main/java/org/acme/vehiclerouting/domain/Visit.java index 9bd77eae28..8f6970373a 100644 --- a/java/vehicle-routing/src/main/java/org/acme/vehiclerouting/domain/Visit.java +++ b/java/vehicle-routing/src/main/java/org/acme/vehiclerouting/domain/Visit.java @@ -35,7 +35,7 @@ public class Visit implements LocationAware { @JsonIdentityReference(alwaysAsId = true) @PreviousElementShadowVariable(sourceVariableName = "visits") private Visit previousVisit; - @CascadingUpdateShadowVariable(targetMethodName = "updateArrivalTime", sourceVariableNames = {"vehicle", "previousVisit"}) + @CascadingUpdateShadowVariable(targetMethodName = "updateArrivalTime") private LocalDateTime arrivalTime; public Visit() { diff --git a/python/vehicle-routing/src/vehicle_routing/domain.py b/python/vehicle-routing/src/vehicle_routing/domain.py index 3ce3a41b15..99f886e136 100644 --- a/python/vehicle-routing/src/vehicle_routing/domain.py +++ b/python/vehicle-routing/src/vehicle_routing/domain.py @@ -50,10 +50,7 @@ class Visit(JsonDomainBase): IdSerializer, VisitValidator, Field(default=None)] arrival_time: Annotated[ Optional[datetime], - CascadingUpdateShadowVariable(source_variable_name='previous_visit', - target_method_name='update_arrival_time'), - CascadingUpdateShadowVariable(source_variable_name='vehicle', - target_method_name='update_arrival_time'), + CascadingUpdateShadowVariable(target_method_name='update_arrival_time'), Field(default=None)] def update_arrival_time(self):