-
Notifications
You must be signed in to change notification settings - Fork 16
/
obtainReward.m
39 lines (36 loc) · 1.32 KB
/
obtainReward.m
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
function reward = obtainReward(this, phase)
% Copyright 2020 The MathWorks, Inc.
reward = 0;
driver = [];
for i = 1:this.N
% get all of the drivers from each of the road
if ~isempty(this.network(i).Vehicles)
driver = [this.network(i).Vehicles.MotionStrategy];
end
if isempty(driver)
continue
end
% component 1: judge by the distance to intersection
% distance_to_intersection = network(i).Length - driver.getStationDistance;
% reward = reward - sum(distance_to_intersection < this.thresholdDistance);
% component 2: waiting time
% speed of the car is lower that specified speed limit
% is the one get delay
speed = driver.getSpeed;
reward = reward - sum(speed < this.slowSpeedThreshold) * this.scenario.SampleTime;
% strategy 3: maximize the cars speed
speed = driver.getSpeed;
reward = reward + sum(speed) * 0.01;
end
% component 4: get reward when car are entering the intersection
for i = 7:12
if isempty(this.network(i).Vehicles)
continue
end
for j = 1:length(this.network(i).Vehicles)
if ~ismember(this.network(i).Vehicles(j), this.vehicleEnterJunction)
reward = reward + this.rewardForPass;
this.vehicleEnterJunction = [this.vehicleEnterJunction this.network(i).Vehicles(j)];
end
end
end