-
Notifications
You must be signed in to change notification settings - Fork 0
/
pddl_test.py
88 lines (72 loc) · 2.49 KB
/
pddl_test.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import requests
from pprint import pprint
from re import match
import argparse
from glob import glob
import csv
def plan(domain_file, problem_file):
url_prefix = "http://lcas.lincoln.ac.uk/fast-downward/"
#headers = {'content-type': 'application/x-www-form-urlencoded'}
with open(domain_file, 'r') as domain,\
open(problem_file, 'r') as problem:
d = domain.read()
d = d.decode('ascii', 'ignore').encode('ascii')
p = problem.read()
# payload = 'domain=' + d + '&problem=' + p
payload = {'domain': d, 'problem': p}
r = requests.post(url_prefix,
data=payload)
json = r.json()
plan = json['plan'].splitlines()
sout = json['sout'].splitlines()
actions = []
if len(plan) > 1:
for action in plan:
m = match('[(]([a-z,_,-]*) .*[)]', action)
if m:
actions.append(m.group(1))
result = {
'plan': plan,
'sout': sout,
'solution_found': 'Solution found.' in sout,
'length': len(plan) - 1,
'actions': actions
}
return result
parser = argparse.ArgumentParser(description='compute similarity')
parser.add_argument('glob',
help='path glob pattern')
parser.add_argument('--problem',
help='list of problem files',
action='append')
parser.add_argument('--csv_file',
help='result csv file', default='pddl-results.csv')
args = parser.parse_args()
files = glob(args.glob)
with open(args.csv_file, "w") as csv_file:
csv_writer = csv.writer(csv_file, dialect='excel')
csv_row = ['domain_file']
for p in args.problem:
csv_row.append(p + ' plan')
csv_row.append(p + ' sout')
csv_row.append(p + ' plan length')
csv_writer.writerow(csv_row)
for domain_file in files:
print domain_file
csv_row = [domain_file]
for problem_file in args.problem:
try:
p = plan(domain_file, problem_file)
#pprint(p)
csv_row.append(' '.join(p['actions']))
if p['solution_found']:
csv_row.append('TRUE')
else:
csv_row.append(p['sout'])
csv_row.append(p['length'])
except Exception as e:
print " ", e
csv_row.append(str(e))
csv_row.append('')
csv_row.append('')
csv_writer.writerow(csv_row)