how can i display an answer for all iteration?
Show older comments
i have this coding for quadratic assignment problem (assign facilities to location using flow and distant matrix)
i want to display all the answer that i get from 10 iteration
%%read data
clc
clear
%flow
f=[ 0 90 10 23 43 0 0 0 0 0 0 0
90 0 0 0 0 88 0 0 0 0 0 0
10 0 0 0 0 0 26 16 0 0 0 0
23 0 0 0 0 0 0 0 0 0 0 0
43 0 0 0 0 0 0 0 0 0 0 0
0 88 0 0 0 0 0 0 1 0 0 0
0 0 26 0 0 0 0 0 0 0 0 0
0 0 16 0 0 0 0 0 0 96 0 0
0 0 0 0 0 1 0 0 0 0 29 0
0 0 0 0 0 0 0 96 0 0 0 37
0 0 0 0 0 0 0 0 29 0 0 0
0 0 0 0 0 0 0 0 0 37 0 0];
%distance
d=[ 0 36 54 26 59 72 9 34 79 17 46 95
36 0 73 35 90 58 30 78 35 44 79 36
54 73 0 21 10 97 58 66 69 61 54 63
26 35 21 0 93 12 46 40 37 48 68 85
59 90 10 93 0 64 5 29 76 16 5 76
72 58 97 12 64 0 96 55 38 54 0 34
9 30 58 46 5 96 0 83 35 11 56 37
34 78 66 40 29 55 83 0 44 12 15 80
79 35 69 37 76 38 35 44 0 64 39 33
17 44 61 48 16 54 11 12 64 0 70 86
46 79 54 68 5 0 56 15 39 70 0 18
95 36 63 85 76 34 37 80 33 86 18 0];
[r,c]=size(f);
max_i= r;
max_j =r;
max_k= r;
max_q= r;
MaxIt=10;
for no=1:MaxIt
ID=randperm(r); %PERMUTATION r NOMBOR ..r = 3, 1 2 3, 1 3 2...
x=zeros(r,r);
n=length(ID);
x1=ID;
for i=1:n
for j=1:r
x(j,x1(j))=1;
B(i).mat=x; % used to keep the memory when 0,1 permutation in (i),for BINARY RELATION
end
x=zeros(r,r);
end
z=0;xa=B(no).mat;
for i=1:max_i
for j=1:max_j
for k=1:max_k
for q=1:max_q
z= z+ f(i,k).*d(j,q).*xa(i,j).*xa(k,q); %find the min value of the assignment
end
end
end
end
no;
F(no,:)=[no z]; %STOR ALL VALUE Z 1...UNTIL MaxIt IN MATRIX F
end
%end
zmin=min(F(:,2));
ii=find(F(:,2)==zmin) ;
x_initial = B(ii).mat;
% xbin= B(ii).mat % xbin = initial value for facility location for minimun z
z_minimum = zmin
Iter_zvalue = F % matrix F has no of iteration..col 1 dan z
Iter_MaxIt = ID
% disp(ID)
i want to make it display the iteration as example below, but i didnt know how to do it
exp:
Iter_MaxIt 1=
11 4 7 5 12 3 9 1 2 8 6 10
F 1 =
31868
Iter_MaxIt 2=
11 4 7 5 12 3 9 1 2 8 6 10
F 2 =
31868
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!