Browse Source

improved route planner

lookup-tables
Stephan Richter 5 years ago
parent
commit
44f6fe292e
  1. 2
      pom.xml
  2. 27
      src/main/java/de/srsoftware/web4rail/PathFinder.java

2
pom.xml

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId>
<version>1.2.62</version>
<version>1.2.63</version>
<name>Web4Rail</name>
<packaging>jar</packaging>
<description>Java Model Railway Control</description>

27
src/main/java/de/srsoftware/web4rail/PathFinder.java

@ -53,8 +53,14 @@ public class PathFinder extends BaseClass{ @@ -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{ @@ -102,12 +108,21 @@ public class PathFinder extends BaseClass{
public static Route chooseRoute(Context context) {
LOG.debug("PathFinder.chooseRoute({})",context);
TreeMap<Integer, List<Route>> availableRoutes = PathFinder.availableRoutes(context,new HashSet<Route>());
if (availableRoutes.isEmpty()) return null;
while (!availableRoutes.isEmpty()) {
LOG.debug("availableRoutes: {}",availableRoutes);
Entry<Integer, List<Route>> entry = availableRoutes.lastEntry();
List<Route> preferredRoutes = entry.getValue();
Route selectetRoute = preferredRoutes.get(random.nextInt(preferredRoutes.size()));
LOG.debug("Chose \"{}\" with priority {}.",selectetRoute,entry.getKey());
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;
}
}

Loading…
Cancel
Save