简体   繁体   中英

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 )

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. By "TDA ← TDA \\ {(X,c)} ;" in line 16, does the backslash mean that we remove that arc from 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. Is that basically correct?

Line 16 is mutable set difference: Remove (X,c) from the set TDA .

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 . In other words, this is a fancy filtered query on set c .

Line 17 is a bit ambiguous because k is never specified. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM