Skip to content

Commit 3108f75

Browse files
committed
Simply function updatewp_density(), reduced to O(N) time complexity
1 parent ca8fa62 commit 3108f75

File tree

2 files changed

+54
-66
lines changed

2 files changed

+54
-66
lines changed

test_wp_post.csv

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
215.33378922713493,201.81188825091405,10.60898494720459,-3.1388674628234354
2-
207.41565325823706,201.7903097664661,10.619364808783029,-3.1408510799080163
3-
191.4214210078194,201.77844886259473,10.605507721489147,-3.1415164639101048
4-
175.4266373709534,201.7772302251504,10.611396949219438,-3.140580743635333
5-
159.4319026861715,201.76104498837955,10.613230713506017,3.141196304457918
6-
143.43676275858144,201.76738464853605,10.613291479935194,-3.137302315917327
7-
135.43964216735327,201.73307409027387,10.604526101807872,-3.1372291493871987
8-
133.4396594802003,201.72434710202552,10.609897548129618,3.1356802584669548
9-
131.43817566422254,201.7361808030658,10.60818733376841,3.102272447519027
10-
130.4365059989096,201.77558697115873,10.6096427346935,3.053164876672713
11-
129.43716305555228,201.8641877034682,10.623217663352115,2.9817592584352175
12-
128.45475765877168,202.02255982503527,10.606557686226711,2.888153280291491
13-
127.50008717750973,202.26982785660655,10.611634930667403,2.783093122586031
14-
126.57554687673233,202.6162445675219,10.61474755621642,2.6815322679243874
15-
125.68418110839512,203.05793768057114,10.631189557302914,2.5863100498659444
16-
124.83994420999264,203.5816999073285,10.633261431131434,2.5042530358408204
17-
123.232211364341,204.7720923706875,10.627961250844871,2.4606781954921946
18-
110.80154596882166,214.8431060543582,10.6269350207704,2.4790894163582062
19-
103.97751274215905,220.16669653527612,10.646126730230025,2.4790894163582062
1+
215.33378942682145,201.81189013707106,10.60898494720459,-3.1388698357672853
2+
207.407571243807,201.79030843560355,10.619364808783029,-3.140852973086565
3+
191.41333977648827,201.77847781226544,10.605507721489147,-3.1415227379885993
4+
175.41855515356585,201.77735952728074,10.611396949219438,-3.1405684653829766
5+
159.42382039004926,201.76097790283688,10.613230713506017,-3.1415570276597546
6+
143.42871972390898,201.76040806249935,10.613291479935194,-3.136511891867225
7+
133.5486034312751,201.7102091138769,10.604526101807872,3.1323144477993283
8+
131.5988311930191,201.72830002107017,10.609897548129618,3.095923759610543
9+
130.20032565289256,201.79221266157862,10.60818733376841,3.036305703369278
10+
129.12984266800655,201.9053388738151,10.6096427346935,2.952479747452028
11+
128.15521971272076,202.09188179468225,10.623217663352115,2.847905147141233
12+
127.2138315624822,202.3765887391256,10.606557686226711,2.733024733632629
13+
126.23927845089067,202.79850168289744,10.611634930667403,2.618942838115936
14+
125.0283611179826,203.49609381985314,10.61474755621642,2.515986575255768
15+
123.12379047588523,204.87196786092954,10.631189557302914,2.4587765905022847
16+
113.58786068698177,212.6278218069211,10.633261431131434,2.4766743948736263
17+
103.97548917105081,220.16407382029885,10.627961250844871,2.4766743948736263

wpProcess.py

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -137,53 +137,43 @@ def updatewp_density(self):
137137
idx_org = 0
138138
station_.append(self.station[0])
139139
curvature_.append(self.curvature[0])
140-
while station_[-1] < self.station[-1]:
141-
# obtain s, s.t. curvature vlaue is within limits
142-
ds = min( 16.0, self.station[-1]-station_[-1] )
143-
flg_runonce = False
144-
while not flg_runonce or ds>=1.0:
145-
flg_runonce = True
146-
s = station_[-1]+ds
147-
flg_excd = False # flag indicator whether it exceeds curvature limit
148-
coef = 0.1
149-
150-
# check the curvature in the range [station_[-1], station_[-1]+ds] exceeding limit
151-
i = idx_org
152-
while i<len(self.station) and self.station[i]<=s:
153-
if ds > 1.0 and abs(self.curvature[i]) > max(0.01, coef/ds):
154-
flg_excd = True
155-
break
156-
i += 1
157-
158-
if flg_excd:
159-
ds /= 2
160-
else:
161-
break
162-
print ds
163-
idx_org = i
164-
# interp for new x, y, curvature at s
165-
fx = interp1d(self.station, self.x)
166-
fy = interp1d(self.station, self.y)
167-
fcurv = interp1d(self.station, self.curvature)
168-
x_.append( float( fx(s) ) )
169-
y_.append( float(fy(s)) )
170-
station_.append(s)
171-
curvature_.append( float(fcurv(s)) )
172-
173-
# update the class members x, y, th, station, curvature
174-
# plt.plot(self.x, self.y, 'b.')
175-
# plt.plot(x_, y_, 'r.')
176-
# plt.xlabel('x [m]')
177-
# plt.ylabel('y [m]')
178-
# plt.legend(['original','adjusted'], loc='best')
179-
# plt.show()
180-
181-
# plt.plot(self.station, self.curvature, 'b.')
182-
# plt.plot(station_, curvature_, 'r.')
183-
# plt.xlabel('station [m]')
184-
# plt.ylabel('curvature [m]')
185-
# plt.legend(['original','adjusted'], loc='best')
186-
# plt.show()
140+
fx = interp1d(self.station, self.x)
141+
fy = interp1d(self.station, self.y)
142+
fcurv = interp1d(self.station, self.curvature)
143+
144+
ds = 16.0
145+
for i in range(len(self.x) ):
146+
if ds < self.station[i] - station_[-1] or i == (len(self.x) - 1):
147+
if i == (len(self.x) - 1):
148+
ds = self.station[-1] - station_[-1]
149+
s = station_[-1] + ds
150+
print(ds)
151+
152+
# interp for new x, y, curvature at s
153+
x_.append( float( fx(s) ) )
154+
y_.append( float(fy(s)) )
155+
station_.append(s)
156+
curvature_.append( float(fcurv(s)) )
157+
# reset
158+
ds = 16
159+
160+
ds = min(ds, 0.1/abs(self.curvature[i]) )
161+
ds = max(ds, 1.0) # saturation of ds
162+
163+
#update the class members x, y, th, station, curvature
164+
plt.plot(self.x, self.y, 'b.')
165+
plt.plot(x_, y_, 'r.')
166+
plt.xlabel('x [m]')
167+
plt.ylabel('y [m]')
168+
plt.legend(['original','adjusted'], loc='best')
169+
plt.show()
170+
171+
plt.plot(self.station, self.curvature, 'b.')
172+
plt.plot(station_, curvature_, 'r.')
173+
plt.xlabel('station [m]')
174+
plt.ylabel('curvature [m]')
175+
plt.legend(['original','adjusted'], loc='best')
176+
plt.show()
187177

188178
self.x = x_
189179
self.y = y_

0 commit comments

Comments
 (0)