-
Notifications
You must be signed in to change notification settings - Fork 1
/
support.m
42 lines (38 loc) · 1.31 KB
/
support.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
function [utils] = support()
%UTILS Summary of this function goes here
% Detailed explanation goes here
utils = struct();
utils.computeIncentivizedFlow = @computeIncentivizedFlow;
utils.swapStationIndices = @swapStationIndices;
utils.toStationTimeIndex = @toStationTimeIndex;
utils.splitDstar = @splitDstar;
end
function [f] = computeIncentivizedFlow(p, alpha, dinc, dstar)
f = (alpha * swapStationIndices(p, dstar) + swapStationIndices(p, dinc)) - ...
(alpha * dstar + dinc);
f = squeeze(sum(toStationTimeIndex(p, f), 2));
f = f(:);
end
function [b] = swapStationIndices(p, d)
b = permute(toStationTimeIndex(p, d), [2, 1, 3]);
b = b(:);
end
function [matrix] = toStationTimeIndex(p, vector)
if size(vector, 2) ~= 1
error("toStationTimeIndex:badDimension", "Input must be a column vector.");
end
switch numel(vector)
case (p.N * p.T)
matrix = reshape(vector, p.N, p.T);
case (p.N * p.N * p.T)
matrix = reshape(vector, p.N, p.N, p.T);
case (p.N * p.N)
matrix = reshape(vector, p.N, p.N);
otherwise
error("toStationTimeIndex:badNumel", "wrong number of elements");
end
end
function [dstarO, dstarD] = splitDstar(p, dstar)
dstarO = dstar(1:(p.N*p.N*p.T));
dstarD = dstar((p.N*p.N*p.T+1):end);
end