-
Notifications
You must be signed in to change notification settings - Fork 1
/
ac_2.py
28 lines (24 loc) · 958 Bytes
/
ac_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from collections import deque
import copy
from revise import revise_v2, all_arcs
def arc_consistency_2(domains, constraints, number_of_nodes):
val_queue1 = deque()
val_queue2 = deque()
for i in range(0, number_of_nodes):
arcs = all_arcs(constraints)
for j in range(0, i):
if (i, j) in arcs:
val_queue1.append((i, j))
val_queue2.append((j, i))
while not val_queue1.__len__() == 0:
while not val_queue1.__len__() == 0:
k, m = val_queue1.popleft()
if revise_v2(domains, (k, m), constraints):
if len(domains[str(k)]) == 0:
return False
for p in range(0, i + 1):
if ((p, k) in arcs) and m != p:
val_queue2.append((p, k))
val_queue1 = copy.deepcopy(val_queue2)
val_queue2.clear()
return True