You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
809 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package core.solver;
import core.problem.Problem;
import java.util.ArrayDeque;
import java.util.Deque;
public interface Searcher {
/**
* @problem 要解决的问题
* @return 当前问题的解路径。如果没有解则返回null
*/
Deque<Node> search(Problem problem);
/**
* 默认实现,从目标结点,反向回溯得到一条路径
* @param node 目标结点
* @return 倒推生成的从根结点到目标结点的路径,栈底是目标结点,栈顶是根结点
*/
default Deque<Node> generatePath(Node node) {
Deque<Node> stack = new ArrayDeque<>();
while (node.getParent() != null) {
stack.push(node);
node = node.getParent();
}
return stack;
}
}