Implement the Travelling salesman problem

Hey
I would like to implement the branch and bound algorithm to solve the TSP. For achieving this task I found good inputs at this website: https://ch.mathworks.com/help/optim/examples/travelling-salesman-problem.html
Attached you can find my script. At the moment I get following error message:
>> TSP Error using optim.problemdef.OptimizationProblem/solve options is not a valid solver. Use 'linprog' or 'intlinprog' instead.
Error in TSP (line 71) tspsol = solve(tsp,'options',opts)
Could someone help me to solve this problem? I don't know where is the fault. I have also an additional question. Is my script working with the branch and bound algorithm? I would guess so because the scripts contains constraints and subconstraints. But I'm not sure...
Best

3 comentarios

John D'Errico
John D'Errico el 31 de Mzo. de 2018
What version of MATLAB do you have? I would conjecture that you are using an older MATLAB release, that is too old to support what you tried to do.
Stefan Zeiter
Stefan Zeiter el 31 de Mzo. de 2018
Thanks for your reply
I have the version R2017b.
Stefan Zeiter
Stefan Zeiter el 31 de Mzo. de 2018
I guess this is the second newest version.

Iniciar sesión para comentar.

 Respuesta aceptada

John D'Errico
John D'Errico el 31 de Mzo. de 2018
Editada: John D'Errico el 31 de Mzo. de 2018
Your problem is here:
tspsol = solve(tsp,'options',opts)
which should be:
tspsol = solve(tsp,opts)
tspsol =
struct with fields:
trips: [19900×1 double]
As you can see, my release (also R2017b) has no problem.

3 comentarios

Stefan Zeiter
Stefan Zeiter el 1 de Abr. de 2018
Thanks for your answer. I updated the file.
Now I get a new error message.
Undefined function or variable 'updateSalesmanPlot'.
Error in TSP (line 80) lh = updateSalesmanPlot(lh,tspsol.trips,idxs,stopsLon,stopsLat);
I think I have to define the variable "updateSalesmanPlot" already in the beginning when I load the "usborder.mat".
So when I adapt the line number 5:
updateSalesmanPlot = load('usborder.mat','x','y','xx','yy');
Then I get this error message:
Subscript indices must either be real positive integers or logicals.
Error in TSP (line 80)
lh = updateSalesmanPlot(lh,tspsol.trips,idxs,stopsLon,stopsLat);
I hope you can help me one more time
Thanks
John D'Errico
John D'Errico el 1 de Abr. de 2018
NO. You do NOT define a variable named updateSalesmanPlot. That is expected to be a function. When you created it as a variable, it tries to index into the variable, instead of calling a function by that name.
Stefan Zeiter
Stefan Zeiter el 1 de Abr. de 2018
Editada: Stefan Zeiter el 1 de Abr. de 2018
okay...
So you have an idea how I can prevent the Error message at line 80?
Subscript indices must either be real positive integers or logicals.
Error in TSP (line 80)
lh = updateSalesmanPlot(lh,tspsol.trips,idxs,stopsLon,stopsLat);

Iniciar sesión para comentar.

Más respuestas (1)

Alan Weiss
Alan Weiss el 2 de Abr. de 2018

0 votos

From the example that you mentioned click the "Try this example" button in MATLAB (not in your browser). This will take your MATLAB to the appropriate folder, containing the updateSalesmanPlot function, so MATLAB can find it.
Alan Weiss
MATLAB mathematical toolbox documentation

Preguntada:

el 31 de Mzo. de 2018

Respondida:

el 2 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by