function ordering = HillClimbing_TSP(cities)
disp('Hill Climbing TSP:')
tic
N = length(cities);
numIter = 1000;
orders = randperm(N);
orders = [orders, orders(1)];

cur_dis = 0;
for j = 1:N
    dis_temp = sqrt((cities(orders(j), 1)-cities(orders(j+1),1))^2 + (cities(orders(j),2)-cities(orders(j+1),2))^2);
    cur_dis = cur_dis + dis_temp;
end

for i = 1:numIter
    new_dis = 0;
    city1 = ceil(rand*N);
    city2 = ceil(rand*N);
    if city1 ~= city2
        new_order = orders;
        temp = new_order(city1);
        new_order(city1) = new_order(city2);
        new_order(city2) = temp;
        new_order = [new_order(1:end-1), new_order(1)];
        for j = 1:N
            dis_tmp = sqrt((cities(new_order(j), 1)-cities(new_order(j+1),1))^2 + (cities(new_order(j),2)-cities(new_order(j+1),2))^2);
            new_dis = new_dis + dis_tmp;
        end
        
        if new_dis < cur_dis
            orders = new_order;
            cur_dis = new_dis;
        end
    end
end

ordering = orders;
toc
%plot the resulting ordering of cities as
figure;
plot(cities(ordering,1),cities(ordering,2), '-o')
title('Hill Climbing TSP');
hold on
for k = 1:N
    text(cities(ordering(k),1),cities(ordering(k),2), num2str(k), 'color', 'r', 'FontSize',18);
end
hold off

disp('Hill Climbing TSP:')
cur_dis
ordering