-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_image.py
executable file
·65 lines (62 loc) · 2.68 KB
/
test_image.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
def test_image(instancefile,solutionfile,testpointfile):
with open(instancefile,'r') as instances:
with open(solutionfile,'r') as solutions:
inputline = instances.readline()
while inputline !="":
assert inputline[0]=='M'
inputline = instances.readline()
with open("tempmatrix.in",'w') as tempmatrix:
while inputline != "" and inputline != "A\n":
tempmatrix.write(inputline)
inputline = instances.readline()
with open("temppolyhedron.in",'w') as temppolyhedron:
while inputline != "" and inputline[0] != 'M':
temppolyhedron.write(inputline)
inputline = instances.readline()
run(["truncate", "-s", "-1", "tempmatrix.in"])
run(["truncate", "-s", "-1", "temppolyhedron.in"])
result = run(["./fourier-motzkin.sh", "image", "temppolyhedron.in", "tempmatrix.in", "outfile.ot"], stdout=PIPE, stderr=STDOUT)
print("output test image: "+result.stdout.decode('utf-8'))
solA = []
solutionline = solutions.readline()
assert solutionline=="A\n"
solutionline = solutions.readline()
while solutionline != "b\n":
solA.append(list(map(float,solutionline.split(" "))))
solutionline = solutions.readline()
solutionline = solutions.readline()
solb = list(map(float,solutionline.split(" ")))
with open("outfile.ot",'r') as outfile:
A = []
outline = nextline(outfile)
assert outline=="A"
outline = nextline(outfile)
while outline != "" and outline != "b":
A.append(list(map(float,outline.split(" "))))
outline = nextline(outfile)
if outline == "":
raise Exception("No correct output file")
outline = nextline(outfile)
if outline == "" or outline == "\n":
print("Empty b vector")
b = []
else:
b = list(map(float,outline.split(" ")))
n = len(solA[0])
with open(testpointfile,'r') as testpoints:
points = []
testline = testpoints.readline()
assert testline[0] == "n"
while testline != "n {}\n".format(n):
testline = testpoints.readline()
testline = testpoints.readline()
while testline != "" and testline != "\n" and testline[0] != 'n':
points.append(list(map(float,testline.split(" "))))
testline = testpoints.readline()
if not testequalpolyhedra((A,b),(solA,solb),points):
return False
return True
if __name__ == '__main__':
test_image("image_instances.dat",
"image_solutions.dat",
"testpoints.dat")