Constraint Satisfaction problems
identification problem(只关心结果,不关心path)
planning v.s. identification
- planning problems: search problem
following path will result a goal
path has various cost
heuristics give problems a guide
state is a black-box,and goal test is performed on state - identification problems: CSP
all paths have the same cost
goal is important , path doesn’t matter
state id a feature vector, goal test is constraint on the feature vector
CSP factors(构成)
- variable:
{
X
1
,
⋯
,
X
N
}
\{X_1,\cdots,X_N\}
{X1,⋯,XN}
discrete or continuous - domain
- constraints:变量的值约束
unary constraints: not graph, prune the domain
binary constraints:
higher-order constraints: 3 or more variables
global constraints
preference: often reperesent by cost of each assignment
补充一些概念
feature vector
一个state 被一个完全赋值的vector明确
partitial assignment/ complete assignment
property
- NP hard problem:没办法在多项式时间内求解
o ( d n ) o(d^n) o(dn)种可能赋值 - partial states: partial assignments有的变量没有被赋值
- complete state:完全赋值
- successor function: total states with a new variable assigned
- solution: assignments satisfies all the constraints
- goal test:完全赋值并满足约束
Constraint Graphs
- node: variables
edges: constraints between them - constraints
unary constraints: not graph, prune the domain
binary constraints:
higher-order constraints: 3 or more variables(也可以在约束图中被表示,但有一些不寻常)eg global constraints all dif - transform N-nary CSPS to binary CSPS
step:
将3元约束,转化为2元约束- z with domain 3 tuples ( A , B , C ) ∈ { ( a 1 , b 1 , c 1 ) , ⋯ , ( a n , b n , c n ) } (A,B,C)\in\{(a_1,b_1,c_1),\cdots,(a_n,b_n,c_n)\} (A,B,C)∈{(a1,b1,c1),⋯,(an,bn,cn)}
- (Z,A),(Z,B)
约束图:
binary constraint graph(最常见)
多元也可以写出来
solving CSP
csp问题有有限domain或无限domain,也有可能variable是连续variable(enumerate就不可以用了)
problem
initial state: empty assignments{}
successor function: assign a value to an anssigned value
goal test: an assignment satisfies all the constraints 并且complete
backtracking search
uninformed search
优化DFS用于CSP
2 principles
- fix an ordering for variables, and select values in this order(赋值顺序没有影响)
- 只赋不会冲突的值,当没有合适的值的时候,回溯,取改变前一个变量的值
improvement of backtracking search
filtering
(直接去掉会导致回溯的没有assign的variable的值域)
- forward checking: whenever a value is assigned to X i X_i Xi, cross off the value of unassigned variable X j X_j Xj which will vilotile the constraints
- arc consistency:
把约束图上的一条无方向的edge,变成两条有方向的arc
an arc x → y x\rightarrow y x→y is consistency, if for every x in the tail there is some y in the head could be assigned without violating some constraints,否则的话就移出x
forward checking: 所有的指向new assignment的arc consistent(只能保证局部arc consistent)
in our class, we did not mention there is no need to insert if it has already existed, it does not matter (AC-3)也是重复插入了
time complexity:
o
(
e
d
3
)
o(ed^3)
o(ed3)
查一条arc的时间
d
2
d^2
d2,一个变量对应d
一条arc被放入的次数
d
d
d,一个变量最多被放d次
4. 1-consistecy
2-consistency
k-consistency:任取k个node的组合,对k-1个node赋值,能够保证第k个node有至少一个可以赋值
strong k-consistency: 能够保证更低的个数的一致
forward checking 仅仅保证了指向新赋值的arc相容性,没有弧相容发现错误早
ordering
1.MRV: minimum remaining variable/most constrained variable,就是可以选择的值最少
2.LCV: least constraining value:may need arc consistency or forward checking,影响其他变量的值最少
structure
- independent sub-problems: extreme case
- connected-subgraph
- tree-structure CSPS(no loop in the constraint graph )
O ( d n ) → O ( n d 2 ) O(d^n)\rightarrow O(nd^2) O(dn)→O(nd2) - step
- prick an arbitrary node as the root
- let the undtrected edges point from parents to childs
- check arc consistency from children to parents
- forward assignment:对每一个选取和parents consisitent 的值
- instantiate a variable, and then the subgraph is a tree
- cycle cutest conditioning:
找到最小的一个set(cutset)移走他们,剩下的集合是一个树
o ( d c ) ( n − c ) d 2 o(d^c)(n-c)d^2 o(dc)(n−c)d2 - tree-decomposition: create a tree-structured graph of mega-variables,each mega-variable encodes part of the original CSP,sub-problems overlap to ensure consistent solutions
local search
- work with a complete states, then reassign variable values
- randomly select any conflicted variable,reassign
- choose a value that violates the fewest constraints
可以在常数时间内,解决问题,但是不能保证完备性,而且是次优的
R = c o n s t r a i n t s v a r i a b l e s R=\frac{constraints}{variables} R=variablesconstraints: 在某个值的时候,求解问题很困难
local search
local search v.s. systematic search
systematic search:
keep paths in memory. and remember alternatives so search can backtrack
search covered before
keep history of some visited nodes
always complete for finite search spaces, some complete for infinite search spaces
good for building up solutions incrementally : state _partitial solution,action_extend partial solution
local search:
path may be irrelevant, if only the final configuration is needed
garden descent, greedy local search ,simulated annealing(退火算法), genetic algorithm(遗传算法)
not keep the history of visited nodes
not complete
Good for fixing up candidate silutions: not satisfy all constraints ,action, make a small change in the candidate solution
hill-climbing search
题目问题
np难问题,我们无法最小化解决时间,通过范式解
如果我们保证arc consistency 那么当剩余部分是树形结构时,就不会导致backtracking search