diff --git a/core/src/main/java/ru/trader/core/MarketAnalyzer.java b/core/src/main/java/ru/trader/core/MarketAnalyzer.java index 89547d8..81e7007 100644 --- a/core/src/main/java/ru/trader/core/MarketAnalyzer.java +++ b/core/src/main/java/ru/trader/core/MarketAnalyzer.java @@ -187,19 +187,19 @@ public class MarketAnalyzer { } public Collection getPaths(Place from, Place to, double balance){ + List top = new ArrayList<>(limit); RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize); Collection vendors = market.getVendors(); Collection fVendors = from.get(); Collection toVendors = to.get(); + int count = (int) Math.ceil(limit / fVendors.size()); for (Vendor fromVendor : fVendors) { for (Vendor toVendor : toVendors) { - Collection paths = searcher.getPaths(fromVendor, toVendor, vendors, jumps, balance, cargo, limit); - if (paths.size()>0){ - return paths; - } + Collection paths = searcher.getPaths(fromVendor, toVendor, vendors, jumps, balance, cargo, count); + TopList.addAllToTop(top, paths, limit, RouteGraph.byProfitComparator); } } - return Collections.emptyList(); + return top; } public Collection getPaths(Vendor from, Place to, double balance){ @@ -207,24 +207,25 @@ public class MarketAnalyzer { RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize); Collection vendors = market.getVendors(); Collection toVendors = to.get(); + int count = (int) Math.ceil(limit / toVendors.size()); for (Vendor toVendor : toVendors) { - Collection paths = searcher.getPaths(from, toVendor, vendors, jumps, balance, cargo, limit); + Collection paths = searcher.getPaths(from, toVendor, vendors, jumps, balance, cargo, count); TopList.addAllToTop(top, paths, limit, RouteGraph.byProfitComparator); } return top; } public Collection getPaths(Place from, Vendor to, double balance){ + List top = new ArrayList<>(limit); RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize); Collection vendors = market.getVendors(); Collection fVendors = from.get(); + int count = (int) Math.ceil(limit / fVendors.size()); for (Vendor fromVendor : fVendors) { - Collection paths = searcher.getPaths(fromVendor, to, vendors, jumps, balance, cargo, limit); - if (paths.size()>0){ - return paths; - } + Collection paths = searcher.getPaths(fromVendor, to, vendors, jumps, balance, cargo, count); + TopList.addAllToTop(top, paths, limit, RouteGraph.byProfitComparator); } - return Collections.emptyList(); + return top; } public Collection getTopPaths(double balance){