Skip to content

Commit 779c729

Browse files
stratcomp benchmark changes
1 parent 2af9884 commit 779c729

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

benchmarks/stratcomp-deppruning/generate_instances.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,44 @@
99

1010
num_inst = 10
1111

12-
min_comp = 1
12+
min_comp = 10
1313
max_comp = 100
14-
step_comp = 1
14+
step_comp = 10
1515

16-
products_factor = 5
16+
products_factor = 10
1717
owners_factor = 0.2
1818

1919

2020
for size in range(min_comp, max_comp + 1, step_comp):
2121
for num in range(0, num_inst):
2222
f = open('instances/inst_' + str(size).zfill(3) + '_' + str(num).zfill(3) + '.hex', 'w')
2323

24-
f.write('strat(X1) v strat(X2) :- prod(_,X1,X2).\n')
24+
f.write('strat(X1) v strat(X2) v strat(X3) v strat(X4) :- prod(_,X1,X2,X3,X4).\n')
2525
f.write('strat(X) :- &owns[\"instances/owners_' + str(size).zfill(3) + '_' + str(num).zfill(3) + '\",strat](X), comp(X).\n')
2626

2727
for comp in range(0,size):
2828
f.write('comp(c' + str(comp) + ').\n')
2929

3030
for prod in range(0,size * products_factor):
31-
f.write('prod(p' + str(prod) + ',c' + str(randint(0,size-1)) + ',c' + str(randint(0,size-1)) + ').\n')
31+
f.write('prod(p' + str(prod) + ',c' + str(randint(0,size-1)) + ',c' + str(randint(0,size-1)) + ',c' + str(randint(0,size-1)) + ',c' + str(randint(0,size-1)) + ').\n')
3232

3333
f.close()
3434

3535

36-
f = open('instances/owners_' + str(size).zfill(3) + '_' + str(num).zfill(3), 'w')
36+
if True:
3737

38-
for owner in range(0,int(size * owners_factor)):
39-
f.write('owns(c' + str(randint(0,size-1)) + ',c' + str(randint(0,size-1)) + ').\n')
38+
f = open('instances/owners_' + str(size).zfill(3) + '_' + str(num).zfill(3), 'w')
4039

41-
f.close()
40+
for owner in range(0,int(size * owners_factor)):
41+
first = randint(0,size-2)
42+
f.write('own(c' + str(first) + ',c' + str(randint(first+1,size-1)) + ',c' + str(randint(first+1,size-1)) + ',c' + str(randint(first+1,size-1)) + ').\n')
43+
44+
f.close()
45+
46+
else:
47+
f = open('instances/owners_' + str(size).zfill(3) + '_' + str(num).zfill(3), 'w')
48+
49+
for owner in range(0,int(size * owners_factor)):
50+
f.write('own(c' + str(randint(0,size-1)) + ',c' + str(randint(0,size-1)) + ',c' + str(randint(0,size-1)) + ',c' + str(randint(0,size-1)) + ').\n')
4251

52+
f.close()

testsuite/plugin.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,21 +1001,27 @@ def owns(path,strat):
10011001
ownsrel = dict()
10021002

10031003
for line in f:
1004-
m = re.search('owns\((.+),(.+)\)', line)
1004+
m = re.search('own\((.+),(.+),(.+),(.+)\)', line)
10051005
if m.group(1) in ownsrel:
1006-
ownsrel[m.group(1)].append(m.group(2))
1006+
ownsrel[m.group(1)].append((m.group(2),m.group(3),m.group(4)))
10071007
else:
1008-
ownsrel[m.group(1)] = [m.group(2)]
1008+
ownsrel[m.group(1)] = [(m.group(2),m.group(3),m.group(4))]
1009+
1010+
true_strat = []
1011+
false_strat = []
10091012

10101013
for x in dlvhex.getInputAtoms():
10111014
if x.tuple()[0] == strat and x.isTrue():
1012-
if x.tuple()[1].value() in ownsrel:
1013-
for el in ownsrel[x.tuple()[1].value()]:
1014-
dlvhex.output((el,))
1015-
elif x.tuple()[0] == strat and not x.isFalse():
1016-
if x.tuple()[1].value() in ownsrel:
1017-
for el in ownsrel[x.tuple()[1].value()]:
1018-
dlvhex.outputUnknown((el,))
1015+
true_strat.append(x.tuple()[1].value())
1016+
if x.tuple()[0] == strat and x.isFalse():
1017+
false_strat.append(x.tuple()[1].value())
1018+
1019+
for key in ownsrel:
1020+
for el in ownsrel[key]:
1021+
if el[0] in true_strat and el[1] in true_strat and el[2] in true_strat:
1022+
dlvhex.output((key,))
1023+
if el[0] not in false_strat and el[1] not in false_strat and el[2] not in false_strat:
1024+
dlvhex.outputUnknown((key,))
10191025

10201026

10211027
def complianceCheck4(path,i,j,k,inp,outp):
@@ -1025,13 +1031,13 @@ def complianceCheck4(path,i,j,k,inp,outp):
10251031
ownsrel = dict()
10261032

10271033
for line in f:
1028-
m = re.search('owns\((.+),(.+)\)', line)
1034+
m = re.search('own\((.+),(.+),(.+),(.+)\)', line)
10291035
if m.group(1) in ownsrel:
1030-
ownsrel[m.group(1)].append(m.group(2))
1036+
ownsrel[m.group(1)] += [m.group(2),m.group(3),m.group(4)]
10311037
else:
1032-
ownsrel[m.group(1)] = [m.group(2)]
1038+
ownsrel[m.group(1)] = [m.group(2),m.group(3),m.group(4)]
10331039

1034-
if inp in ownsrel and outp in ownsrel[inp]:
1040+
if outp in ownsrel and inp in ownsrel[outp]:
10351041
return "0"
10361042
else:
10371043
return "1"

0 commit comments

Comments
 (0)