diff --git a/core/src/main/java/ru/trader/analysis/graph/Crawler.java b/core/src/main/java/ru/trader/analysis/graph/Crawler.java index 1787105..d07e805 100644 --- a/core/src/main/java/ru/trader/analysis/graph/Crawler.java +++ b/core/src/main/java/ru/trader/analysis/graph/Crawler.java @@ -96,9 +96,10 @@ public class Crawler { setTarget(target); if (count > 1 || s.isEntry(target)) { int maxDeep = maxSize - (s.isEntry(target) ? graph.getMinJumps() * 2 : graph.getMinJumps()); + if (maxDeep < 0) maxDeep = 0; found = bfs(start(s), maxDeep, count); } else { - found = dfs(start(s), t.get().getLevel() + 1, count); + found = dfs(start(s), Math.min(t.get().getLevel() + 1, s.getLevel()), count); } } LOG.debug("Found {} paths", found); @@ -168,7 +169,7 @@ public class Crawler { } } if (!stop && found < count){ - if (deep < source.getLevel() && entry.size() < maxSize-1) { + if (deep <= source.getLevel() && entry.size() < maxSize-1) { LOG.trace("Search around"); for (Edge edge : entry.getEdges()) { if (edge.getTarget().isSingle()) continue; diff --git a/core/src/test/java/ru/trader/analysis/graph/CrawlerTest.java b/core/src/test/java/ru/trader/analysis/graph/CrawlerTest.java index d5e1626..496ed62 100644 --- a/core/src/test/java/ru/trader/analysis/graph/CrawlerTest.java +++ b/core/src/test/java/ru/trader/analysis/graph/CrawlerTest.java @@ -260,6 +260,42 @@ public class CrawlerTest extends Assert { } + @Test + public void testGetCustomPaths() throws Exception { + LOG.info("Start get custom paths"); + //max distance 15.6, 1 jump tank + Ship ship = new Ship(); + ship.setMass(18);ship.setTank(0.6); + Profile profile = new Profile(ship); + profile.setJumps(4); + LOG.info("Ship = {}, Jumps = {}", profile.getShip(), profile.getJumps()); + ConnectibleGraph graph = new ConnectibleGraph<>(profile); + graph.build(x5, entrys); + // x5 <-> x4 <-> x3 - refill -> x2, + // x5 <-> x6 <-> x4 <-refill -> x2 + // x5 <-> x3 <- refill -> x2 + // x5 <-> x4 <- refill -> x6 + SimpleCollector paths = new SimpleCollector<>(); + CCrawler crawler = new CCrawler<>(graph, paths::add); + + crawler.setStartFuel(0.3); + crawler.findMin(x3, x2); + assertPaths(paths.get(), PPath.of(x3, x2)); + paths.clear(); + + crawler.findFast(x3, x2); + assertPaths(paths.get(), PPath.of(x3, x2)); + paths.clear(); + + crawler.setStartFuel(0.6); + crawler.findMin(x6, x2); + assertPaths(paths.get(), PPath.of(x6, x4, x2)); + paths.clear(); + + crawler.findFast(x6, x2); + assertPaths(paths.get(), PPath.of(x6, x4, x2)); + paths.clear(); + } @After public void tearDown() throws Exception {