diff --git a/java/bundles/org.eclipse.set.application/src/org/eclipse/set/application/graph/BankServiceImpl.java b/java/bundles/org.eclipse.set.application/src/org/eclipse/set/application/graph/BankServiceImpl.java index 52ea4ae11..9bf1972cf 100644 --- a/java/bundles/org.eclipse.set.application/src/org/eclipse/set/application/graph/BankServiceImpl.java +++ b/java/bundles/org.eclipse.set.application/src/org/eclipse/set/application/graph/BankServiceImpl.java @@ -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()); } } @@ -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(); diff --git a/java/bundles/org.eclipse.set.application/src/org/eclipse/set/application/graph/TopologicalGraphServiceImpl.java b/java/bundles/org.eclipse.set.application/src/org/eclipse/set/application/graph/TopologicalGraphServiceImpl.java index bca930e0f..21bf5556b 100644 --- a/java/bundles/org.eclipse.set.application/src/org/eclipse/set/application/graph/TopologicalGraphServiceImpl.java +++ b/java/bundles/org.eclipse.set.application/src/org/eclipse/set/application/graph/TopologicalGraphServiceImpl.java @@ -144,7 +144,8 @@ public Optional 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 path) { diff --git a/java/bundles/org.eclipse.set.basis/src/org/eclipse/set/basis/graph/TopPath.java b/java/bundles/org.eclipse.set.basis/src/org/eclipse/set/basis/graph/TopPath.java index ab69bb56f..ac8c50252 100644 --- a/java/bundles/org.eclipse.set.basis/src/org/eclipse/set/basis/graph/TopPath.java +++ b/java/bundles/org.eclipse.set.basis/src/org/eclipse/set/basis/graph/TopPath.java @@ -23,7 +23,7 @@ public class TopPath { private final List edges; private final BigDecimal length; - private final BigDecimal offset; // offset from start of first edge + private final BigDecimal firstEdgeLength; /** * @param edges @@ -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 edges, final BigDecimal length, - final BigDecimal offset) { + final BigDecimal firstEdgeLength) { this.edges = edges; this.length = length; - this.offset = offset; + this.firstEdgeLength = firstEdgeLength; } /** @@ -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; } /** @@ -74,7 +72,7 @@ public BigDecimal offset() { * on the path */ public Optional getDistance(final TopPoint point) { - BigDecimal pathOffset = this.offset.negate(); + BigDecimal pathOffset = this.firstEdgeLength; TOP_Kante previousEdge = null; for (final TOP_Kante edge : edges()) { @@ -83,7 +81,7 @@ public Optional 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() @@ -108,15 +106,15 @@ public Optional 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(); - } - } diff --git a/java/bundles/org.eclipse.set.feature.plazmodel/src/org/eclipse/set/feature/plazmodel/check/BankValues.xtend b/java/bundles/org.eclipse.set.feature.plazmodel/src/org/eclipse/set/feature/plazmodel/check/BankValues.xtend index b08557088..7a6aa2c9d 100644 --- a/java/bundles/org.eclipse.set.feature.plazmodel/src/org/eclipse/set/feature/plazmodel/check/BankValues.xtend +++ b/java/bundles/org.eclipse.set.feature.plazmodel/src/org/eclipse/set/feature/plazmodel/check/BankValues.xtend @@ -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, diff --git a/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/AsDirectedTopGraph.java b/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/AsDirectedTopGraph.java index 4158f87f1..3bcb15aeb 100644 --- a/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/AsDirectedTopGraph.java +++ b/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/AsDirectedTopGraph.java @@ -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; @@ -303,8 +304,9 @@ private static List> findRelevantEdgesFromTarget( // Check whether the incoming edges of this node are correctly // decorated - for (final DirectedTOPEdge edge : graph - .incomingEdgesOf(vertex)) { + final Set> incomingEdgesOf = graph + .incomingEdgesOf(vertex); + for (final DirectedTOPEdge edge : incomingEdgesOf) { // Mark the edge if needed final BigDecimal weight = edge.edge().getWeight(); final BigDecimal remainingWeight = currentRemaining @@ -320,6 +322,12 @@ private static List> 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(); diff --git a/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/AsSplitTopGraph.java b/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/AsSplitTopGraph.java index b86e85d59..36bb9fd3a 100644 --- a/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/AsSplitTopGraph.java +++ b/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/AsSplitTopGraph.java @@ -176,7 +176,6 @@ public Node splitGraphAt(final TopPoint at) { */ public Node splitGraphAt(final TopPoint at, final Boolean inTopDirection) { final TOP_Kante edge = at.edge(); - final List pointEdgeList = pointEdgeGraph.edgeSet().stream() .filter(c -> c.edge == edge) .filter(c -> c.offset.compareTo(at.distance()) <= 0) @@ -184,7 +183,6 @@ public Node splitGraphAt(final TopPoint at, final Boolean inTopDirection) { .compareTo(at.distance()) >= 0) .toList(); final Optional pointGraphEdge = pointEdgeList.stream() - .max((e1, e2) -> e1.offset.compareTo(e2.offset)); if (pointGraphEdge.isPresent()) { return splitGraphAt(pointEdgeGraph, at, pointGraphEdge.get(), diff --git a/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/DirectedPathSearch.java b/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/DirectedPathSearch.java index 8fbeab8b3..5c8bc9fc6 100644 --- a/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/DirectedPathSearch.java +++ b/java/bundles/org.eclipse.set.utils/src/org/eclipse/set/utils/graph/DirectedPathSearch.java @@ -229,14 +229,19 @@ public TopPath getTopPath(final Predicate condition, private static TopPath pathTransform( final GraphPath> path, final Node startNode) { - if (!path.getStartVertex().equals(startNode)) { + final DirectedTOPEdge 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(