error in running loop : the resultant is giving an empty array
1 view (last 30 days)
Show older comments
here is complete code.can anybody please check this
tic;
no_of_machines=7;
no_of_cells=3;
No_of_Parts = 6;
no_of_workers=4;
demand=[600 550 500 520 620 500];
M1=[1 0 0 0;0 0 1 0];% AVAILABLE workers FOR Machine 1
M2=[0 0 1 0;0 0 0 1];% AVAILABLE workers FOR Machine 2
M3=[0 1 0 0;0 0 0 1];% //
M4=[1 0 0 0;0 0 1 0];%//
M5=[0 1 0 0;0 0 0 1];%//
M6=[0 0 1 0;0 0 0 1];%//
M7=[0 1 0 0;0 0 0 1];
%operation times of parts
OP1=[10 0 0 10 0 20 15;10 13 0 0 12 0 15];
OP2=[0 10 10 15 0 0 20;11 0 13 0 17 10 0];
OP3=[10 0 0 12 11 0 0;0 11 18 0 0 0 17];
OP4=[10 0 0 0 19 0 14;0 14 0 17 0 10 0];
OP5=[18 13 0 0 0 15 0;10 12 0 0 10 0 11];
OP6=[0 10 0 0 0 10 15;12 11 0 13 0 15 0];
labor_cost=[2.5; 2.7; 3.5; 4];%salary of each labor
% GENERATING ALL POSSIBLE COMBINATIONS OF 12 ROUTES
OP = [OP1;OP2;OP3;OP4;OP5;OP6];
z = [size(OP1,1) size(OP2,1) size(OP3,1) size(OP4,1) size(OP5,1) size(OP6,1)];
c = [0 cumsum(z(1:end-1))];
a = allcomb(1:z(1),1:z(2),1:z(3),1:z(4),1:z(5),1:z(6));
n = size(a,1);
all_comb_of_OProutes = cell(1,n);
for i=1:n
all_comb_of_OProutes{i} = OP(c+a(i,:),:);
end
celltimes=@(all_comb_of_OProutes) sum(bsxfun(@times,all_comb_of_OProutes,demand'),1);
total_timereq_for_all_machines=cellfun(celltimes,all_comb_of_OProutes,'UniformOutput',false);
%//STEP 2:GENERATING ALL CELLS COMBINATIONS FOR MACHINES
CELL = zeros(no_of_cells^no_of_machines,no_of_machines);
t = 0;
for l = 0:(no_of_cells^no_of_machines)-1 %k=(2187-1=2186)
s = dec2base(l,no_of_cells,no_of_machines);
if length(unique(s))==no_of_cells
t = t+1;
CELL(t,:) = s-'0'+1;
end
end
CELL = CELL(1:t,:);
combination_array=num2cell(CELL,2);% all possible combinations
%//GENERATING MACHINE CELL MATRICES FROM ABOVE 1806 COMBINATIONS
[r1,c1]=size(combination_array);
for m=1:r1
R=1:numel(combination_array{m});
Z = zeros(R(end),max(combination_array{m}));
Z(sub2ind(size(Z),R,combination_array{m})) = 1;
allCells_array{m}=Z; % machine cell matrix array of all combinations
end
count=0;
for n=1:numel(allCells_array)
for i=1:numel(all_comb_of_OProutes)
Time_of_machine_inCells{n,i} = bsxfun(@times, allCells_array{n}, total_timereq_for_all_machines{i}');
end
end
% GENERATING ALL POSSIBLE COMBINATIONS workers and machines
M= [M1;M2;M3;M4;M5;M6;M7];
zz = [size(M1,1) size(M2,1) size(M3,1) size(M4,1) size(M5,1) size(M6,1) size(M7,1)];
cc = [0 cumsum(zz(1:end-1))];
aa = allcomb(1:zz(1),1:zz(2),1:zz(3),1:zz(4),1:zz(5),1:zz(6),1:zz(7));
nn = size(aa,1);
all_comb_of_workers = cell(1,nn);
for j=1:nn
all_comb_of_workers{j} = M(cc+aa(j,:),:);
end
count=0;
for k=numel(Time_of_machine_inCells)
for j=1:numel(all_comb_of_workers)
cell_worker= Time_of_machine_inCells{k}'*all_comb_of_workers{j};
count=count+1
total{k,j}=cell_worker;
end
end
toc;
problem is in the last loop of total{k,j}.when I run the code the counts should be 14794752 since k=115584 and j=128 but after running code the counts are only 128 and resultant is all 0x0 double in <115584x128>cell.. please some body copy paste this n check if their systems are also giving this ? a file used in this code is also given here
0 Comments
Accepted Answer
Geoff Hayes
on 20 Jan 2017
summyia - I think that the problem is with the line
for k=numel(Time_of_machine_inCells)
k is being initialized to a single value and so you are not iterating over anything. You probably want to use
for k=1:numel(Time_of_machine_inCells)
instead. Note that this will take a lot (!) longer to run. :)
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!