[英]Having some difficulty implementing a 'generalized arc consistency' algorithm in Java
Here is the algorithm I am trying to implement in Java... (Didn't fully format correctly, so it may be easier to view it at this link, just scroll up half a page from where it brings you http://artint.info/html/ArtInt_79.html#AC-3-fig ) 这是我正在尝试用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 }
I'm not understanding what line 16 & 17 are doing exactly. 我不明白第16和17行到底在做什么。 By "TDA ← TDA \\ {(X,c)} ;"
通过“ TDA←TDA \\ {(X,c)};” in line 16, does the backslash mean that we remove that arc from TDA?
在第16行中,反斜杠是否表示我们从TDA中删除了该弧?
Then, in line 17, it seems we are saying that the new domain of X is whatever was already in the old domain, ANDed with everything that does/doesn't fulfill the constraint. 然后,在第17行中,似乎我们要说的是X的新域是旧域中已经存在的任何域,并与所有满足/不满足约束的事物进行“与”运算。 Is that basically correct?
这基本上是正确的吗?
Line 16 is mutable set difference: Remove (X,c)
from the set TDA
. 第16行是可变的集合差异:从集合
TDA
删除(X,c)
。
Line 17 is set builder notation: Set ND X
(which I believe means something like "New domain of X
") to the set of all elements x
where x
is in the domain of X
and there also exists a set of equal pairs that's an element of set c
and that includes X=x
, Y1=y1
up through Y_k=y_k
where these pairs satisfy y_i\\in domain(Y_i)
for all i=1,2,...k
. 第17行是设置生成器的符号:将
ND X
(我认为这意味着类似“ X
新域”)设置为所有元素x
的集合,其中x
在X
的域中,并且还存在一组相等的对集c
元素,其中包括X=x
, Y1=y1
直到Y_k=y_k
,其中这些对满足所有i=1,2,...k
y_i\\in domain(Y_i)
。 In other words, this is a fancy filtered query on set c
. 换句话说,这是对
c
集的过滤式查询。
Line 17 is a bit ambiguous because k
is never specified. 第17行有点模棱两可,因为从未指定
k
。 In this case, one is usually free to infer that it can take any value. 在这种情况下,通常可以随意推断它可以取任何值。 So the inner set could be
{X=x}
or {X=x,Y1=y1}
or etc. with any number of the Y_=y_
pairs. 因此,内部集合可以是
{X=x}
或{X=x,Y1=y1}
等等,具有任意数量的Y_=y_
对。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.