From 1768e459d9dacba052ac27a9549dc83f172c133c Mon Sep 17 00:00:00 2001 From: Fred Date: Thu, 8 Aug 2024 18:04:15 -0300 Subject: [PATCH 1/3] chore: update models --- .../java/org/acme/foodpackaging/domain/Job.java | 2 +- .../org/acme/taskassigning/domain/Employee.java | 6 +----- .../java/org/acme/taskassigning/domain/Task.java | 13 ++++++------- .../java/org/acme/vehiclerouting/domain/Visit.java | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) 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..0b8d183964 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 @@ -45,7 +45,7 @@ public class Job { /** * Start is after cleanup. */ - @CascadingUpdateShadowVariable(targetMethodName = "updateStartCleaningDateTime", sourceVariableNames = {"line", "previousJob"}) + @CascadingUpdateShadowVariable(targetMethodName = "updateStartCleaningDateTime") private LocalDateTime startCleaningDateTime; @PiggybackShadowVariable(shadowVariableName = "startCleaningDateTime") 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() { From 71adc273db6474a7e7223db10413def6e5390aa1 Mon Sep 17 00:00:00 2001 From: Fred Date: Thu, 8 Aug 2024 18:55:44 -0300 Subject: [PATCH 2/3] chore: update models --- python/vehicle-routing/src/vehicle_routing/domain.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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): From 23c5c29ee07613ad246ed7fc5bd8f60eaa442048 Mon Sep 17 00:00:00 2001 From: Fred Date: Mon, 12 Aug 2024 11:21:19 -0300 Subject: [PATCH 3/3] chore: address PR comments --- .../src/main/java/org/acme/foodpackaging/domain/Job.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 0b8d183964..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; @@ -47,11 +46,9 @@ public class Job { */ @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