forked from Slippery-Chickenz/LogicalBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResolutionNode.py
More file actions
56 lines (46 loc) · 1.74 KB
/
ResolutionNode.py
File metadata and controls
56 lines (46 loc) · 1.74 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
from Variable import Variable
class ResolutionNode():
'''
Class to hold node data for tree generation. Each node represents a Resolution clause
variables: a list of variables contained in the clause. Always members of the Variable class
parent: The ID of a node's parent node. (-1,-1) indicates a root node
child: The ID of a node's child node.
'''
def __init__(self, variables, parent, child):
self.variables = variables
self.parent = parent
self.child = child
def getParent(self):
return self.parent
def getVariables(self):
return self.variables
def numVariables(self):
return len(self.variables)
def changeParent(self, new_parents):
self.parent = new_parents
def printNode(self, par_child = True):
print("([", end = '')
for i in self.variables:
print("{},".format(i.stringVar()), end = '')
if not par_child:
print("])", end = '')
return
print("],{},{})".format(self.parent, self.child), end = '')
#Function to negate all variables in a clause
def invertVariables(self):
for var in self.variables:
var.negateVariable()
#Function to determine whether the clause is an atomic statement
def isAtom(self):
if len(self.variables) == 1:
return True
return False
def __eq__(self, other):
if self.parent == other.parent and self.child == other.child:
vars_s = self.variables
vars_o = other.getVariables()
if len(vars_s)==len(vars_o):
for i in range(len(vars_s)):
if vars_s[i] == vars_o[i]:
return True
return False