-
Notifications
You must be signed in to change notification settings - Fork 3
/
problemFileMaker.py
86 lines (71 loc) · 2.92 KB
/
problemFileMaker.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
from dbHandler import dbHandler
class problemFileMaker:
def __init__(self):
self.dbCaller = dbHandler()
def addObjects(self):
'''
Function returns objects that need to be added to the problem file
@Returns - pddl format strings of objects
'''
s = ""
object_type = self.dbCaller.getObjects()
for i in object_type:
objects = self.dbCaller.getCustomCursor('object_name', 'objects', 'type ='+ str(i[0]))
for o in objects:
s += ' ' + o[0]
s += ' - ' + i[1] + '\n'
return s
def addNotNeeded(self):
pois = self.dbCaller.getCustomCursor('object_name', 'objects', 'type = 8')
actors = self.dbCaller.getCustomCursor('object_name', 'objects', 'type in (1,2,3,4)')
s = ""
for i in pois:
s += '(not_needed_search_casualties ' + i[0] + ' )\n'
s += '(not_needed_attend_casualties ' + i[0] + ' )\n'
for j in pois:
s += '(not_needed_diverted_traffic ' + i[0] + ' '+ j[0] +')\n'
for i in actors:
s += '(not_needed_active_local_alert ' + i[0] + ' )\n'
s += '(not_needed_address_media )\n'
return s
def addInitialState(self, gs):
s = ""
initStateList = self.dbCaller.getTasks()
self.notSmallFire = True
for predicate in initStateList:
if (predicate[0] == "small_fire_at byeng"):
if 'Small' in gs:
s += '(' + predicate[0] + ')\n'
self.notSmallFire = False
else:
s += '(' + predicate[0] + ')\n'
s += '\n(=(total-cost) 0.0)\n\n'
s += self.addNotNeeded()
return s
def addResourcesIfAvailable(self, data, pred):
s = ""
for i in data:
length = len(i)
for j in range(1, length):
pre = [p[1] for p in pred if p[0] == j]
if(i[j] > 0):
s += '('+ pre[0] +' '+ i[0] +')\n'
return s
def addFireStationResources(self):
return self.addResourcesIfAvailable(self.dbCaller.getFireStationsData(), self.dbCaller.getFireStationPredicates())
def addHospitalResources(self):
return self.addResourcesIfAvailable(self.dbCaller.getHospitalData(), self.dbCaller.getHospitalPredicates())
def addPoliceStationResources(self):
return self.addResourcesIfAvailable(self.dbCaller.getPoliceStationData(), self.dbCaller.getPoliceStationPredicates())
def addDurationsOfActions(self):
durationList = self.dbCaller.getActionDurations()
s = ""
for duration in durationList:
s += '(=(' + duration[0] + ') ' + str(duration[1]) + ')\n'
return s
def addGoal(self):
goalList = self.dbCaller.getSubGoalPredicates()
s = ""
for goal in goalList:
s += '(' + goal[0] + ')\n'
return s