Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update @CascadingUpdateShadowVariable models #536

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ public void setTasks(List<Task> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 1 addition & 4 deletions python/vehicle-routing/src/vehicle_routing/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading