-
Notifications
You must be signed in to change notification settings - Fork 211
feat: add support for maps with traffic #2320
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
Open
diogodanielsoaresferreira
wants to merge
10
commits into
TimefoldAI:main
Choose a base branch
from
diogodanielsoaresferreira:add_support_maps_with_traffic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,857
−23
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fcc4cc6
feat: add support for maps with traffic
diogodanielsoaresferreira 362999e
Merge branch 'main' into add_support_maps_with_traffic
diogodanielsoaresferreira c03df73
Rename LocationsAndTrafficAwareSolverModel to TimeAwareLocationsSolve…
diogodanielsoaresferreira 13aeea5
Return N matrices if pruning is not enabled but traffic is enabled
diogodanielsoaresferreira 96341a0
Merge branch 'main' into add_support_maps_with_traffic
diogodanielsoaresferreira c5ef758
Merge branch 'main' into add_support_maps_with_traffic
diogodanielsoaresferreira 518be76
feat: Add timeawareLocationAccumulator
diogodanielsoaresferreira 358ac82
fix: fix minor issues according to PR comments
diogodanielsoaresferreira ce64681
fix: add optional String in constructor args
diogodanielsoaresferreira 99103cc
Merge branch 'main' into add_support_maps_with_traffic
diogodanielsoaresferreira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...src/main/java/ai/timefold/solver/service/maps/api/TimeAwareUniqueLocationAccumulator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package ai.timefold.solver.service.maps.api; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.IdentityHashMap; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import ai.timefold.solver.service.maps.api.model.Location; | ||
| import ai.timefold.solver.service.maps.api.model.TimeInterval; | ||
|
|
||
| /** | ||
| * Accumulates {@link Location}s with their time availability data while checking for duplicates. | ||
| */ | ||
| public final class TimeAwareUniqueLocationAccumulator { | ||
| private final Set<Location> instanceUniqueLocations = Collections.newSetFromMap(new IdentityHashMap<>()); | ||
| private final Set<Location> equalityUniqueLocations = new LinkedHashSet<>(); | ||
| private final Map<Location, List<TimeInterval>> locationsWithAvailability = new LinkedHashMap<>(); | ||
|
|
||
| /** | ||
| * Adds a single {@link Location} while checking for duplicates. | ||
| * <p> | ||
| * For each unique location, the time intervals when the location is available for traveling are merged. | ||
| * | ||
| * @return true if the accumulator already contains a different equal instance of this location, otherwise false | ||
| */ | ||
| public boolean addLocation(Location location, List<TimeInterval> availableTimes) { | ||
| boolean addedEquality = equalityUniqueLocations.add(location); | ||
| boolean addedInstance = instanceUniqueLocations.add(location); | ||
| locationsWithAvailability.computeIfAbsent(location, l -> new ArrayList<>()).addAll(availableTimes); | ||
| // There are two equal instances, which means that locations have not been deduplicated. | ||
| return !addedEquality && addedInstance; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a map of locations and their corresponding availability time intervals. | ||
| * Each location is associated with a list of time intervals during which it is available for traveling. | ||
| * | ||
| * @return a map where the keys are {@link Location} instances and the values are lists of {@link TimeInterval} instances | ||
| * representing the periods during which the locations are available. | ||
| */ | ||
| public Map<Location, List<TimeInterval>> getLocationsWithAvailability() { | ||
| return locationsWithAvailability; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
service/maps/api/src/main/java/ai/timefold/solver/service/maps/api/model/TimeInterval.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package ai.timefold.solver.service.maps.api.model; | ||
|
|
||
| import java.time.OffsetDateTime; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * A half-open time interval {@code [from, to)} representing the period during which a location may be involved in | ||
| * travel. {@link #from()} is inclusive; {@link #to()} is exclusive. An interval where {@code from.equals(to)} is a | ||
| * zero-length (empty) interval — it still carries the meaning that the location is relevant at exactly {@code from}. | ||
| */ | ||
| public record TimeInterval(OffsetDateTime from, OffsetDateTime to) { | ||
|
|
||
| public TimeInterval { | ||
| Objects.requireNonNull(from, "from"); | ||
| Objects.requireNonNull(to, "to"); | ||
| if (from.isAfter(to)) { | ||
| throw new IllegalArgumentException( | ||
| "from (%s) must not be after to (%s)".formatted(from, to)); | ||
| } | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the
firstAvailableMatrixis there for the situation when traffic data was enabled, but we don't ask for it, correct?Instead of finding the first available matrix on the hot path, why don't we select the right one and set it as the
distanceMatrixreference during enrichment?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct. We don't do that because we don't know which is the "right" one, that's why we just take the first. We can do this in the enricher and set the first matrix as the "single" matrix, although it's a tradeoff: we get the optimizations for single matrix, but the object will take more memory (3 matrices + 1 repeated matrix for requests without timestamp).