Skip to content

Commit

Permalink
Improve after review
Browse files Browse the repository at this point in the history
  • Loading branch information
TruongQuangSB committed Dec 9, 2024
1 parent 3a26de5 commit 213d1bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,13 @@ private static List<DirectedTOPEdge<Edge>> findRelevantEdgesFromTarget(
final BigDecimal weight = edge.edge().getWeight();
final BigDecimal remainingWeight = currentRemaining
.subtract(weight);
final Node edgeSource = graph.getEdgeSource(edge);

if (remainingWeight.compareTo(BigDecimal.ZERO) < 1) {
continue;
}
edgesDistance.add(edge);
// Mark the edge's source vertex if needed
final Node edgeSource = graph.getEdgeSource(edge);
remainingWeigthFromEnd.computeIfAbsent(edgeSource, v -> {
nodesToProcess.add(edgeSource);
return remainingWeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,19 @@ public TopPath getTopPath(final Predicate<TopPath> condition,
private static TopPath pathTransform(
final GraphPath<Node, DirectedTOPEdge<Edge>> path,
final Node startNode) {
if (!path.getStartVertex().equals(startNode)) {
final DirectedTOPEdge<Edge> firstEdge = path.getEdgeList().getFirst();
final Node edgeSource = path.getGraph().getEdgeSource(firstEdge);
if (!path.getStartVertex().equals(startNode)
|| !edgeSource.equals(startNode)) {
throw new IllegalArgumentException(
"Path not start from source node"); //$NON-NLS-1$
}

final BigDecimal firstEdgeLength = firstEdge.edge().getWeight();
return new TopPath(
path.getEdgeList().stream().map(e -> e.edge()).distinct()
.map(Edge::edge).toList(),
getDirectedPathWeight(path), startNode.point().distance());
getDirectedPathWeight(path), firstEdgeLength);
}

private static BigDecimal getDirectedPathWeight(
Expand Down

0 comments on commit 213d1bb

Please sign in to comment.