Routing service:

remove routes with lower quality.
Select route if only one route found
This commit is contained in:
Jan 2025-09-27 20:43:36 +02:00
parent 466ad88c13
commit 0fcdb336cc

View file

@ -99,8 +99,9 @@ public class RoutingService {
*/
connectDestinationChainDirectly(container, destinationChains);
/* remove duplicates. */
removeDuplicateRoutes(container.getRoutes());
/* remove duplicates & lower qualities. */
removeDuplicateRoutes(container.getRoutes(), true);
/*
* finally find and mark the fastest and the cheapest route.
*/
@ -122,6 +123,10 @@ public class RoutingService {
routeInformation.add(routeInformationObj);
}
if(routeInformation.size() == 1) {
routeInformation.getFirst().getRoute().setSelected(true);
}
return routeInformation;
}
@ -484,16 +489,24 @@ public class RoutingService {
/*
* There might be duplicate routes now, because the same route can be created by "nearby-routing" and container rates
*/
removeDuplicateRoutes(routes);
removeDuplicateRoutes(routes, false);
container.overrideRoutes(routes);
}
private void removeDuplicateRoutes(Collection<TemporaryRouteObject> routes) {
private void removeDuplicateRoutes(Collection<TemporaryRouteObject> routes, boolean removeLowQuality) {
var toRemove = new ArrayList<TemporaryRouteObject>();
var bestQuality = routes.stream().map(TemporaryRouteObject::getQuality).reduce((q1, q2) -> q1.ordinal() < q2.ordinal() ? q1 : q2);
for (var route : routes) {
if(removeLowQuality && route.getQuality().ordinal() > bestQuality.get().ordinal()) {
toRemove.add(route);
continue;
}
var sections = route.getSections();
boolean hasNearByRouting = sections.getLast().getType().equals(TemporaryRateObject.TemporaryRateObjectType.NEAR_BY);
@ -924,6 +937,10 @@ public class RoutingService {
this.quality = quality;
}
public ChainQuality getQuality() {
return quality;
}
}