How to solve TSP using GA?

15 ビュー (過去 30 日間)
Muhammad Qaisar Fahim
Muhammad Qaisar Fahim 2023 年 3 月 6 日
回答済み: Alan Weiss 2023 年 3 月 8 日
Hello,
I am trying to compare some solvers and I am using TSP (https://www.mathworks.com/help/optim/ug/travelling-salesman-problem.html) as my bench mark problem. I am not sure how to define this problem so that I can solve it using GA. The way I though is to replace this line with GA
[x_tsp,costopt,exitflag,output] = intlinprog(dist,intcon,[],[],Aeq,beq,lb,ub,opts);
But I am getting an error when I do this:
x_tsp = ga(dist,nStops,[],[],Aeq,beq,lb,ub,intcon)
This is the error message.
Error using ga
Fitness function must be a function handle.
Error in GA_1 (line 65)
x_tsp = ga(dist,nStops,[],[],Aeq,beq,lb,ub,intcon)

回答 (1 件)

Alan Weiss
Alan Weiss 2023 年 3 月 8 日
I think that it is useless to try to solve a TSP using ga, mainly because ga is so slow and unreliable compared to Optimization Toolbox solvers. If you want to see an approach to solving a TSP using ga, look at Custom Data Type Optimization Using the Genetic Algorithm.
But if you ignore my advice and insist on trying to use ga inappropriately to solve a TSP using exactly the algorithm described for intlinprog, then you need to create a function handle that gives the value of a tour; you cannot use a vector as intlinprog does to represent an objective function.
fun = @(x)dot(x,dist);
Please do not use this; you will not get a good solution, and it will take a long time.
Alan Weiss
MATLAB mathematical toolbox documentation

カテゴリ

Help Center および File ExchangeTraveling Salesman (TSP) についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by