Skip to content

Commit

Permalink
Fix find banking line process (#1118)
Browse files Browse the repository at this point in the history
* Fix find banking line process

* Apply suggestions from code review

Co-authored-by: Marius Heine <[email protected]>

* Improve after review

---------

Co-authored-by: Marius Heine <[email protected]>
  • Loading branch information
TruongQuangSB and mariusheine authored Dec 10, 2024
1 parent 2bad794 commit 55f767b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,27 @@ private void addBankingForContainer(
}
for (final Ueberhoehungslinie line : container
.getUeberhoehungslinie()) {
final BankingInformation bankingInformation = findTOPBanking(line);
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
if (bankingInformation == null) {
logger.debug("Can't find TopPath for Ueberhoehungslinie: {}", //$NON-NLS-1$
line.getIdentitaet().getWert());
bankingInformations.put(line, Optional.empty());
} else {
logger.debug("Found TopPath for Ueberhoehungslinie: {}", //$NON-NLS-1$
line.getIdentitaet().getWert());
bankingInformations.put(line, Optional.of(bankingInformation));

try {
final BankingInformation bankingInformation = findTOPBanking(
line);

if (bankingInformation == null) {
logger.debug(
"Can't find TopPath for Ueberhoehungslinie: {}", //$NON-NLS-1$
line.getIdentitaet().getWert());
bankingInformations.put(line, Optional.empty());
} else {
logger.debug("Found TopPath for Ueberhoehungslinie: {}", //$NON-NLS-1$
line.getIdentitaet().getWert());
bankingInformations.put(line,
Optional.of(bankingInformation));
}
} catch (final NullPointerException e) {
logger.error(e.getMessage());
}
}

Expand Down Expand Up @@ -165,6 +174,9 @@ public BankingInformation findTOPBanking(

final Ueberhoehung begin = bankingLine.getIDUeberhoehungA().getValue();
final Ueberhoehung end = bankingLine.getIDUeberhoehungB().getValue();
if (begin == null || end == null) {
return null;
}
final BigDecimal bankingLineLength = bankingLine
.getUeberhoehungslinieAllg().getUeberhoehungslinieLaenge()
.getWert();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public Optional<TopPath> findShortestPath(final TopPoint from,
.map(p -> new TopPath(
p.getEdgeList().stream().map(Edge::edge).distinct()
.toList(),
getPathWeight(p), fromNode.point().distance()));
getPathWeight(p),
p.getEdgeList().getFirst().getWeight()));
}

private static BigDecimal getPathWeight(final GraphPath<Node, Edge> path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class TopPath {
private final List<TOP_Kante> edges;
private final BigDecimal length;
private final BigDecimal offset; // offset from start of first edge
private final BigDecimal firstEdgeLength;

/**
* @param edges
Expand All @@ -32,14 +32,14 @@ public class TopPath {
* the total length of the path. may be less than the total
* length of the edges if the path does not cover the full extent
* of the edges
* @param offset
* starting offset from the first TOP_Kante in edges
* @param firstEdgeLength
* the length of the first edge
*/
public TopPath(final List<TOP_Kante> edges, final BigDecimal length,
final BigDecimal offset) {
final BigDecimal firstEdgeLength) {
this.edges = edges;
this.length = length;
this.offset = offset;
this.firstEdgeLength = firstEdgeLength;
}

/**
Expand All @@ -59,12 +59,10 @@ public BigDecimal length() {
}

/**
* @return the total length of the path. may be less than the total length
* of the edges if the path does not cover the full extent of the
* edges
* @return the length off the first Edges
*/
public BigDecimal offset() {
return offset;
public BigDecimal firstEdgeLength() {
return firstEdgeLength;
}

/**
Expand All @@ -74,7 +72,7 @@ public BigDecimal offset() {
* on the path
*/
public Optional<BigDecimal> getDistance(final TopPoint point) {
BigDecimal pathOffset = this.offset.negate();
BigDecimal pathOffset = this.firstEdgeLength;

TOP_Kante previousEdge = null;
for (final TOP_Kante edge : edges()) {
Expand All @@ -83,7 +81,7 @@ public Optional<BigDecimal> getDistance(final TopPoint point) {

// If the point is on the current edge, check which direction to add
if (point.edge().equals(edge)) {
// in top direction?
// In top direction
if (previousEdge == null
|| previousEdge.getIDTOPKnotenB().getValue() == edge
.getIDTOPKnotenA().getValue()
Expand All @@ -108,15 +106,15 @@ public Optional<BigDecimal> getDistance(final TopPoint point) {
}

return Optional.of(pointDistance);

}

// Point not on this edge, check next edge
if (previousEdge != null) {
pathOffset = pathOffset.add(edgeLength);
}
previousEdge = edge;
pathOffset = pathOffset.add(edgeLength);

}
return Optional.empty();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class BankValues extends AbstractPlazContainerCheck implements PlazCheck, EventH
].map [
val bankLength = ueberhoehungslinieAllg.
ueberhoehungslinieLaenge.wert
if (IDUeberhoehungA?.value === null ||
IDUeberhoehungB?.value === null) {
return createError(
"Die Überhöhungslinie {GUID} hat entweder keine Ueberhoehung_A oder keine Ueberhoehung_B.",
Map.of("GUID", it.identitaet.wert))
}
val begin = new TopPoint(IDUeberhoehungA.value)
val end = new TopPoint(IDUeberhoehungB.value)
val paths = topologicalService.findAllPathsBetween(begin, end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.function.Predicate;

import org.eclipse.set.basis.graph.TopPath;
Expand Down Expand Up @@ -303,8 +304,9 @@ private static List<DirectedTOPEdge<Edge>> findRelevantEdgesFromTarget(

// Check whether the incoming edges of this node are correctly
// decorated
for (final DirectedTOPEdge<Edge> edge : graph
.incomingEdgesOf(vertex)) {
final Set<DirectedTOPEdge<Edge>> incomingEdgesOf = graph
.incomingEdgesOf(vertex);
for (final DirectedTOPEdge<Edge> edge : incomingEdgesOf) {
// Mark the edge if needed
final BigDecimal weight = edge.edge().getWeight();
final BigDecimal remainingWeight = currentRemaining
Expand All @@ -320,6 +322,12 @@ private static List<DirectedTOPEdge<Edge>> findRelevantEdgesFromTarget(
nodesToProcess.add(edgeSource);
return remainingWeight;
});

// When another edge exists, which is shorter than found edge, replace the weight
remainingWeigthFromEnd.computeIfPresent(edgeSource,
(k, v) -> remainingWeight.compareTo(v) > 0
? remainingWeight
: v);
}
}
assert nodesToProcess.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,13 @@ public Node splitGraphAt(final TopPoint at) {
*/
public Node splitGraphAt(final TopPoint at, final Boolean inTopDirection) {
final TOP_Kante edge = at.edge();

final List<Edge> pointEdgeList = pointEdgeGraph.edgeSet().stream()
.filter(c -> c.edge == edge)
.filter(c -> c.offset.compareTo(at.distance()) <= 0)
.filter(c -> c.offset.add(c.length)
.compareTo(at.distance()) >= 0)
.toList();
final Optional<Edge> pointGraphEdge = pointEdgeList.stream()

.max((e1, e2) -> e1.offset.compareTo(e2.offset));
if (pointGraphEdge.isPresent()) {
return splitGraphAt(pointEdgeGraph, at, pointGraphEdge.get(),
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 55f767b

Please sign in to comment.