patternMinor
Processing random matrices
Viewed 0 times
randomprocessingmatrices
Problem
I am doing my research about scheduling by using Matlab. I am a new Matlab user and I have a problem with time execution of my following code:
```
clc
clear all
A=8;
B=12;
C=10;
ProcessTime= [ 11 11 11 11 4 4 4 4 4 4 4 2 ]; %Converting Matrice
RandomMatriceA=zeros(A,B,C);
RandomMatriceB=zeros(A,B,C);
SumRandomMatriceB=zeros(1,A,C);
ConvertMatriceA=zeros(A,B,C);
ProcessRandomMatriceA=zeros(A,B,C);
StartProcess=zeros(A,B,C);
EndProcess=zeros(A,B,C);
StartPost=zeros(A,B,C);
for ii=1:C;
for x=1:2:A-1;
%make first random matrice
[vals RandomMatriceA(x,:,ii)]=sort(rand(1,B),2); %batasan tidak boleh satu kelompok melakukan lebih dari satu aktivitas dalam satu waktu
done=false;
while ~done,
%make row of second random matrice
NewRowRandomMatriceB=randi([0 2],1,B);
%Make sure sum all element per row in RandomMatriceB <=11
done=sum(NewRowRandomMatriceB)<12;
end
RandomMatriceB(x,:,ii)=NewRowRandomMatriceB;
%After making RandomMatriceA and RandomMatriceB, then Make New
%Matrice
%To know varible of new matrice which is result of combining
%RandomMatriceA,RandomMatriceB and ProcessTime
for y=1:B,
ConvertMatriceA(x,y,ii)=ProcessTime(RandomMatriceA(x,y,ii));%FirstVarible:Consecutive The Number of value in all element of RandomMatriceA
end
ProcessRandomMatriceA(x,:,ii)=ProcessTime(RandomMatriceA(x,:,ii))+RandomMatriceB(x,:,ii);
EndProcess(x,:,ii)=cumsum(ProcessRandomMatriceA(x,:,ii),2);%secondVaribale:to know in which column The Consecutive value RandomMatrice will be end
StartProcess(x,:,ii)=EndProcess(x,:,ii)-(ProcessTime(RandomMatriceA(x,:,ii))-1);%ThirdVariable:to know in which column The Consecutive Value will be start
for yy=1:B;
N=RandomMatriceA(x,yy,ii);
StartPost(x,N,ii)=StartProcess(x,yy,ii);
end
end
for h=2:2:A;
doneA=
```
clc
clear all
A=8;
B=12;
C=10;
ProcessTime= [ 11 11 11 11 4 4 4 4 4 4 4 2 ]; %Converting Matrice
RandomMatriceA=zeros(A,B,C);
RandomMatriceB=zeros(A,B,C);
SumRandomMatriceB=zeros(1,A,C);
ConvertMatriceA=zeros(A,B,C);
ProcessRandomMatriceA=zeros(A,B,C);
StartProcess=zeros(A,B,C);
EndProcess=zeros(A,B,C);
StartPost=zeros(A,B,C);
for ii=1:C;
for x=1:2:A-1;
%make first random matrice
[vals RandomMatriceA(x,:,ii)]=sort(rand(1,B),2); %batasan tidak boleh satu kelompok melakukan lebih dari satu aktivitas dalam satu waktu
done=false;
while ~done,
%make row of second random matrice
NewRowRandomMatriceB=randi([0 2],1,B);
%Make sure sum all element per row in RandomMatriceB <=11
done=sum(NewRowRandomMatriceB)<12;
end
RandomMatriceB(x,:,ii)=NewRowRandomMatriceB;
%After making RandomMatriceA and RandomMatriceB, then Make New
%Matrice
%To know varible of new matrice which is result of combining
%RandomMatriceA,RandomMatriceB and ProcessTime
for y=1:B,
ConvertMatriceA(x,y,ii)=ProcessTime(RandomMatriceA(x,y,ii));%FirstVarible:Consecutive The Number of value in all element of RandomMatriceA
end
ProcessRandomMatriceA(x,:,ii)=ProcessTime(RandomMatriceA(x,:,ii))+RandomMatriceB(x,:,ii);
EndProcess(x,:,ii)=cumsum(ProcessRandomMatriceA(x,:,ii),2);%secondVaribale:to know in which column The Consecutive value RandomMatrice will be end
StartProcess(x,:,ii)=EndProcess(x,:,ii)-(ProcessTime(RandomMatriceA(x,:,ii))-1);%ThirdVariable:to know in which column The Consecutive Value will be start
for yy=1:B;
N=RandomMatriceA(x,yy,ii);
StartPost(x,N,ii)=StartProcess(x,yy,ii);
end
end
for h=2:2:A;
doneA=
Solution
My best guess given the information:
You are doing some expensive ismember operations. You can try to get rid of them by tracking Done in a different way.
Perhaps you can use a more efficent way to do it in the same location, or perhaps you need to move it inside the loop and do it in a very cheap way there.
You are doing some expensive ismember operations. You can try to get rid of them by tracking Done in a different way.
Perhaps you can use a more efficent way to do it in the same location, or perhaps you need to move it inside the loop and do it in a very cheap way there.
Context
StackExchange Code Review Q#15242, answer score: 2
Revisions (0)
No revisions yet.