马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
小弟是初学者
刚开始使用MATLAB
不知该问题要怎样解决呢
"In an assignment A(I) = B, the number of elements in B and I must be the same."- clear all;close all;clc
- job_num = 20; % 工件数目
- p_max = 100; % p的最大值
- w_max = 20; % w的最大值
- a = -0.45; % 学习效应
- v_AccTemp=0; % v使用电脑新的累增器数值
- w_AccTemp=0; % w使用电脑新的累增器数值
- for y =1:3
- series = randperm(p_max); % 产生一组序列介于1~p_max
- p = series(1:job_num) % p =序列(第1笔到最末笔)
- cnt = job_num; % cnt计数器
- for k =1:ceil(job_num/w_max) %ceil:计算大于指定数的最小整数
- series = randperm(w_max) %产生一组序列介于1~w_max
- if(cnt>w_max) %工件数目大于w_max
- w(1+(k-1)*w_max:k*w_max) = series;
- else
- w(1+(k-1)*w_max:job_num) = series(1:cnt);
- end
- cnt = cnt-w_max;
- end
- end
- p
- w
- %p = p';
- %w = w';
- %p = [68 75 86 21 72];
- %w = [3 2 1 5 4];
- %p = [54 32 9 47];
- %w = [3 2 1 4];
- %----------------------------------WSPT------------------------------------
- wspt = p./w;
- [sorted_val,sort_ind] = sort(wspt);
- sum = 0;
- for i =1:job_num
- for j = 1:i
- tmp = 1;
- for k = j+1:i
- tmp = tmp*(1+(job_num-1)*k^a);
- end
- z(j)=j^a*tmp;
- sum = sum +w(sort_ind(i))*p(sort_ind(j))*z(j);
- end
- end
- wspt_result = sum
- %-----------------------------Optimal--------------------------------------
- n_1 = prod(1:job_num);
- row = n_1;
- col = job_num;
- allorder_K = zeros(1,job_num-1);
- period = n_1/1000;
- min_result = 100000000;
- total =0;
- cnt = 0;
- tic;
- for allorder_i=1:n_1;
- allorder_flag=zeros(1,job_num);
- allorder_P=zeros(1,job_num);
- for allorder_j=1:job_num-1
- position=job_num-allorder_K(allorder_i);
- allorder_j=job_num;
- while(allorder_j>=position)
- if (allorder_flag(allorder_j)==1)
- position=position-1;
- end
- allorder_j=allorder_j-1;
- end
- allorder_P(position)=job_num+1-allorder_i;
- allorder_flag(position)=1;
- end
- for allorder_i=1:job_num
- if(allorder_flag(allorder_i)==0)
- allorder_P(allorder_i);
- break;
- end
- end
- %--------以下更新K---------------
- for allorder_i=1:job_num-1
- allorder_K(job_num-allorder_i)=mod(allorder_K(job_num-allorder_i)+1,allorder_i+1);
- if (allorder_K(job_num-allorder_i)~=0)
- break;
- end
- end
- %---------------------------------------------------------------------
- for m=1:row
- sort_ind = allorder_P;
- sum = 0;
- for j =1:job_num
- tmp = tmp*(1+(job_num-1)*k^a);
- end
- z(j) = j^a * tmp;
- sum = sum+w(sort_ind(i))*p(sort_ind(j))*z(j);
- end
- result(cnt,1)=sum; %记录每一次结果存成行向量
- min_result = min(result)
- if (sum > max_result)
- max_result = sum;
- end
- if (sum < min_result)
- min_result = sum;
- end
- total = total + sum;
- end
- if mod (cnt,period)==0
- fprintf('第%09d迭代,花费:%f秒,进度:%f%% \n',cnt,toc,100*cnt/n_1);
- drawnow;
- tic;
- end
- %min_result = min(result)
- v_min = v_result / min_result
- v_total(y,1) = v_min
- for i = 1:length (v_min)
- v_SumTemp=v_min(i);
- v_Acctemp=v_AccTemp+v_SumTemp;
- end
- wspt_min = wspt_result/min_result
- for i =1:length(wspt_min)
- w_SumTemp = wspt_min(i);
- w_AccTemp = w_AccTemp+w_SumTemp;
- end
- w_total(y,1) = wspt_min
- %------------------------final_result-------------------------------------
- special_mean = v_AccTemp / 20
- special_min = min(v_total)
- special_max = max(v_total)
- special_op = 1/job_num^a
- general_mean = w_AccTemp / 20
- general_min = min(w_total)
- general__max = max(w_total)
- general_op = ((1+job_num-1)^job_num)/job_num^a
复制代码
[ 本帖最后由 ChaChing 于 2010-5-7 14:12 编辑 ] |