简体   繁体   English

如何实现非时间顺序回溯

[英]How to implement non chronological backtracking

I'm working on a CDCL SAT-Solver.我正在研究 CDCL SAT-Solver。 I don't know how to implement non-chronological backtracking.我不知道如何实现非时间顺序回溯。 Is this even possible with recursion or is it only possible in a iterative approach.这甚至可以通过递归实现还是只能在迭代方法中实现。

Actually what i have done jet is implemented a DPLL Solver which works with recursion.实际上我所做的 jet 是实现了一个 DPLL Solver,它可以与递归一起使用。 The great differnece from DPLL and CDCL ist that the backracking in the tree is not chronological.与 DPLL 和 CDCL 的最大区别在于树中的回溯不是按时间顺序排列的。 Is it even possible to implement something like this with recursion.甚至有可能用递归来实现这样的东西。 In my opionion i have two choices in the node of the binary-decision-tree if one of to path leads ia conlict:在我的选项中,如果 to 路径之一导致 ia 冲突,我在二叉决策树的节点中有两个选择:

  1. I try the other path -> but then it would be the same like the DPLL, means a chronological backtracking我尝试另一条路径 -> 但它会像 DPLL 一样,意味着按时间顺序回溯
  2. I return: But then i will never come back to this node.我返回:但是我将永远不会回到这个节点。

So am i missing here something.所以我在这里错过了什么。 Could it be that the only option is to implement it iterativly?难道唯一的选择是迭代地实现它吗?

Non-chronological backtracking (or backjumping as it is usually called) can be implemented in solvers that use recursion for the variable assignments.非时间顺序回溯(或通常称为回溯)可以在使用递归进行变量赋值的求解器中实现。 In languages that support non-local gotos, you would typically use that method.在支持非本地 goto 的语言中,您通常会使用该方法。 For example in the C language you would use setjmp() to record a point in the stack and longjmp() to backjump to that point.例如,在 C 语言中,您将使用 setjmp() 记录堆栈中的一个点,并使用 longjmp() 回跳到该点。 C# has try-catch blocks, Lispy languages might have catch-throw, and so on. C# 有 try-catch 块,Lispy 语言可能有 catch-throw 等等。

If the language doesn't support non-local goto, then you can implement a substitute in your code.如果语言不支持非本地 goto,那么您可以在代码中实现替代。 Instead of dpll() returning FALSE, have it return a tuple containing FALSE and the number of levels that need to be backtracked.而不是 dpll() 返回 FALSE,让它返回一个包含 FALSE 和需要回溯的级别数的元组。 Upstream callers decrement the counter in the tuple and return it until zero is returned.上游调用者递减元组中的计数器并返回它,直到返回零。

You can modify this to get backjumping.您可以修改它以获得回跳。

private Assignment recursiveBackJumpingSearch(CSP csp, Assignment assignment) {
    Assignment result = null;
    if (assignment.isComplete(csp.getVariables())) {
        result = assignment;
    }
    else {
        Variable var= selectUnassignedVariable(assignment, csp);

        for (Object value : orderDomainValues(var, assignment, csp)) {
            assignment.setAssignment(var, value);
            fireStateChanged(assignment, csp);
            if (assignment.isConsistent(csp.getConstraints(var))) {

                    result=recursiveBackJumpingSearch(csp, assignment);
                    if (result != null) {
                        break;
                    }
                    if (result == null)
                        numberOfBacktrack++;

            }
            assignment.removeAssignment(var);
        }
    }
    return result;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM