How to create simulated annealing objective function?

4 views (last 30 days)
Hello!
I want to create a objective function for Travelling salesman problem using simulated annealing with global optimization toolbox.
Does anyone have idea how to make these?
Thank you for help
  3 Comments
jan grlica
jan grlica on 28 May 2015
Thank you.
Yes i can't look on the second link too.
jan grlica
jan grlica on 28 May 2015
Edited: Walter Roberson on 28 May 2015
for now my programe is looking like these: one .m file:
clc
close all
clear all
global pot
global y
global x
global bestfval_log
global N
bestfval_log = [];
ime=[1 2 3];
str1 = 'Enka';
str2 = 'Dvojka';
str3 = 'Trojka';
x=[1 2 3];
y=[1 2 3];
N=length(x);
figure ('Name', 'Popotnik');
axes('Color', [0.5 0.5 0.5]);
axis([0 10 0 10]);
hold on;
for i=1:N
plot(x(i), y(i), 'g+');
end
text(x(1),y(1),str1);
text(x(2),y(2),str2);
text(x(3),y(3),str3);
pot=1:N;
x0=[0 0];
[x, fval, exitFlag, output] = simulannealbnd(@kriterijskafunckija, x0);
and my objective function is:
function d = kriterijskafunkcija(pot)
%global pot
global x
global y
global N
%global d
d=0;
for i=1:N-1
d=d+((x(pot(i))-x(pot(i+1)))^2+(y(pot(i))-y(pot(i+1)))^2)^.5;
end
i=N;
d=d+((x(pot(i))-x(pot(1)))^2+(y(pot(i))-y(pot(1)))^2)^.5;
anyone knows how to move forward and make these work

Sign in to comment.

Answers (2)

Alan Weiss
Alan Weiss on 28 May 2015
Edited: Alan Weiss on 28 May 2015
The simulated annealing solver is based on continuous variables by default. Perhaps you could make it work for a custom data type, similar to the genetic algorithm solution. But travelling salesman problems are most easily formulated for integer variables. For solutions, see this MILP example which uses Optimization Toolbox, or this genetic algorithm example using Global Optimization Toolbox and a custom data type.
Alan Weiss
MATLAB mathematical toolbox documentation

Walter Roberson
Walter Roberson on 28 May 2015
See my discussion in http://uk.mathworks.com/matlabcentral/answers/220440-simulated-annealing-how-to-solve-this-error as to what the problem is here (the code has exactly the same basic problem here), and as to why it is hard to fix.
The short summary: you can use Simulated Annealing techniques with Traveling Salesperson, but using simulannealbnd() itself for the problem is going to be difficult.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!