-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIteratedLocalSearch_SA.m
50 lines (42 loc) · 1.49 KB
/
IteratedLocalSearch_SA.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
% Befor use this repository, you have to add the path at once.
% p = path;
% pathAssets = strcat(pwd,'/assets/');
% path(path,pathAssets);
clc;
close all;
clear;
%% --- Create cities and map
nStops = 100; % you can use any number, but the problem size scales as N^2
[distMap, stopsLon, stopsLat] = initCities(nStops);
%% --- params of Simulated Aneealing
temperature = 4000;
cool_coefficient = 0.935;
timesNeighbor = 30;
%% --- params of IteratedLocalSearch
iterate = 19;
bestCosts = zeros(iterate+1,1);
%% --- Step1: output initial tour;
initTour = getRandomTour(nStops);
%% --- Step2: LocalSearch(tour)
% This code use Simulated Annealing (2-opt)
doPlot = 1;
[ bestCost, bestTour ] = doSimulatedAnnealing(distMap,stopsLon,stopsLat,timesNeighbor,temperature,cool_coefficient,nStops,initTour,doPlot);
bestCosts(1,1) = bestCost;
%% --- Step3: LocalSearch(tour)
% Step2で得た局所解を中心に、局所解を抜け出す目的でN-Optを行った状態を初期値しとして局所解を行なう。
% これをiterate回行なう
for i = 1:iterate
nextInitTour = getNOpt(bestTour,4);
[ bestCost, bestTour ] = doSimulatedAnnealing(distMap,stopsLon,stopsLat,timesNeighbor,temperature,cool_coefficient,nStops,nextInitTour,doPlot);
bestCosts(i+1,1) = bestCost;
end
doPlot = 1;
%% --- 可視化
if doPlot == 1
% 各時点での最小値の遷移
figure('Name','Best value of each local search','NumberTitle','off')
plot(bestCosts,'LineWidth',2);
xlabel('iteration');
ylabel('Best Cost');
grid on;
end