-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPathPlanning_WithoutTwice.m
90 lines (77 loc) · 3.34 KB
/
PathPlanning_WithoutTwice.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
89
90
function [ppath, stay_node_list, completionTime,computeDuring] = PathPlanning_WithoutTwice(last_completionTime, last_path, schedule, stay_node_list, devicelist, parameterlist)
%PathPlanningWithoutTwice - 对比算法1ï¼šæ— äºŒæ¬¡å¸è½½ç–略,åªèƒ½ç‰å¾…本地任务计算完毕å†ç§»åŠ¨åˆ°ä¸€ä¸ªèŠ‚ç‚?
%
% Syntax: [ppath, stay_node_list, completionTime] = PathPlanningWithoutTwice(input)
%
% 原地å¸è½½çš„ç–ç•¥ä¸ä¼šåŒæ—¶è£…载多个任务,故ä¸ç”¨è?ƒè™‘å˜å‚¨å¤§å°é™åˆ¶
temp_path = last_path;
temp_completionTime = last_completionTime;
temp_stay_node_list = stay_node_list;
temp_computeDuring = 0;
min_completionTime = temp_completionTime;
min_path = temp_path;
min_stay_node_list = stay_node_list;
% 2-opt找到path使æ?»ä½“完æˆæ—¶é—´æœ?å°?
% 注æ„ï¼Œæ— äºŒæ¬¡å¸è½½ï¼Œæ•…都是1,1; 3,3è¿™ç§æˆå¯¹å‡ºçŽ°çš„å½¢å¼?
opt = randperm(length(devicelist), 2);
opt_i = opt(1);
opt_j = opt(2);
temp_list = [];
for i = 1 : length(devicelist)
temp_list(end+1) = temp_path(1,2*i);
end
for iter = 1:parameterlist.iteration
opt_n = max(opt_i, opt_j) - min(opt_i, opt_j) + 1;
k = 1;
left = min(opt_i, opt_j);
right = max(opt_j, opt_i);
while k < floor(opt_n / 2)
temp = temp_list(1, left);
temp_list(1,left) = temp_list(1,right);
temp_list(1,right) = temp;
left = left + 1;
right = right - 1;
k = k + 1;
end
i = 1; j = 1;
while i <= length(temp_list)
temp_path(1,j) = temp_list(1,i);
temp_path(1,j+1) = temp_list(1,i);
j = j + 2;
i = i + 1;
end
% [temp_ddllist, temp_stoplist] = ComputeDDL(temp_path, devicelist, parameterlist);
% [temp_completionTime, ~, temp_stay_node_list] = ComputeNodeCompleteTime ...,
% (temp_ddllist, temp_stoplist, temp_path, schedule, 1, devicelist, parameterlist);
temp_completionTime = 0;
temp_computeDuring = 0;
for p = 1 : length(temp_path)
if mod(p,2) == 0
% 计算 + 移动
computetime = devicelist(temp_path(1,p)).computation / parameterlist.compute_freq;
if p ~= length(temp_path)
movetime = parameterlist.distance(temp_path(1,p),temp_path(1,p+1)) / parameterlist.move_speed;
else
movetime = 0;
end
temp_completionTime = temp_completionTime + computetime + movetime;
temp_computeDuring = temp_computeDuring + computetime;
else
% 上ä¼
uptime = devicelist(temp_path(1,p)).inputsize / parameterlist.trans;
temp_completionTime = temp_completionTime + uptime;
end
end
if (temp_completionTime < min_completionTime) && ...,
abs(temp_completionTime - min_completionTime) > parameterlist.epsilon
min_completionTime = temp_completionTime;
min_path = temp_path;
min_stay_node_list = temp_stay_node_list;
computeDuring = temp_computeDuring;
end
end
ppath = min_path;
stay_node_list = min_stay_node_list;
completionTime = min_completionTime;
computeDuring = temp_computeDuring;
end