Skip to main content
. 2023 Jan 9;25(1):135. doi: 10.3390/e25010135
Algorithm 4 Reward function for the vehicle agent (Code Listing 4: Reward Function)
1 REWARD (st, at){
2 vmin ← 5
3 vbrake ← 20
4 vmax ← 18
5 ɸthreshold ← 0.05
6 reward ← 0
if (vt > vbrake and acct = Brake){
8    reward ← reward + 1}
else if (vt > vbrake and acct = accelerate){
10    reward  ← reward − 1}
11 else if (vt > vmax and acct = Brake){
12    reward ← reward − 1}
13 else if (vt > vmax and acct = Accelerate){
14    reward ← reward + 1}
15 else if (ɸt < −ɸthreshold and steer t = TurnRight){
16     reward ← reward + 1}
17 else if (ɸt < −ɸthreshold and steer t = TurnLeft){
18    reward ← reward − 1}
19 else if (ɸt > −ɸthreshold and steer t = TurnLeft){
20    reward ← reward + 1}
21 else if (ɸt > ɸthreshold and steer t = TurnRight){
22    reward ← reward − 1}
23 else if (vt < vmin and acct ≠ Accelerate){
24    reward ← reward − 1
25 return REWARD
26 }