diff --git a/pom.xml b/pom.xml
index ef7e8df..a1322f9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
de.srsoftware
web4rail
- 1.2.62
+ 1.2.63
Web4Rail
jar
Java Model Railway Control
diff --git a/src/main/java/de/srsoftware/web4rail/PathFinder.java b/src/main/java/de/srsoftware/web4rail/PathFinder.java
index 87f6acf..1baf484 100644
--- a/src/main/java/de/srsoftware/web4rail/PathFinder.java
+++ b/src/main/java/de/srsoftware/web4rail/PathFinder.java
@@ -53,8 +53,14 @@ public class PathFinder extends BaseClass{
LOG.debug("{}→ Candidate {} would create loop, skipping",inset,routeCandidate.shortName());
continue;
}
- if (!routeCandidate.allowed(context)) continue; // Zug darf auf Grund einer nicht erfüllten Bedingung nicht auf die Route
- if (!routeCandidate.isFreeFor(context.route(routeCandidate))) continue; // Route ist nicht frei
+ if (!routeCandidate.allowed(context)) {
+ if (routeCandidate.endBlock() != destination) { // allowance may be overridden by destination
+ LOG.debug("{} not allowed for {}",routeCandidate,context);
+ continue; // Zug darf auf Grund einer nicht erfüllten Bedingung nicht auf die Route
+ }
+ LOG.debug("{} not allowed for {} – overridden by selected destination",routeCandidate,context);
+ }
+
int priority = 0;
if (isSet(direction) && routeCandidate.startDirection != direction) { // Route startet entgegen der aktuellen Fahrtrichtung des Zuges
if (!train.pushPull) continue; // Zug kann nicht wenden
@@ -102,12 +108,21 @@ public class PathFinder extends BaseClass{
public static Route chooseRoute(Context context) {
LOG.debug("PathFinder.chooseRoute({})",context);
TreeMap> availableRoutes = PathFinder.availableRoutes(context,new HashSet());
- if (availableRoutes.isEmpty()) return null;
- Entry> entry = availableRoutes.lastEntry();
- List preferredRoutes = entry.getValue();
- Route selectetRoute = preferredRoutes.get(random.nextInt(preferredRoutes.size()));
- LOG.debug("Chose \"{}\" with priority {}.",selectetRoute,entry.getKey());
+ while (!availableRoutes.isEmpty()) {
+ LOG.debug("availableRoutes: {}",availableRoutes);
+ Entry> entry = availableRoutes.lastEntry();
+ List preferredRoutes = entry.getValue();
+ LOG.debug("preferredRoutes: {}",preferredRoutes);
+ Route selectedRoute = preferredRoutes.get(random.nextInt(preferredRoutes.size()));
+ if (selectedRoute.isFreeFor(context.route(selectedRoute))) {
+ LOG.debug("Chose \"{}\" with priority {}.",selectedRoute,entry.getKey());
+ return selectedRoute;
+ }
- return selectetRoute;
+ LOG.debug("Selected route \"{}\" is not free for {}",selectedRoute,context);
+ preferredRoutes.remove(selectedRoute);
+ if (preferredRoutes.isEmpty()) availableRoutes.remove(availableRoutes.lastKey());
+ }
+ return null;
}
}