AI约束满足问题CSP.ppt_第1页
AI约束满足问题CSP.ppt_第2页
AI约束满足问题CSP.ppt_第3页
AI约束满足问题CSP.ppt_第4页
AI约束满足问题CSP.ppt_第5页
已阅读5页,还剩72页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

约束满足问题 (CSP) Constraint Satisfaction Problems (CSP) (对于困难的决策,我们将推迟到它变得容易的时候再做决定) R&N: Chap. 5,我们想做些什么?,搜索技术通常按照一个任意的次序对可能进行选择,一般很少有效的信息能够帮助如何进行选择 在许多问题中,状态的到达与进行选择的次序无关(“可交换”) ,即采取不同的次序进行选择也一样可以到达同一个状态 那能否通过选定某种适合的选择次序能够更有效的解决这些问题呢?甚至可以避免进行选择?,约束传播 Constraint Propagation,将一个皇后放入到一个方格里 移去所有可能攻击到的方格,6 6 5 5 5 5 6,5 5 5 5 5 6 7,Constraint Propagation,计算每一行、每一列不会受到攻击的方格数 将一个皇后放置在有着最小数目的行或列上 再次移去可能受到攻击的所有方格,3 4 4 3 3 5,4 3 3 3 4 5,重复前述过程,Constraint Propagation,4 3 2 3 4,3 3 3 4 3,Constraint Propagation,4 2 2 1 3,3 3 3 1,Constraint Propagation,2 2 1,2 2 1,Constraint Propagation,Constraint Propagation,2 1,1 2,Constraint Propagation,1,1,Constraint Propagation,我们需要些什么?,后继函数与目标测试 还需要: 通过约束传播( propagate the constraints )信息,比如通过对一个皇后位置的约束来影响其他皇后的位置 提前的失败测试(failure test) 约束的清晰表示 约束传播算法,约束满足问题 (CSP) Constraint Satisfaction Problem (CSP),变量的集合 variables X1, X2, , Xn 每一个变量Xi所有可能的取值,构成该变量的值域Di;通常Di是有限的 约束的集合 constraints C1, C2, , Cp 每个约束描述了一个变量子集与特定的某些值合法的结合对应关系 目标: 每一个变量都得到了一个赋值,且所有的约束得到满足,地图着色问题,7 个变量 WA,NT,SA,Q,NSW,V,T 每个变量的值域是一样的: red, green, blue 两个相邻的变量不能取相同的值: WANT, WASA, NTSA, NTQ, SAQ, SANSW, SAV,QNSW, NSWV,8-皇后问题,8 个变量 Xi, i = 1 to 8 每个变量的值域均为: 1,2,8 约束表示为如下形式: Xi = k Xj k for all j = 1 to 8, ji 对角线也是相同的约束,Street Puzzle(课本习题5.13),Ni = English, Spaniard, Japanese, Italian, Norwegian Ci = Red, Green, White, Yellow, Blue Di = Tea, Coffee, Milk, Fruit-juice, Water Ji = Painter, Sculptor, Diplomat, Violinist, Doctor Ai = Dog, Snails, Fox, Horse, Zebra,The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctors The Horse is next to the Diplomats,Who owns the Zebra? Who drinks Water?,Street Puzzle,Ni = English, Spaniard, Japanese, Italian, Norwegian Ci = Red, Green, White, Yellow, Blue Di = Tea, Coffee, Milk, Fruit-juice, Water Ji = Painter, Sculptor, Diplomat, Violinist, Doctor Ai = Dog, Snails, Fox, Horse, Zebra,The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctors The Horse is next to the Diplomats,Street Puzzle,Ni = English, Spaniard, Japanese, Italian, Norwegian Ci = Red, Green, White, Yellow, Blue Di = Tea, Coffee, Milk, Fruit-juice, Water Ji = Painter, Sculptor, Diplomat, Violinist, Doctor Ai = Dog, Snails, Fox, Horse, Zebra,The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctors The Horse is next to the Diplomats,(Ni = English) (Ci = Red),(Ni = Japanese) (Ji = Painter),(N1 = Norwegian),(Ci = White) (Ci+1 = Green) (C5 White) (C1 Green),Street Puzzle,Ni = English, Spaniard, Japanese, Italian, Norwegian Ci = Red, Green, White, Yellow, Blue Di = Tea, Coffee, Milk, Fruit-juice, Water Ji = Painter, Sculptor, Diplomat, Violinist, Doctor Ai = Dog, Snails, Fox, Horse, Zebra,The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctors The Horse is next to the Diplomats,(Ni = English) (Ci = Red),(Ni = Japanese) (Ji = Painter),(N1 = Norwegian),(Ci = White) (Ci+1 = Green) (C5 White) (C1 Green),一元(unary)约束,Street Puzzle,Ni = English, Spaniard, Japanese, Italian, Norwegian Ci = Red, Green, White, Yellow, Blue Di = Tea, Coffee, Milk, Fruit-juice, Water Ji = Painter, Sculptor, Diplomat, Violinist, Doctor Ai = Dog, Snails, Fox, Horse, Zebra,The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left N1 = Norwegian The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk D3 = Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctors The Horse is next to the Diplomats,Street Puzzle,Ni = English, Spaniard, Japanese, Italian, Norwegian Ci = Red, Green, White, Yellow, Blue Di = Tea, Coffee, Milk, Fruit-juice, Water Ji = Painter, Sculptor, Diplomat, Violinist, Doctor Ai = Dog, Snails, Fox, Horse, Zebra,The Englishman lives in the Red house C1 Red The Spaniard has a Dog A1 Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left N1 = Norwegian The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk D3 = Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice J3 Violinist The Fox is in the house next to the Doctors The Horse is next to the Diplomats,有限CSP vs. 无限CSP Finite vs. Infinite CSP,有限CSP : 每个变量的值域有有限个值 无限CSP : 一些或所有的变量的值域是无限的 E.g., 实数线性规划: 本课程只讨论有限CSP,CSP 描述为搜索问题,n个变量 X1, ., Xn 合法赋值 : Xi1 vi1, ., Xik vik, 0 k n, 即取值vi1, ., vik满足所有与变量Xi1, ., Xik有关的约束 完全赋值: k由0到n,每个变量都得到了赋值 变量值域大小为d, 则有O(dn) 种完全赋值 状态: 合法赋值 初始状态: 空赋值 , 即 k = 0,也就是还没有变量得到赋值 状态的后继: Xi1vi1, ., Xikvik Xi1vi1, ., Xikvik, Xik+1vik+1 目标测试: k = n,即n个变量都得到了赋值,4 变量 X1, ., X4 令节点N的合法赋值为: A = X1 v1, X3 v3 以为变量X4取值为例 令X4 的值域为 v4,1, v4,2, v4,3 A的后继为以下赋值中的合法赋值: X1 v1, X3 v3 , X4 v4,1 X1 v1, X3 v3 , X4 v4,2 X1 v1, X3 v3 , X4 v4,3 ,回溯搜索 Backtracking Search,本质即使用递归的简化深度优先算法,回溯搜索 (3 变量),赋值 Assignment = ,赋值 Assignment = (X1,v11),X1,v11,回溯搜索 (3 变量),赋值 Assignment = (X1,v11), (X3,v31),X1,v11,v31,X3,回溯搜索 (3 变量),赋值 Assignment = (X1,v11), (X3,v31),X1,v11,v31,X3,X2,假设没有一个X2的取值能构成合法赋值,回溯搜索 (3 变量),赋值 Assignment = (X1,v11), (X3,v32),X1,v11,X3,v32,v31,X2,回溯搜索 (3 变量),赋值 Assignment = (X1,v11), (X3,v32),X1,v11,X3,v32,X2,假设仍然没有一个X2的取值能构成合法赋值,搜索算法回溯到前一个变量(X3)并尝试另外的赋值。但假设X3只有两个可能的取值。于是算法回溯到X1,v31,X2,回溯搜索 (3 变量),赋值 Assignment = (X1,v12),X1,v11,X3,v32,X2,v31,X2,v12,回溯搜索 (3 变量),Assignment = (X1,v12), (X2,v21),X1,v11,X3,v32,X2,v31,X2,v12,v21,X2,回溯搜索 (3 变量),Assignment = (X1,v12), (X2,v21),X1,v11,X3,v32,X2,v31,X2,v12,v21,X2,回溯搜索 (3 变量),Assignment = (X1,v12), (X2,v21), (X3,v32),X1,v11,X3,v32,X2,v31,X2,v12,v21,X2,v32,X3,回溯搜索 (3 变量),Assignment = (X1,v12), (X2,v21), (X3,v32),X1,v11,X3,v32,X2,v31,X2,v12,v21,X2,v32,X3,算法不需要考虑那些在其它 子树中次序一样的X3赋值,回溯搜索 (3 变量),Assignment = (X1,v12), (X2,v21), (X3,v32),X1,v11,X3,v32,X2,v31,X2,v12,v21,X2,v32,X3,由于只有三个变量,因此 赋值已完全,回溯搜索 (3 变量),回溯算法 Backtracking Algorithm,CSP-BACKTRACKING(A) If assignment A is complete then return A X select a variable not in A D select an ordering on the domain of X For each value v in D do Add (Xv) to A If A is valid then result CSP-BACKTRACKING(A) If result failure then return result Return failure Call CSP-BACKTRACKING(),该递归算法会保存太多的数据到内存中,用迭代改进将会节省许多内存, 感兴趣的同学可以进一步思考。,地图着色问题 Map Coloring,CSP回溯效率的关键问题,CSP-BACKTRACKING(A) If assignment A is complete then return A X select a variable not in A D select an ordering on the domain of X For each value v in D do Add (Xv) to A If a is valid then result CSP-BACKTRACKING(A) If result failure then return result Return failure,下一个将选择哪一个变量来赋值? The current assignment may not lead to any solution, but the algorithm still does know it. Selecting the right variable to which to assign a value may help discover the contradiction more quickly 变量X的(多个)值应该按一个什么样的次序进行赋值? The current assignment may be part of a solution. Selecting the right value to assign to X may help discover this solution more quickly More on these questions in a short while .,CSP回溯效率的关键问题,下一个将选择哪一个变量来赋值? 当前的赋值不一定就能得到问题的解,正确的选择一个变量将有助于更快的发现约束关系 变量X的(多个)值应该按一个什么样的次序进行赋值? The current assignment may be part of a solution. Selecting the right value to assign to X may help discover this solution more quickly More on these questions in a short while .,CSP回溯效率的关键问题,下一个将选择哪一个变量来赋值? 当前的赋值不一定就能得到问题的解,正确的选择一个变量将有助于更快的发现约束关系 变量X的(多个)值应该按一个什么样的次序进行赋值? 当前的赋值可能会是解的一部分,正确的选择一个值赋给X将有助于更快的找到解 More on these questions in a short while .,CSP回溯效率的关键问题,下一个将选择哪一个变量来赋值? 当前的赋值不一定就能得到问题的解,正确的选择一个变量将有助于更快的发现约束关系 变量X的(多个)值应该按一个什么样的次序进行赋值? 当前的赋值可能会是解的一部分,正确的选择一个值赋给X将有助于更快的找到解 有关问题将很快得到解答,CSP回溯效率的关键问题,前向检验 Forward Checking,把值5赋给X1导致变量X2, X3, ., X8 的值域减小(值域中的一些值被移去),一种简单的约束传播技术 :,地图着色问题的前向检验,地图着色问题的前向检验,地图着色问题的前向检验,地图着色问题的前向检验,空集:当前的赋值 (WA R), (Q G), (V B) 无法得到(构成)问题的解,地图着色问题的前向检验,前向检验 (通用形式),一旦一对变量和值(Xv)加入到赋值A ,则 do: 对于每个A之外的变量 do: 对每一个与联系Y和A中的变量的约束C do: 将所有不满足C的值从Y的值域中移去,回溯算法修改,CSP-BACKTRACKING(A, var-domains) If assignment A is complete then return A X select a variable not in A D select an ordering on the domain of X For each value v in D do Add (Xv) to A var-domains forward checking(var-domains, X, v, A) If a variable has an empty domain then return failure result CSP-BACKTRACKING(A, var-domains) If result failure then return result Return failure,CSP-BACKTRACKING(A, var-domains) If assignment A is complete then return A X select a variable not in A D select an ordering on the domain of X For each value v in D do Add (Xv) to A var-domains forward checking(var-domains, X, v, A) If a variable has an empty domain then return failure result CSP-BACKTRACKING(A, var-domains) If result failure then return result Return failure,不再需要校验A是否合法,回溯算法修改,CSP-BACKTRACKING(A, var-domains) If assignment A is complete then return A X select a variable not in A D select an ordering on the domain of X For each value v in D do Add (Xv) to A var-domains forward checking(var-domains, X, v, A) If a variable has an empty domain then return failure result CSP-BACKTRACKING(A, var-domains) If result failure then return result Return failure,需要传递更新后的变量值域,回溯算法修改,CSP-BACKTRACKING(A, var-domains) If assignment A is complete then return A X select a variable not in A D select an ordering on the domain of X For each value v in D do Add (Xv) to A var-domains forward checking(var-domains, X, v, A) If a variable has an empty domain then return failure result CSP-BACKTRACKING(A, var-domains) If result failure then return result Return failure,回溯算法修改,下一个将选择哪一个变量来赋值? 最多约束变量启发式 Most-constrained-variable heuristic 最多约束变量启发式 Most-constrained-variable heuristic 对该变量的赋值应该按照什么次序进行尝试? 最少约束值启发式 Least-constraining-value heuristic,以上启发式规则容易使人困惑 记住所有的变量最终都将得到一个赋值,然而值域中仅有一个值必须赋给变量,最多约束变量启发式,下一个将选择哪一个变量来赋值? 选择具有最少剩余值的变量 基本原理: 将分支因子最小化,8-Queens,4 3 2 3 4,前向检验,8-Queens,4 2 1 3,前向检验,Map Coloring,SA的剩余值域大小为1(剩余值Blue) Q的剩余值域大小为2 NSW, V 和 T的剩余值域大小为3 选择 SA,最多约束变量启发式,下一个将选择哪一个变量来赋值? 在同样拥有最小剩余值域的多个变量(即受到的约束最多)中,选择其中受到其他未赋值变量的约束个数最多的变量 基本原理: 增加未来移去值的数量,以减少未来的分支因子,Map Coloring,在未进行任何赋值之前,所有变量的值域大小均为3,但SA陷入的约束个数(5)比其他变量多 选择SA并对其进行赋值(如 Blue),最少约束值启发式,对选定变量的赋值应该按照什么次序进行? 选择X的一个值首先对X进行赋值,该值将最少的移去当前赋值之外的变量值域的值 基本原理: 由于仅有一个值最终会赋给X ,应首先选取最少约束的值,因为该值看起来最不可能导致非法的赋值 说明: 需要对所有的值采用启发式进行前向检验,而不仅是针对已选的值,Map Coloring,Q的值域还剩余两个值: Blue and Red 把Blue赋给Q ,则导致SA剩余0个值,而赋Red则剩余1个值,Blue,Map Coloring,Q的值域还剩余两个值: Bl

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论