-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify.py
executable file
·180 lines (165 loc) · 8.17 KB
/
verify.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import os
from book_keeping import *
#get the values in a line
def getValue(line):
values = []
for words in (line.strip().split()):
values +=[words]
return values[1:]
def getSparse(sparseRepFileName):
sparseMatrixRow = []
sparseMatrixResult = []
lineNum = 0;
#get the sparse matrix
with open(sparseRepFileName) as f:
for line in f:
if (not(lineNum == 0)): #skip the first line
sparseMatrixRow = []
for words in (line.strip().split()):
sparseMatrixRow += [int(words)]
sparseMatrixResult.append(sparseMatrixRow)
lineNum +=1
return sparseMatrixResult
#-----------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------
#---------module_name:::getSparseMessy
#---------functionlity::: this function looks at the log file and extracts the sparstMatrix
#-----------------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------------------------------------
def getSparseMessy(sparseRepFileName):
sparseMatrixRow = []
sparseMatrixResult = []
lineNum = 0;
start = end = firstRow = 0
#get the sparse matrix
with open(sparseRepFileName) as f:
for line in f:
if len(line.strip().split()) > 0:
if (line.strip().split()[0]) == "sparseMatrixStart":
end = 0
firstRow = 0
start = 1
if (line.strip().split()[0]) == "sparseMatrixEnd":
end = 1
start = 0
if (start == 1 and end != 1 and firstRow >= 2) :
sparseMatrixRow = []
for words in (line.strip().split()):
sparseMatrixRow += [int(words)]
#print "hlo"
sparseMatrixResult.append(sparseMatrixRow)
if (start == 1):
firstRow +=1
if(end == 1):
return sparseMatrixResult
#verifies that the set of nodes provided are actually independant by looking at the sparese representation
def verifyNodesIndependant(possibleIndepNodeList, sparseRepFileName, printBool, logFileName):
logFilePtr = open(logFileName, "a")
allLines = []
sparseMatrixResult = []
lineNum = 0;
#get the sparse matrix
# with open(sparseRepFileName) as f:
# for line in f:
# if (not(lineNum == 0)): #skip the first line
# sparseMatrixRow = []
# for words in (line.strip().split()):
# sparseMatrixRow += [int(words)]
# sparseMatrixResult.append(sparseMatrixRow)
# lineNum +=1
#
sparseMatrixResult = getSparse(sparseRepFileName)
# print possibleIndepNodeList
# print sparseMatrixResult
for i in range(0, len(possibleIndepNodeList)):
for j in range (0, len(possibleIndepNodeList)):
if (not(i == j)):
if (possibleIndepNodeList[i]) in sparseMatrixResult[possibleIndepNodeList[j] - 1]:
if (printBool):
logFilePtr.write(str(possibleIndepNodeList[i]) + " is connected to " + str(possibleIndepNodeList[j]) + "\n")
logFilePtr.close();
logFilePtr = open(logFileName, "r")
print str(possibleIndepNodeList[i]) + " is connected to " + str(possibleIndepNodeList[j])
return 0
logFilePtr.close();
return 1;
#def verifyMaximumSetSerials(sparseRepFileName, adjacentRepFilName, MISResultRefFileName, MISResultToVerifyFileName):
##
# generateAdjacentFromSparce(sparseRepFileName, adjacentRepFilName)
#
## #finding the MIS using the MIS.cpp file
## #generate the result using the internet found code(this is the refrence code
## os.system("g++ MIS.cpp")
## os.system("./a.out " + adjacentRepFilName + " " + MISResultRefFileName)
##
## #genearte the result using out written serial code
## os.system("g++ serial.cpp")
## os.system("./a.out" + " " + sparseRepFileName + " " + MISResultToVerifyFileName);
##
# #checking whether the max number of indep node equal
# if (numOfIndepNodeEqual(MISResultRefFileName, MISResultToVerifyFileName)):
# logFilePtr.write("--------number of max independant node test:---->passed")
# print "--------number of max independant node test:---->passed"
# else:
# logFilePtr.write("--------number of max independant node test:---->passed")
# print "--------number of max independant node test:---->failed"
# #checking wheter the nodes found are actually independant
# possibleIndepNodeList = parseResultAndExtractIndepNodes(MISResultRefFileName)
# if (verifyNodesIndependant(possibleIndepNodeList, sparseRepFileName, 1)):
# print "--------all nodes independeent test:---->passed"
# else:
# print "--------all nodes independeent test:---->failed"
#
#
#generateAdjacentFromSparce(sparseRepFileName, adjacentRepFilName)
#finding the MIS using the MIS.cpp file
#generate the result using the internet found code(this is the refrence code
# os.system("g++ MIS.cpp")
# os.system("./a.out " + adjacentRepFilName + " " + MISResultRefFileName)
#genearte the result using out written serial code
# os.system("g++ serial.cpp")
# os.system("./a.out" + " " + sparseRepFileName + " " + MISResultToVerifyFileName);
#
def verifyMaximalSet(sparseRepFileName, MISResultToVerifyFileName, logFileName):
#checking wheter the nodes found are actually independant
possibleIndepNodeList = parseResultAndExtractIndepNodes(MISResultToVerifyFileName)
failed = 0 #a flag indidcating whether some test was failed
if (verifyNodesIndependant(possibleIndepNodeList, sparseRepFileName, 1, logFileName)):
logFilePtr = open(logFileName, "a")
logFilePtr.write("--------number of max independant node test:---->passed\n")
logFilePtr.close()
print "--------all nodes independeent test:---->passed"
else:
logFilePtr = open(logFileName, "a")
logFilePtr.write("--------number of max independant node test:---->failed \n")
logFilePtr.close();
#collecting all the failed files in a folder
logFilePtr = open(logFileName, "r")
logFilePtr.close();
print "--------all nodes independeent test:---->failed"
failed = 1
#check whether the set is indeed maximal by adding other nodes and making sure that the set does not stay independant
numOfGraphNode= findNumOfLinesInAFile(sparseRepFileName) - 1
for i in range(0, numOfGraphNode):
if not((i+1) in possibleIndepNodeList):
possibleIndepNodeListAddedOneElement = []
#add an element and see if still independent
possibleIndepNodeListAddedOneElement = [i + 1] + possibleIndepNodeList;
if (verifyNodesIndependant(possibleIndepNodeListAddedOneElement, sparseRepFileName, 0, logFileName)):
#writing into the log folder
logFilePtr = open(logFileName, "a")
logFilePtr.write("--------maximal test:---->failed\n")
logFilePtr.write("we can add other nodes and still be independent\n")
logFilePtr.write("for example " + str(possibleIndepNodeListAddedOneElement) + "\n")
logFilePtr.close();
#printing to the screen
print "--------maximal test:---->failed"
print "we can add other nodes and still be independent"
print "for example " + str(possibleIndepNodeListAddedOneElement);
failed = 1
return failed
logFilePtr = open(logFileName, "a")
logFilePtr.write("--------maximal test:---->passed\n")
print "--------maximal test:---->passed"
logFilePtr.close();
return failed