Asked by sharifah shuthairah syed abdullah
on 13 Oct 2018 at 16:34

i have this coding, i want to have make a loop of for 10 iteration.. the curent coding didnt give me 10 iteration..

i want to have 10 possible solution however its only show 1 solution. below is the coding. what can i do to make it generate 10 solution

%read data clc clear %global f d; %flow f=[ 0 5 2 4 1 5 0 3 0 2 2 3 0 0 0 4 0 0 0 5 1 2 0 5 0]; %distance d=[ 0 1 2 3 1 1 0 1 2 2 2 1 0 1 3 3 2 1 0 4 1 2 3 4 0]; [r,c]=size(f); max_i= r; max_j =r; max_k= r; max_q= r; A=zeros(r,r); ID=randperm(r); MaxIt=10; 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; %store permutationof binary value, 0,1 end x=zeros(r,r); end for i=MaxIt for no=1:length(B) 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); end end end end end no; F(no,:)=[no z]; end zmin=min(F(:,2)); ii=find(F(:,2)==zmin) ; x_initial = B(ii).mat; xbin= B(ii).mat z_minimum = zmin

%disp(B(ii).mat) %fprintf (B(no).mat); %disp(z)

Opportunities for recent engineering grads.

Apply Today
## 10 Comments

## madhan ravi (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_621957

which solution?

## sharifah shuthairah syed abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_622134

for the current coding it can only produce one random solution. how can i code so that it can produce multiple solution? can you help me?

## Kevin Chng (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623569

Hi

You direct assign the value of MaxIt to i, this is not looping the for-loop. Therefore, you will only have the solution when i = MaxIt, change it to

However, I guess it has yet completely solve your solution.

## sharifah shuthairah syed abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623570

oo..thanks.. i get the answer..however, how can i see all the solution?

## Kevin Chng (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623573

I'm unclear with your intention on your programming, can't give proper advise...

I suspect the code above is not in right position to collect the data. However, if you want get the result from all the iteration for F, you could edit your code like this:

Then in the zmin there

Then you will get 10 zmin result.

## sharifah shuthairah syed abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623579

Dear @kevin Vhng i change the coding as what you ask and i get

## Kevin Chng (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623614

Hi, B(ii).mat is a structure with 5 double matrix within.

i'm unsure with your intention, if let say want to run without error, you may try

change your MaxIt to 5

then change your code to

I am sorry that I can't help you too detail because i don't know your intention of your code. But i guess something wrong with the programming logic.

## sharifah shuthairah syed abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623641

please dont be sorry, im feel very grateful for ur reply, actually my intention to solve the Quadratic Assignment Problem using GA, this is the 1st step which is to fine the initial population, which is the set of solution.. however the coding didnt show set of solution, it only show 1 solution.. are my coding itself is wrong?

## Kevin Chng (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_623857

Quadratic Assignment Problem using GAI'm not familiar with the topic above, do you have pseudocode for it? or any reference for me to see? Where do you find reference to write your code?

Perhaps they will help me to understand more.

## sharifah shuthairah syed abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423824-how-can-i-make-it-to-loop-of-an-iteration#comment_624081

i have the step

http://iopscience.iop.org/article/10.1088/1757-899X/300/1/012002 this is the paper that i write for conference.. i want to solve the problem using genetic algorithm

the reference is from one f my lecturer in my university... i find one coding that solve the same problem using the same method, however i need to change here and there, and its become difficult..that is why i want to build my own..however i find a difficulties also..

Sign in to comment.