|
This is the code, I guess the error means there is a problem with the less than or equal but I cant figure it out.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
% Get the text file given and extract data from it
% Create an array to store the Machine Total Times
% Replicate the Processing Time for each machine and add it % to the Setup Time
fgetmat;
MTT = cell(numMachines,1);
for idx = 1:numMachines
MTT{idx} = repmat(PT(:,idx)',[numJobs 1]) + ST{idx}
end
% Create a cell array for the MIN & POS and MAX & POS
% Create a cell array to store the Machine schedule
% Create a cell array to store the Machine time
minpos = cell(numMachines,1);
maxpos = cell(numMachines,1)
MSchJ = cell(numMachines,1);
MSchT = cell(numMachines,1);
eligibleIdxs = cell(numMachines,1);
% Initialize the values for %p and %r
p = 0.20;
r = 0.40;
% Finding the MIN & MAX value for starting time at machine
% Assumes that the starting time of each job is the diagonal
% "a" returns the value and "b" returns the column
for n = 1:numMachines;
M = MTT{n};
[a b] = min(diag(M));
minpos{n} = [a b];
[A B] = max(diag(M));
maxpos{n} = [A B];
end
% Change the array minpos & maxpos to a matrix to get out
% values easier
MINP = cell2mat(minpos);
MAXP = cell2mat(maxpos);
rand('state', sum(100*clock));
while min(MINP) ~= Inf;
if rand < p;
[a b] = min(MINP(:,1)); % Get the MIN time
MSchT{b} = [MSchT{b} a];
MSchJ{b} = [MSchJ{b} MINP(b,2)];
% Putting Inf at the diag for the selected machine
MTT{b} = inf_diag(MTT{b});
% Putting Inf at the columns for the job number
for c = 1:numMachines;
MTT{c}(:,MINP(b,2)) = Inf;
end
% Putting Inf at the rows for the job number except
% machine b
for d = [1:b-1 b+1:numMachines];
MTT{d}(MINP(b,2),:) = Inf;
end
% Finding the minimum starting values again
for n = 1:numMachines;
M = MTT{n};
[a b] = min(diag(M));
minpos{n} = [a b];
[A B] = max(diag(M));
maxpos{n} = [A B];
end
MINP = cell2mat(minpos);
MAXP = cell2mat(maxpos);
else
[a b] = min(MINP(:,1));
[A B] = max(MAXP(isfinite(MAXP(:,1)),1));
for m = 1:numMachines;
diags{m,1} = diag(MTT{m});
vmax = a + floor(r*(A-a));
eligibleEntry = (diags{m,1} <= vmax);
eligibleIdxs{m} = find(eligibleEntry(:));
end
selMach = floor(rand*numMachines+1);
selIdx = floor(rand*size(eligibleIdxs{selMach},1)+1);
idxVal = eligibleIdxs{selMach}(selIdx);
rndTim = diag(MTT{selMach}(idxVal,idxVal));
MSchT{selMach} = [MSchT{selMach} rndTim];
MSchJ{selMach} = [MSchJ{selMach} idxVal];
% Putting Inf at the diag for the selected machine
MTT{selMach} = inf_diag(MTT{selMach});
% Putting Inf at the columns for the job number
for c = 1:numMachines;
MTT{c}(:,idxVal) = Inf;
end
% Putting Inf at the rows for the job number except
% machine b
for d = [1:selMach-1 selMach+1:numMachines];
MTT{d}(idxVal,:) = Inf;
end
% Finding the minimum starting values again, now with one less job to
% select and then putting them together in one matrix
for n = 1:numMachines;
M = MTT{n};
[a b] = min(diag(M));
minpos{n} = [a b];
[A B] = max(diag(M));
maxpos{n} = [A B];
end
MINP = cell2mat(minpos);
MAXP = cell2mat(maxpos);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Thanks in advance!
|