-
Notifications
You must be signed in to change notification settings - Fork 0
/
lm-mcms3.py
38 lines (31 loc) · 1.21 KB
/
lm-mcms3.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
def reward_function(params):
'''
Minimal curvature max speed reward
'''
# Read input parameters
all_wheels_on_track = params['all_wheels_on_track']
steering_abs = abs(params['steering_angle']) # Only need the absolute steering angle
speed = params['speed']
progress_reward = params['progress']
distance_from_center = params['distance_from_center']
track_width = params['track_width']
if progress_reward >= 100:
progress_reward = 7000
else:
progress_reward = progress_reward * 10
# parameter to be optimized
speed_treshold = 3000
# calculated parameter
steering_treshold = 50
if steering_abs != 0.:
steering_factor = steering_abs
else:
steering_factor = 0.1
reward = progress_reward + steering_treshold/steering_factor + speed_treshold * speed * speed
if distance_from_center <= 0.37 * track_width:
distance_factor = (track_width - distance_from_center) / track_width
reward = reward * distance_factor * distance_factor * distance_factor
# we just do not accept the wheels off track
if not params["all_wheels_on_track"]:
reward = reward / 100.
return float(reward)