forked from puemos/graphplan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactionLayer.py
59 lines (45 loc) · 1.57 KB
/
actionLayer.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
from util import Pair
class ActionLayer(object):
"""
A class for an ActionLayer in a level of the graph.
The layer contains a list of actions (action objects) and a list of mutex actions (Pair objects)
"""
def __init__(self):
"""
Constructor
"""
self.actions = [] # list of all the actions in the layer
self.mutexActions = [] # list of pairs of action that are mutex in the layer
def addAction(self, act):
# adds the action act to the actions list
self.actions.append(act)
def removeActions(self, act):
# removes the action act to the actions list
self.actions.remove(act)
def getActions(self):
# returns the actions list
return self.actions
def getMutexActions(self):
# returns the mutex actions list
return self.mutexActions
def addMutexActions(self, a1, a2):
# add the pair (a1,a2) to the mutex actions list
self.mutexActions.append(Pair(a1,a2))
def isMutex(self, Pair):
"""
Returns true if the pair of actions are mutex in this action layer
"""
return Pair in self.mutexActions
def effectExists(self, prop):
"""
Returns true if at least one of the actions in this layer has the proposition prop in its add list
"""
for act in self.actions:
if prop in act.getAdd():
return True
return False
def __eq__(self, other):
return (isinstance(other, self.__class__)
and self.__dict__ == other.__dict__)
def __ne__(self, other):
return not self.__eq__(other)