Fix find fast if source is not root
This commit is contained in:
@@ -96,9 +96,10 @@ public class Crawler<T> {
|
|||||||
setTarget(target);
|
setTarget(target);
|
||||||
if (count > 1 || s.isEntry(target)) {
|
if (count > 1 || s.isEntry(target)) {
|
||||||
int maxDeep = maxSize - (s.isEntry(target) ? graph.getMinJumps() * 2 : graph.getMinJumps());
|
int maxDeep = maxSize - (s.isEntry(target) ? graph.getMinJumps() * 2 : graph.getMinJumps());
|
||||||
|
if (maxDeep < 0) maxDeep = 0;
|
||||||
found = bfs(start(s), maxDeep, count);
|
found = bfs(start(s), maxDeep, count);
|
||||||
} else {
|
} 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);
|
LOG.debug("Found {} paths", found);
|
||||||
@@ -168,7 +169,7 @@ public class Crawler<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!stop && found < count){
|
if (!stop && found < count){
|
||||||
if (deep < source.getLevel() && entry.size() < maxSize-1) {
|
if (deep <= source.getLevel() && entry.size() < maxSize-1) {
|
||||||
LOG.trace("Search around");
|
LOG.trace("Search around");
|
||||||
for (Edge<T> edge : entry.getEdges()) {
|
for (Edge<T> edge : entry.getEdges()) {
|
||||||
if (edge.getTarget().isSingle()) continue;
|
if (edge.getTarget().isSingle()) continue;
|
||||||
|
|||||||
@@ -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<Point> 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<Point> paths = new SimpleCollector<>();
|
||||||
|
CCrawler<Point> 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
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user