-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunWrappingSpeed.py
More file actions
93 lines (70 loc) · 2.62 KB
/
runWrappingSpeed.py
File metadata and controls
93 lines (70 loc) · 2.62 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
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
import sys
import time
import numpy as np
from matplotlib import pyplot as plt
from subprocess import Popen, PIPE
def parse_output(raw_output):
springLength = []
for word in raw_output.decode('utf-8').split('\n'):
try:
var = float(word.strip())
except:
for char in word.split('\t')[:-2]:
springLength.append(float(char.strip()))
# just assume that the last list of output is the spring length
return springLength
def general_loop(variable,loopRange,nTimes,isVec,showVisualizer=False,plotLength=False):
totalCases = len(loopRange)
totalRuns = totalCases*nTimes
runTimes = []
maxSpringLength = []
for i in range(len(loopRange)):
instance = loopRange[i]
if isVec==1:
args = "./build/wrappingSpeed --" + variable + "=[" + str(instance) + ",0,0]"
elif isVec==2:
args = "./build/wrappingSpeed --" + variable + "=[0," + str(instance) + ",0]"
elif isVec==3:
args = "./build/wrappingSpeed --" + variable + "=[0,0," + str(instance) + "]"
else:
args = "./build/wrappingSpeed --" + variable + "=" + str(instance)
if showVisualizer:
args += " --visualizer"
simTime = 5.0;
args += " --final_time="+str(simTime)
tDelta = 0
maxLength = 0
for ii in range(0,nTimes):
p = Popen(args,shell=True,stdout=PIPE)
t0 = time.time()
output = p.communicate()[0]
tDelta += time.time() - t0
percentage = round((i*nTimes+ii)/totalRuns*100)
print("[",percentage,"%] Runtime with",str(variable),"=", \
str(round(instance,5)),":",round(time.time()-t0,5))
maxLength += max(parse_output(output))
runTimes.append(tDelta/nTimes)
maxSpringLength.append(maxLength/nTimes)
fig,ax1 = plt.subplots()
color1 = 'tab:red'
color2 = 'tab:blue'
ax1.plot(loopRange,runTimes,color=color1)
ax1.set_xlabel(str(variable))
ax1.set_ylabel("runtime [s]",color=color1)
ax1.tick_params(axis='y',labelcolor=color1)
if plotLength:
ax2 = ax1.twinx()
ax2.plot(loopRange,maxSpringLength,color=color2)
ax2.set_ylabel("max spring length [m]",color=color2)
ax2.tick_params(axis='y',labelcolor=color2)
plt.show()
def main():
# rotationArray = np.linspace(1,1.2,10)
# variable = "body_mass_factor"
rotationArray = np.linspace(0,1,20)
variable = "cylinder_rotation"
nTimes = 20
isVec = 2
general_loop(variable,rotationArray,nTimes,isVec)
if __name__ == "__main__":
main()