how to set / add another rules in random selection code

조회 수: 3 (최근 30일)
syamil syam
syamil syam 2012년 6월 20일
this is my code for random selection of nurse scheduling...
i have 7 columns (work of day) and M rows ..
how can I make the 44(off) is just one 44 in a week and before 44 must 33(night)?
row = get(handles.tblLoad,'Data');
[rs cs] = size(row);
dataName=row(1:rs);
set(handles.tblGenerate,'RowName',dataName);
m=str2double(get(handles.txtjumlah,'String'));
%call function from file randomwords.m to generate row by row randomly
% B = cell(m,7);
% B{m,7} = [];
% for i = 1:1
% for q = 1:m
% for j = 1:7
% B{q,j}=randomwords(10,1) %random mx7 dlm cell
% end
% end
% end
% x=cell2mat(B); % convert jadi matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function will randomly set a rules for soft constraint and save it in N
% case 1
% +----------------------+
% | Shift | Percent |
% |11(Morning)| 0.5 |
% |22(Evening)| 0.3 |
% |33(Night) | 0.175 |
% |44(off) | 0.025 |
% +----------------------+
% case 2
% +----------------------+
% | Shift | Percent |
% |11(Morning)| 0.45 |
% |22(Evening)| 0.33 |
% |33(Night) | 0.195 |
% |44(off) | 0.025 |
% +----------------------+
% case 3
% +----------------------+
% | Shift | Percent |
% |11(Morning)| 0.40 |
% |22(Evening)| 0.36 |
% |33(Night) | 0.215 |
% |44(off) | 0.025 |
% +----------------------+
AA = [m 7];
for i=1:7
%bil=round(rand(1,1)*2) %random number from 0-2
bil44=1;
switch bil
case 0
bil11=round(m*0.5)
bil22=round(m*0.3)
bil33=round(m*0.175)
bil44= round(m*0.025)
case 1
bil11=round(m*0.45)
bil22=round(m*0.33)
bil33=round(m*0.195)
bil44= round(m*0.025)
case 2
bil11=round(m*0.40)
bil22=floor(m*0.36)
bil33=round(m*0.215)
bil44= round(m*0.025)
end
if bil44==0
bil44=1;
end
N(:,i)=[bil11;bil22;bil33;bil44] % set of rules of soft constraint
end
% Data of shift is assign in mx7 cell and store in x
t=sum(N)~=AA(1);
if isnan(m)
msgbox('Total of nurse is not a valid number','Warning','error')
else
if any(t), I1 = randi(size(N,1)-1);
N(I1,:) = N(I1,:)-t;
end
x = zeros(AA);
xx = 11*(1:4)';
for j = 1:size(N,2)
x(randperm(AA(1)),j) = ...
cell2mat(arrayfun(@(i)xx(i)*ones(N(i,j),1),1:length(xx),'un',0).');
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by