-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpropositionLayer.py
64 lines (50 loc) · 1.92 KB
/
propositionLayer.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
from util import Pair
class PropositionLayer(object):
"""
A class for an PropositionLayer in a level of the graph.
The layer contains a list of propositions (Proposition objects) and a list of mutex propositions (Pair objects)
"""
def __init__(self):
"""
Constructor
"""
self.propositions = [] # list of all the propositions in the layer
self.mutexPropositions = [] # list of pairs of propositions that are mutex in the layer
def addProposition(self, proposition):
# adds proposition to the propositions list
self.propositions.append(proposition)
def removePropositions(self, proposition):
# remove proposition from the propositions list
self.propositions.remove(proposition)
def getPropositions(self):
# retunrs the propositions list
return self.propositions
def addMutexProp(self, p1, p2):
# adds the pair(p1,p2) to the mutex propositions list
self.mutexPropositions.append(Pair(p1,p2))
"""
returns true if proposition p1 and proposition p2 are mutex at this layer
"""
def isMutex(self, p1, p2):
return Pair(p1,p2) in self.mutexPropositions
def getMutexProps(self):
# returns the mutex propositions list
return self.mutexPropositions
def allPrecondsInLayer(self, action):
"""
returns true if all propositions that are preconditions of the
action exist in this layer (i.e. the action can be applied)
"""
for pre in action.getPre():
if not(pre in self.propositions):
return False
for pre1 in action.getPre():
for pre2 in action.getPre():
if Pair(pre1,pre2) in self.mutexPropositions:
return False
return True
def __eq__(self, other):
return (isinstance(other, self.__class__)
and self.__dict__ == other.__dict__)
def __ne__(self, other):
return not self.__eq__(other)