-
Notifications
You must be signed in to change notification settings - Fork 147
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
Refactored Graph Traversal Implementation #258
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b96fc49
Refactor Shortest Path
yashTEF 80bd1bc
Formatting
yashTEF aca283e
Remove Whitespaces
yashTEF 5099b28
Google-Style
yashTEF 4f7e53e
Formatting Checks
yashTEF 03e54eb
Merge branch 'eclipse-ee4j:master' into master
yashTEF 7914a10
Requested Changes
yashTEF 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 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 |
---|---|---|
|
@@ -50,53 +50,34 @@ public List<TransitPath> findShortestPath( | |
@Size(min = 8, max = 8, message = "Deadline value must be eight characters long.") | ||
@QueryParam("deadline") | ||
String deadline) { | ||
LocalDateTime date = nextDate(LocalDateTime.now()); | ||
|
||
List<String> allVertices = dao.listLocations(); | ||
allVertices.remove(originUnLocode); | ||
allVertices.remove(destinationUnLocode); | ||
|
||
int candidateCount = getRandomNumberOfCandidates(); | ||
List<TransitPath> candidates = new ArrayList<>(candidateCount); | ||
List<TransitPath> candidates = new ArrayList<>(); | ||
|
||
for (int i = 0; i < candidateCount; i++) { | ||
allVertices = getRandomChunkOfLocations(allVertices); | ||
List<TransitEdge> transitEdges = new ArrayList<>(allVertices.size() - 1); | ||
String firstLegTo = allVertices.get(0); | ||
|
||
LocalDateTime fromDate = nextDate(date); | ||
LocalDateTime toDate = nextDate(fromDate); | ||
date = nextDate(toDate); | ||
|
||
transitEdges.add( | ||
new TransitEdge( | ||
dao.getVoyageNumber(originUnLocode, firstLegTo), | ||
originUnLocode, | ||
firstLegTo, | ||
fromDate, | ||
toDate)); | ||
|
||
for (int j = 0; j < allVertices.size() - 1; j++) { | ||
String current = allVertices.get(j); | ||
String next = allVertices.get(j + 1); | ||
fromDate = nextDate(date); | ||
toDate = nextDate(fromDate); | ||
date = nextDate(toDate); | ||
List<TransitEdge> transitEdges = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this. It is inefficient to create an empty list when capacity is known. |
||
String fromUnLocode = originUnLocode; | ||
LocalDateTime date = LocalDateTime.now(); | ||
|
||
for (int j = 0; j <= allVertices.size(); ++j) { | ||
LocalDateTime fromDate = nextDate(date); | ||
LocalDateTime toDate = nextDate(fromDate); | ||
String toUnLocode = (j >= allVertices.size() ? destinationUnLocode : allVertices.get(j)); | ||
transitEdges.add( | ||
new TransitEdge(dao.getVoyageNumber(current, next), current, next, fromDate, toDate)); | ||
new TransitEdge( | ||
dao.getVoyageNumber(fromUnLocode, toUnLocode), | ||
fromUnLocode, | ||
toUnLocode, | ||
fromDate, | ||
toDate)); | ||
fromUnLocode = toUnLocode; | ||
date = nextDate(toDate); | ||
} | ||
|
||
String lastLegFrom = allVertices.get(allVertices.size() - 1); | ||
fromDate = nextDate(date); | ||
toDate = nextDate(fromDate); | ||
transitEdges.add( | ||
new TransitEdge( | ||
dao.getVoyageNumber(lastLegFrom, destinationUnLocode), | ||
lastLegFrom, | ||
destinationUnLocode, | ||
fromDate, | ||
toDate)); | ||
|
||
candidates.add(new TransitPath(transitEdges)); | ||
} | ||
|
||
|
@@ -114,7 +95,7 @@ private int getRandomNumberOfCandidates() { | |
private List<String> getRandomChunkOfLocations(List<String> allLocations) { | ||
Collections.shuffle(allLocations); | ||
int total = allLocations.size(); | ||
int chunk = total > 4 ? 1 + new Random().nextInt(5) : total; | ||
int chunk = total > 4 ? 1 + random.nextInt(5) : total; | ||
return allLocations.subList(0, chunk); | ||
} | ||
} |
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.
Please revert this. It is inefficient to create an empty list when capacity is known.