-
Notifications
You must be signed in to change notification settings - Fork 3
/
jsfp_inertia.m
82 lines (60 loc) · 2.7 KB
/
jsfp_inertia.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
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
% Joint Strategy Fictitious Play with Inertia
%{
3 parallel roads; 60 vehicles;
n_r be number of vehicles on road r.
time - determines number of rows of matrix! time varies along a col.
%}
close all; clear all;clc;
totalAgents = 60; %
totalResources = 3; % roads
epsilon = 0.1; % learning-inertia
numIterations = 200; % total-iterations of the game-play.
% -------------------------------------------------------------------------
% initialize Agents
numActions = totalResources;
for i = 1:totalAgents % iterate over agents to make them update their internal state
msg = sprintf('P%d = AgentClass(numActions, epsilon, totalAgents, numIterations);',i);
eval(msg);
end
% -------------------------------------------------------------------------
% initialize roads
ROADS = ResourcesClass(totalResources, numIterations);
% -------------------------------------------------------------------------
% time-iterations of jsfp_inertia
for t=1:numIterations
% obtain Agents' action-choices
actionProfile = zeros(1,totalAgents);
for i = 1:totalAgents % iterate over agents to get their action-choice
msg1 = sprintf('P%d',i);
msg2 = sprintf('P%d.getAction(t);',i);
eval(['[actionProfile(i), ',msg1,'] = ',msg2,';']);
end
% msg = sprintf('Platform: actionProfile = \n');
% disp(msg) % warning(msg)
% actionProfile
%----------------------------------------------------------------------
% compute number of agents on each resource
numAgentsOnResources = zeros(1,totalResources);
for i = 1: totalResources
numAgentsOnResources(i) = sum((actionProfile == i),2) ;
end
% msg = sprintf('Platform: numAgentsOnResources = \n');
% disp(msg) % warning(msg)
% numAgentsOnResources
%----------------------------------------------------------------------
% compute congestion costs experienced
[congestionCosts, ROADS] = ROADS.getResourceCosts(numAgentsOnResources,t);
%----------------------------------------------------------------------
% provide Utility to Agents
for i = 1:totalAgents % iterate over agents to make them update their internal state
% update Expected-Utility of each arm
msg = sprintf('P%d = P%d.updateAgentExpectedUtility(numAgentsOnResources, congestionCosts, t) ;', i, i);
eval(msg);
% % update JointAction Empirical Frequency
% msg = sprintf('P%d = P%d.updateAgentJointActionFrequency(numAgentsOnResources, congestionCosts, t);', i, i)
% eval(msg);
end
end
ROADS.plotResourceCongestion();
P1.plotAgentRegret();
% -------------------------------------------------------------------------