正如您可能猜到的,我正在使用Eclipse中的调试模式来调试我的代码。
我正在编写一个回溯算法(一个递归函数-它称为自己)。
在回溯函数中有一个for循环,在for循环的末尾,如果满足某些条件,则运行以下代码:Backtrack(csp, index + 1, CopyCSP(currentSolution));。
我正在调试我的代码,我想转到for循环的下一个迭代,所以当我到达这一行时,我点击了“步骤”。但是它会进入,并带领我完成下一个回溯函数。
我知道它实际上是下一个函数,因为正如您所看到的,index变量上升了1,这是发生的。
为什么会发生这种情况?我怎么才能避免这件事,而实际上却要走一步呢?如果这一步做不到我想做的事,我该用什么?
下面是我的完整函数的代码:
private void Backtrack(CSP csp, int index, CSP currentSolution) {
//BREAKPOINT IS HERE
if(index == csp.numVars) {
currentSolution.PrintSolution();
csp.PrintSolution(currentSolution);
solved = true;
return;
}
for(int test = 0; test < csp.MaxDomainSize(); test++) {
if(solved) {
return;
}
if(test < currentSolution.vars[index].domain.size) {
currentSolution.vars[index].value = currentSolution.vars[index].domain.get(test);
}
else {
continue;
}
boolean satisfied = true;
for(int i = 0; i < csp.constraints.size; i++) {
if(!csp.constraints.get(i).Satisfied(currentSolution.vars, index)) {
satisfied = false;
}
}
if(satisfied) {
System.out.println("Variable " + index + " satisfied by " + currentSolution.vars[index].value + ".");
Backtrack(csp, index + 1, CopyCSP(currentSolution));
}
}
}我已经在断点的位置发表了评论。
发布于 2018-05-15 02:30:04
按照思路,这是断点.
在大多数情况下,断点会停止控制流。
Eclipse有禁用单个断点和禁用所有断点的选项。对于有条件的断点,您的情况可能是正确的:
我自己也没有用过“命中计数”。
发布于 2018-12-19 21:41:48
我有一个类似的问题,并找到了类似的解决方案,张贴在这里供参考。
问题:
解决方案:
结果:
如果遇到了清晰和简单的共享,希望这会有所帮助。
https://stackoverflow.com/questions/50341390
复制相似问题