3.Solving Constraint Satisfaction Problems(1)

Problem

Given an undirected graph with n nodes, given 3 colors, assign a color to each node so that no two adjacent nodes (with an edge between them) are the same color


Problem

Solution 1——Backtracking(more in charpter 2)

function Backtrack(γ,a) returns solution, or “inconsistent”
     if a is inconsistent with γ then return “inconsistent” 
     if a is total then return a
     select some variable v for which a is not defined
     for each d in Dv in some order do
           a′←a ∪ {(v,d)}
           a′′ ← Backtrack(γ, a′)
           if a′′ ̸= “inconsistent” then return a′
     end
return “inconsistent”

Comments: The size of the search space depends on the order in which we choose variables and values.

Improvement

1.Variable ordering
· Common strategy: Choose most constrained variable (aka “first-fail”) ——Choose a variable with the smallest (consistent) domain.
· Most constraining variable——Involved in as many constraints as possible
· Seek biggest effect on domains of unassigned variables——Detect inconsistencies earlier, shortening search tree branches
· Random selection can also help, especially for tie-breaking

2.Value ordering
· Common strategy: least constraining value——Choose a value that won’t conflict much with others
·Minimise useless backtracking below current node

3.Inference
Inference in CSP solving: deducing additional constraints that follow from the already known constraints.
· Just once before search starts
· At every recursive call of backtracking

Solution2——Forward Checking

Definition: remove from domains any value not consistent with those that have been assigned.

Obviously sound: it does not rule out any solutions.

Can be implemented incrementally for efficiency: only necessary to consider v to be the variable which has just been assigned.

Forward checking is rather weak on its own, but it combines well with the first-fail heuristic( Choose most constrained variable) for variable ordering, to make a powerful technique.

n= number of variables
d = size of initial domains
s = maximum number of constraints involving a given variable (s ≤ n-1)
Forward checking takes O(nsd) time

Solution 3——Arc Consistency(AC-3)

A stronger inference rule: make all variables arc consistent.

Variable v is arc consistent with respect to another variable u iff for every d∈Dv there is at least one d′ ∈Du such that (d,d′)∈Cv.

Unlike forward checking, makes inferences from unassigned variables

In sum, arc consistency extends this to all variables, whether assigned or not. It is stronger than forward checking and unit propagation, but costs more to compute.

The difference between forward checking and arc consistency is that the former only checks a single unassigned variable at time for consistency, while the second also checks pairs of unassigned variables for mutual consistency.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 今天是黄山之旅的第二天,晚上看完星星之后,我美美的睡了一觉,夜里我梦见我会飞啦!我飞呀飞,飞到太空,我在星...
    蕉蕉_5196阅读 1,228评论 0 0
  • 家门口的美丽的花朵,不走出来怎么会发现? 从家里走出来大概十分钟,就会走到芙蓉南路省政府对面。我们一边拍照臭美,一...
    苛娃阅读 1,703评论 0 1
  • setTranslucent ios 7 之后,setTranslucent=yes 默认的 则状态栏及导航栏底...
    小小白衣阅读 5,337评论 0 0