Travelling Salesman problem code additional constraint

1 次查看(过去 30 天)
function Y = evaluation(P)
% P = population
% Distances between 10 cities
% city 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17%
D=[ 0 242 237 113 165 140 94 110 151 145 167 179 151 240 289 245 148
242 0 72 201 337 148 180 236 143 98 102 96 101 5 55 98 100
237 72 0 148 311 95 158 230 110 164 168 66 99 70 17 33 166
113 201 148 0 122 68 164 163 70 215 234 113 134 223 209 165 218
165 337 311 122 0 196 247 264 197 298 318 239 241 349 335 291 302
140 148 95 68 196 0 116 188 32 187 163 45 71 161 112 127 190
94 180 158 164 247 116 0 74 133 83 62 100 59 173 181 185 87
110 236 230 163 264 188 74 0 200 138 129 172 131 234 239 257 142
151 143 110 70 197 32 133 200 0 204 174 48 89 142 95 94 207
145 98 164 215 298 187 83 138 204 0 24 164 130 97 147 191 4
167 102 168 234 318 163 62 129 174 24 0 127 106 100 143 194 28
179 96 66 113 239 45 100 172 48 164 127 0 42 109 83 91 167
151 101 99 134 241 71 59 131 89 130 106 42 0 97 108 124 133
240 5 70 223 349 161 173 234 142 97 100 109 97 0 50 94 99
289 55 17 209 335 112 181 239 95 147 143 83 108 50 0 44 149
245 98 33 165 291 127 185 257 94 191 194 91 124 94 44 0 193
148 100 166 218 302 190 87 142 207 4 28 167 133 99 149 193 0] ; %city 10
[x y] = size(P);
C=0;
for j = 1:x
A=P(j,:);
B=0;
for i = 1:y-1
B(i)=D(A(i),A(i+1));
end
B(y)=D(A(y),A(1));
C(j)=1/sum(B); % minimization problem
end
% Y=C;
How to add contraint that path generated should have starting point as city 1 and ending location also city 1.
I attached complete GA algorithm please update the constraint part and attach it...

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by