Repository navigation
Expand file tree
/
Copy pathpreplan_plot.m
More file actions
144 lines (129 loc) · 6.31 KB
/
Copy pathpreplan_plot.m
File metadata and controls
144 lines (129 loc) · 6.31 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
function [traj_segment,time_given_charger] = preplan_plot(a,numTarChargers,userConfig,start_point,start_pCharger)
%% Plot
N = length(a.optRoute);
rng = [[1 a.optBreak+1];[a.optBreak N]]';
clr = [1 0 0; 0 0 1; 1 0 1; 0 1 0; 1 0.5 0; .5 .5 0 ;0 0 0; 1 .5 .5];
clr = [clr;zeros(10,3)];
figure
hAx = gca;
hold on
batteryLife = a.charging_level;
% battery_history = zeros(a.nSalesmen,560);
man_battery_count = zeros(1,a.nSalesmen);
count = 1;
battery_life_count = 1;
% evaluate the mission
for s = 1:a.nSalesmen
d = userConfig.start_mat(a.optRoute(rng(s,1)),1); % add starting point
time = d/userConfig.start_mat(a.optRoute(rng(s,1)),2);
time_charging = time;
% battery_history(s,ceil(time)) = 20 - time;
for k = rng(s,1):rng(s,2)-1
time_charging = time_charging + a.dmat(a.optRoute(k),a.optRoute(k+1))/userConfig.delta_v;
if time_charging > batteryLife(s,man_battery_count(s)+1) % if the battery is enough to make this travel
battery_life_time(battery_life_count) = time_charging - a.dmat(a.optRoute(k),a.optRoute(k+1))/userConfig.delta_v; % evaluate each trajectory segment
time_start_charging(battery_life_count) = time; % time to start charging
% battery_history(s,ceil(time_start_charging)) = 20 - time_charging;
time = time + userConfig.charging_time; % add charging period TODO: add a ratio for charging ratio
time_end_charging(battery_life_count) = time; % time finished charging
% battery_history(s,ceil(time_end_charging(battery_life_count))) = 20;
time_charging = a.dmat(a.optRoute(k),a.optRoute(k+1))/userConfig.delta_v;
index_Stations(battery_life_count) = count;
battery_life_count = battery_life_count + 1;
man_battery_count(s) = man_battery_count(s) + 1;
end
d = d + a.dmat(a.optRoute(k),a.optRoute(k+1)); % distance
time = time + a.dmat(a.optRoute(k),a.optRoute(k+1))/userConfig.delta_v;
% battery_history(s,ceil(time)) = 20 - time_charging ; % battery life at time step
count = count + 1;
end
count = count + 1;
temp(s)=d;
time_temp(s)=time;
totalTime = max(time_temp);
% battery_history = battery_history(:,1:ceil(totalTime));
rte = a.optRoute(rng(s,1):rng(s,2));
plot(hAx,[start_point(s,1); a.xy(rte,1)],[start_point(s,2); a.xy(rte,2)],'--','linewidth',2,'Color',clr(s,:));
% plot(hAx,[a.xy(rte,1)],[a.xy(rte,2)],'.-','linewidth',2,'Color',clr(s,:));
hold(hAx,'on');
end
fprintf('total energy =')
disp(sum(time_temp))
%% Plot chargers
% charger marker
C = char('s','o');
[scheduled_start, scheduled_ind] = sort(time_start_charging); % sort time schedule
pStation = a.optRoute(index_Stations);
scheduled_charger = pStation(scheduled_ind);
% scheduled_start = time_start_charging(scheduled_ind);
scheduled_end = time_end_charging(scheduled_ind);
num_chargering_period = length(a.charging_location);
NUm = ones(1,numTarChargers)*floor(num_chargering_period/numTarChargers);
remainder_NUm = rem(num_chargering_period,numTarChargers);
NUm(1:remainder_NUm) = NUm(1:remainder_NUm) + 1;
ic_count = 1;
new_order_pStation = zeros(1,num_chargering_period);
time_start = zeros(1,num_chargering_period);
time_end = zeros(1,num_chargering_period);
% scheduling for chargers
for ic = 1:numTarChargers
for jc = 1:NUm(ic)
new_order_pStation(ic_count) = scheduled_charger((jc-1)*numTarChargers+ic);
time_start(ic_count) = scheduled_start((jc-1)*numTarChargers+ic);
time_end(ic_count) = scheduled_end((jc-1)*numTarChargers+ic);
ic_count = ic_count + 1;
end
end
%% Calculate charger energy
time_charger = zeros(numTarChargers,40);
time_charger_travel = zeros(1,length(new_order_pStation)-numTarChargers+1);
time_end_start = zeros(1,length(new_order_pStation)-numTarChargers+1);
cum_NUm = cumsum(NUm);
charger_location_ind = [[1,cum_NUm(1:end-1)+1];cum_NUm]';
charger_count = 1;
for ic = 1:numTarChargers
charger_energy_count = 1;
time_charger_travel(charger_count) = userConfig.start_mat(new_order_pStation(charger_location_ind(ic,1)),2*a.nSalesmen+ic)/userConfig.delta_vc;
time_end_start(charger_count) = time_start(charger_location_ind(ic,1));
charger_count = charger_count + 1;
charger_energy_count = charger_energy_count + 1;
for jc = charger_location_ind(ic,1):charger_location_ind(ic,2)-1
time_charger_travel(charger_count) = a.dmat(new_order_pStation(jc),new_order_pStation(jc+1))/userConfig.delta_vc;
time_charger(ic,charger_energy_count) = time_charger_travel(charger_count);
time_end_start(charger_count) = time_start(jc+1) - time_end(jc);
charger_count = charger_count + 1;
charger_energy_count = charger_energy_count + 1;
end
end
time_given_charger = time_end_start;
% cum_NUm = cumsum(NUm);
% charger_location_ind = [[1,cum_NUm(1:end-1)+1];cum_NUm]';
count_p = 1;
% for ic = 1:numTarChargers
% plot(start_pCharger(ic,1),start_pCharger(ic,2),C(ic),'linewidth',2,'MarkerSize',20,'MarkerEdgeColor',clr(s+ic,:))
% text(start_pCharger(ic,1)-.2,start_pCharger(ic,2),'1','color',clr(s+ic,:),'FontSize',14)
% end
for ic = 1:numTarChargers
for id = 1:1
plot(a.xy(a.charging_location(count_p),1), a.xy(a.charging_location(count_p),2),C(ic),'linewidth',2,'MarkerSize',20,'MarkerEdgeColor',clr(s+ic,:))
text(a.xy(a.charging_location(count_p),1)-.2,a.xy(a.charging_location(count_p),2),num2str(id),'color',clr(s+ic,:),'FontSize',14)
count_p = count_p +1;
end
end
count_p = 1;
plot([0.5,14.5,14.5,0.5,.5],[0.5,.5,14.5,14.5,.5],'k','LineWidth',3)
for ic = 1:numTarChargers
for id = 2:NUm(ic)
plot(a.xy(a.charging_location(count_p),1), a.xy(a.charging_location(count_p),2),C(ic),'linewidth',2,'MarkerSize',20,'MarkerEdgeColor',clr(s+ic,:))
text(a.xy(a.charging_location(count_p),1)-.2,a.xy(a.charging_location(count_p),2),num2str(id),'color',clr(s+ic,:),'FontSize',14)
count_p = count_p +1;
end
end
legend('AUV#1','AUV#2','AUV#3','charger#1','charger#2','border')
legend('boxoff')
% plot(a.xy(a.charging_location,1),a.xy(a.charging_location,2),'s','MarkerSize',10,'MarkerEdgeColor',clr(s+ic,:))
xlabel('X (km)')
ylabel('Y (km)')
axis([0,18,0,15])
traj_segment = battery_life_time;
end