这是我尝试在Java中实现的算法... (没有完全正确格式化,所以在这个链接上查看它可能更容易,只需从它带给你的地方向上滚动半页http://artint.info/html/ArtInt_79.html#AC-3-fig)
1: procedure GAC(V,dom,C)
2: Inputs
3: V: a set of variables
4: dom: a function such that dom ( X ) is the domain of variable X
5: C: set of constraints to be satisfied
6: Output
7: arc-consistent domains for each variable
8: Local
9: D X is a set of values for each variable X
10: TDA is a set of arcs
11: for each variable X do
12: D X ← dom ( X )
13: TDA ← {? X,c ?| c ∈ C and X ∈ scope ( c )}
14: while TDA ?= {} do
15: select ? X,c ? ∈ TDA;
16: TDA ← TDA \ {(X,c)} ;
17: ND X ← { x | x ∈ D X and some { X = x,Y 1 = y 1 ,...,Y k = y k } ∈ c where y i ∈ D Y i for all i }
18: if ND X ?= D X then
19: TDA ← TDA ∪ {? Z,c ? ?| X ∈ scope ( c ? ) , c ? is not c, Z ∈ scope ( c ? ) \ { X }}
20: D X ← ND X
21: return { D X | X is a variable }
我不明白第16行和第16行17正在做的确切。由“TDA←TDA \ {(X,c)};”在第16行,反斜杠是否意味着我们从TDA中移除了这个弧?
然后,在第17行中,我们似乎正在说X的新域是旧域中的任何内容,并且与执行/不满足约束的所有内容进行对比。这基本上是正确的吗?