- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Principles of Artificial Intelligence :: Searching :: CSP
Backtracking Search for CSPs
Principles of Artificial Intelligence
1
Contents
6.3.1 Overview of Backtracking Search 6.3.2 Questions to Improve Backtracking
第一个解
4
6.3. Backtracking Search for CSPs
Overview of Backtracking Search 回溯搜索概述
It is the basic uninformed algorithm, a depth-first search with two improvements, for solving CSPs.
是基本的无信息算法,一种具有两种改进的深度优先搜索,用于求解CSPs问题。
Idea 1: One variable at a time 构思1:每次一个变量 Variable assignments are commutative, i.e.,
变量赋值是可交换的,例如
[WA = red then NT = green], same as [NT = green then WA = red]
也许需要检查该约束。递增式目标检测
Principles of Artificial Intelligence :: Searching :: CSP
5
6.3. Backtracking Search for CSPs
A Simple Backtracking Algorithm for CSPs 一个简单的CSPs回溯算法
回溯搜索递增地构建解的候选,而且一旦确定部分候选c不能成为一个合法的解,就将c抛弃(回 溯)。
Example: 8-queens puzzle 8皇后难题 In the common backtracking approach, the partial candidates are arrangements of
是一种深度优先搜索的通用算法,用于查找某些计算问题的答案,尤其是CSPs。
Backtracking search incrementally builds candidates to the solutions, and abandons each partial candidate c (backtracks), as soon as it determines that c cannot possibly be completed to a valid solution.
k queens in the first k rows of the board, all in different rows and columns.
常见的回溯方法,部分候选是在棋盘的在前k行上布局k个皇后,所有这些要在不同的行与列上。
Principles of Artificial Intelligence :: Searching :: CSP
Idea 2: Check constraints as you go 构思2:检查所需约束 I.e., consider only values which do not conflict previous assignments
即,仅需考虑与前面赋值不发生冲突的值
Might have to check the constraints. “Incremental goal test”
3
6.3. Backtracking Search for CSPs
Example: 4-queen problem 4皇后问题
①
②
⑥
③
④
⑦
Failure
失败
⑤
⑧
Impasse
僵局
Principles of Artificial Intelligence :: Searching :: CSP
⑨百度文库
First solution
Principles of Artificial Intelligence
2
6.3. Backtracking Search for CSPs
Overview of Backtracking Search 回溯搜索概述
It is a general algorithm on depth-first search, used for finding solutions to some computational problems, notably CSPs.
function BACKTRACK-SEARCH(csp) returns a solution, or failure return BACKTRACK({ }, csp)
function BACKTRACK(assignment, csp) returns a solution, or failure if assignment is complete then return assignment var ← SELECT-UNASSIGNED-VARIABLE(csp) for each value in ORDER-DOMAIN-VALUES(var, assignment, csp) do if value is consistent with assignment then add {var = value} to assignment inferences ← INFERENCE(csp, var, value) if inferences ≠ failure then add inferences to assignment result ← BACKTRACK(assignment, csp) if result = failure then return result remove {var = value} and inferences from assignment return failure