-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsac_compiler.py
More file actions
133 lines (95 loc) · 3.51 KB
/
Copy pathsac_compiler.py
File metadata and controls
133 lines (95 loc) · 3.51 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 9 16:12:01 2013
@author: quare
"""
import pddl_parser.PDDL3_File as m
import time
import os
import sys, getopt
def main(argv):
'''
main function
'''
directory = ''
domain_filename=''
problem_filename=''
output_filename=''
try:
opts, args = getopt.getopt(argv,"d:o:f:r:")
except getopt.GetoptError:
print 'sac_compiler.py -d <directory> -o <domainfile> -f <problemfile> -r <resultfile>'
sys.exit(2)
if len(opts)!=4:
print 'sac_compiler.py -d <directory> -o <domainfile> -f <problemfile> -r <resultfile>'
sys.exit()
for opt, arg in opts:
if opt == "-d":
directory = arg
elif opt == "-o":
domain_filename = arg
elif opt == "-f":
problem_filename = arg
elif opt == "-r":
output_filename = arg
#directory="PDDL3_ex/"
#domain_filename="domain.pddl"
#problem_filename="p04.pddl"
#output_filename="comp"
mod_pddl=m.Model() #instantiate a model
time_start = time.clock()
tot_time_start=time_start
mod_pddl.save_in_memory(directory+"/",domain_filename,problem_filename) #save the structure of a pddl3 model in memory
time_elapsed = (time.clock() - time_start)
print("Save in memory: " + str(time_elapsed)+"s")
mod_strips = mod_pddl.adl2strips() #new model in strips (without constraints, functions and preferences)
#joining pddl and strips
new_dom=mod_strips.new_dom
print('New Domain created')
mod_strips.new_prob.join_pddl(mod_pddl,new_dom)
print('New Problem created')
time_start = time.clock()
mod_strips.separation_in_operator_classes()
time_elapsed = (time.clock() - time_start)
print("Separation in class: " + str(time_elapsed)+"s")
print("Classification of operators done")
#compiling
time_start = time.clock()
comp_mod=mod_strips.compile_model()
time_elapsed = (time.clock() - time_start)
print("Compiling time: " + str(time_elapsed)+"s")
print("Compiled")
string_dom=str(comp_mod.new_dom)
string_prob=str(comp_mod.new_prob)
if not os.path.exists(directory+"/output"):
os.mkdir(directory+"/output")
temp_dom_f=open(directory+"/output/"+output_filename+"_dom.pddl","w")
temp_dom_f.write(string_dom)
temp_dom_f.close()
temp_prob_f=open(directory+"/output/"+output_filename+"_prob.pddl","w")
temp_prob_f.write(string_prob)
temp_prob_f.close()
tot_time_elapsed = (time.clock() - tot_time_start)
print("Total: " + str(tot_time_elapsed)+"s")
#os.system('./adl2strips-linux -p output/ -o comp_dom.pddl -f comp_prob.pddl')
return
if __name__ == "__main__":
main(sys.argv[1:])
#dom_strips,prob_strips=p.transform(dom_pddl,prob_pddl) #strips file is created
#try:
#f_str=open(directory+domain_filename+".strips","w")
#f_str.write(dom_strips) #writing output file
#f_str.close()
#except IOError:
#print("Problems writing domain output")
#return -1
#try:
#f_str=open(directory+problem_filename+".strips","w")
#f_str.write(prob_strips) #writing output file
#f_str.close()
#except IOError:
#print("Problems writing problem output")
#return -1
#print("output files produced") #everything was correct
#return 0