-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfwy_no_rmp.m
88 lines (86 loc) · 2.02 KB
/
fwy_no_rmp.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
83
84
85
86
87
88
% x is the primary variable of optimization problem
% alpha's are the prices
% n : mainline density
% l : onramp density
% f : mainline flows
% r : onramp flows
clear all;
close all;
clc;
% network data
network_210East;
%% initial condition
n_segment = size(params.v,1);
n_or = size(find(params.has_or),1);
or_ind = find(params.has_or);
n0 = 100*ones(n_segment,1);
l0 = 10*ones(n_or,1);
%% Charaterizing feasibility of arrivals
f_ss = zeros(n_segment,1);
f_ss(1,1) = (1-params.beta(1))^(-1)*(params.d_up(1));
or_it = 0;
for j = 2:n_segment
if params.has_or(j)
or_it = or_it + 1;
f_ss(j) = (1-beta(j))^(-1)*(f_ss(j-1)+params.d(or_it));
else
f_ss(j) = (1-beta(j))^(-1)*(f_ss(j-1));
end
if f_ss(j) > params.f_bar(j)
warning('infeasible arrival')
end
end
%% start and end times
h_s = 8;
h_e = 9;
t_s = h_s*12*100;
t_e = h_e*12*100;
%% setting up the optimization
% n_seg = size(params.v,1);
% n_or = size(find(params.has_or),1);
n_cur = n0;
l_cur = l0;
max_iter = t_e - t_s + 1;
% preallocation
n = zeros(n_seg,max_iter+1);
l = zeros(n_or, max_iter+1);
f = zeros(n_seg, max_iter);
r = zeros(n_or, max_iter);
n(:,1) = n0;
l(:,1) = l0;
%% iterative control
for iter = 1:max_iter
% control input
r_cur = min(params.r_bar, l_cur + params.d_tv(:,t_s+iter-1));
r_cur = min(r_cur, 0.1*(params.n_bar(or_ind)-n_cur(or_ind)));
% evolve model
[n_next, l_next, f_cur] = fwyDynamics_tv(n_cur, l_cur, r_cur, params, t_s+iter-1);
% storage
n(:,iter+1) = n_next;
l(:,iter+1) = l_next;
f(:,iter) = f_cur;
r(:,iter) = r_cur;
% updating current density
n_cur = n_next;
l_cur = l_next;
end
%% plotting
figure('name','n');
plot(n','LineWidth',2);
% legend('n_1','n_2','n_3')
figure('name','l');
plot(l','LineWidth',2);
% legend('l_1','l_2','l_3')
figure('name','f');
plot(f','LineWidth',2);
% legend('f_1','f_2','f_3')
figure('name','r');
plot(r','LineWidth',2);
% legend('r_1','r_2','r_3')
%%
% figure;
% plot(l_cur','b');
% figure;
% plot(r_cur','r');
% figure;
% plot(params.d','k');