-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nodes.py
47 lines (35 loc) · 1.12 KB
/
Nodes.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
class Node():
pass
class ExprNode(Node):
def evaluate(self,var , adjs):
pass
class BinaryNode(ExprNode):
def __init__(self , left, right):
self.left = left
self.right = right
class AndNode(BinaryNode):
def evaluate(self, var, adjs):
eva = min(self.right.evaluate( var , adjs), self.left.evaluate(var, adjs))
return eva
class ORNode(BinaryNode):
def evaluate(self, var, adjs):
eva= max(self.right.evaluate(var, adjs), self.left.evaluate(var, adjs))
return eva
class UnaryNode(ExprNode):
def __init__(self,expr):
self.expr = expr
class NotNode(UnaryNode):
def evaluate(self, var , adjs):
eva = 1 - self.expr.evaluate(var,adjs)
return eva
class Statement(ExprNode):
def __init__(self,var, adj):
self.var = var
self.adj = adj
def evaluate(self , vars , values):
eva = vars[self.var][self.adj](values[self.var])
return eva
class RuleNode(Node):
def __init__(self,antecedent,consequent):
self.antecedent = antecedent
self.consequent = consequent