This repository was archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModel.m
More file actions
60 lines (47 loc) · 1.61 KB
/
Copy pathModel.m
File metadata and controls
60 lines (47 loc) · 1.61 KB
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
classdef Model
%MODEL Summary of this class goes here
% Detailed explanation goes here
properties
numAngents % int -- number of agents
schedule % obj -- Time module
end
methods
function self = Model(N)
if nargin == 1
self.numAngents = N;
self.schedule = RandomActivation();
% Create agents
for i = 1:N
uniqueId = strcat('ag_',int2str(i));
a = Agent(uniqueId);
self.schedule.add(a);
end
end
end
function wealth = collect(self)
lenSched = length(self.schedule.agentsDic);
wealth = zeros(1, length(lenSched));
for i = 1 : lenSched % sorted
for j = 1 : lenSched % shuffled
id = self.schedule.agentsDic{1,j}.uniqueId;
id = strsplit(id,'_');
id = id(:,end);
id = str2double(id{1,1});
if id == i
wealth(1, i) = self.schedule.agentsDic{1,j}.wealth;
end
end
end
end
function visualization(self)
wealth = collect(self);
bar(wealth)
grid on
ylim([-15,20])
pause(0.08)
end
function step(self)
self.schedule.step();
end
end
end