-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsa.m
More file actions
50 lines (47 loc) · 1.37 KB
/
sa.m
File metadata and controls
50 lines (47 loc) · 1.37 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
clc;
clear;
%% Maghadire Avvalie
n = 10; %teedade node-ha
m = 20; %tedade vasayele naghlie
q = 40; %zarfiate har vasile
maxTime = 120; %hadde aksare zaman baraye harekat az mabdaa ta maghsad
[g, d] = generateNewGraph(n, q, maxTime); % g : Graphe Jadid | d : Depo
[swp, cost, T, Q, C] = sweep(g, q, m, d, maxTime); %ie-jade javabe jadid va mohasebe cost
Cost(1) = cost;
Sweep{1} =swp;
bestState.sweep = swp;
bestState.cost = Cost(1);
Tem = 100;
maxCount = 100;
It = 1;
hold on;
tm=[];
while (It<=maxCount)
tic;
It = It +1;
[Sweep{It}, Cost(It), T, Q, C]= neighbourhood(g, d, maxTime, Sweep{It-1}, m, q, Q, T, C);
delta=Cost(It)-Cost(It-1);
if delta<=0
bestState.sweep=Sweep{It};
bestState.cost = Cost(It);
else
p=exp(-delta/Tem);
if rand<p
bestState.sweep=Sweep{It};
bestState.cost = Cost(It);
end
end
Tem=Tem*0.8;
display([num2str(It-1), ') tedade vasayele naghlie : ' num2str(size(bestState.sweep,2)) ' - hazineye kol : ' num2str(bestState.cost)]);
tm(end+1) = toc;
plot(It,Tem,'.');
end
hold off;
[bestCost,indx] = min(Cost);
display(['behtarin halat : ', num2str(size(Sweep{indx},2)), ' vasile ba hazineye kolle : ' , num2str(bestCost)]);
for i=1:size(bestState.sweep,2)
display(['masire ' num2str(i) ') ' num2str(Sweep{indx}{i})]);
end
drawGraph(g);
figure;
plot(tm);