From e3cd83ed32f778b89e41b4254ebbead966c23473 Mon Sep 17 00:00:00 2001 From: Mo Date: Thu, 22 Oct 2015 23:02:47 +0300 Subject: [PATCH] filtered vendors before build graph and specification --- core/src/main/java/ru/trader/analysis/RouteSearcher.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/main/java/ru/trader/analysis/RouteSearcher.java b/core/src/main/java/ru/trader/analysis/RouteSearcher.java index 574ce10..5a3071c 100644 --- a/core/src/main/java/ru/trader/analysis/RouteSearcher.java +++ b/core/src/main/java/ru/trader/analysis/RouteSearcher.java @@ -11,6 +11,7 @@ import ru.trader.core.Vendor; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; public class RouteSearcher { private final static Logger LOG = LoggerFactory.getLogger(RouteSearcher.class); @@ -48,6 +49,7 @@ public class RouteSearcher { LOG.trace("Start search path from {} to {} ", source, target); ConnectibleGraph graph = new ConnectibleGraph<>(profile, callback); LOG.trace("Build connectible graph"); + places = filtered(source, places); graph.build(source, places); LOG.trace("Graph is builds"); List>> paths = new ArrayList<>(); @@ -67,6 +69,7 @@ public class RouteSearcher { LOG.trace("Start search route from {} to {}", source, target); VendorsGraph vGraph = new VendorsGraph(scorer, callback); LOG.trace("Build vendors graph"); + vendors = filtered(source, vendors); vGraph.build(source, vendors); LOG.trace("Graph is builds"); RouteCollector collector = new RouteCollector(); @@ -82,6 +85,7 @@ public class RouteSearcher { LOG.trace("Start search loops from {}", source); VendorsGraph vGraph = new VendorsGraph(scorer, callback); LOG.trace("Build vendors graph"); + vendors = filtered(source, vendors); vGraph.build(source, vendors); LOG.trace("Graph is builds"); RouteCollector collector = new RouteCollector(); @@ -106,6 +110,11 @@ public class RouteSearcher { return routes; } + protected > Collection filtered(T from, Collection set){ + final double maxDistance = scorer.getProfile().getShip().getMaxJumpRange() * scorer.getProfile().getJumps(); + return set.parallelStream().filter(v -> from.getDistance(v) <= maxDistance).collect(Collectors.toList()); + } + private class RouteCollector { private List routes = new ArrayList<>();