声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 884|回复: 1

[综合讨论] 请问In an assignment A(I) = B,

[复制链接]
发表于 2010-5-7 11:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
小弟是初学者
刚开始使用MATLAB
不知该问题要怎样解决呢
"In an assignment  A(I) = B, the number of elements in B and I must be the same."
  1. clear all;close all;clc
  2. job_num = 20;  % 工件数目
  3. p_max = 100;  % p的最大值
  4. w_max = 20;   % w的最大值
  5. a = -0.45;    % 学习效应
  6. v_AccTemp=0;  % v使用电脑新的累增器数值
  7. w_AccTemp=0;  % w使用电脑新的累增器数值
  8. for y =1:3
  9.     series = randperm(p_max); % 产生一组序列介于1~p_max
  10.     p = series(1:job_num) % p =序列(第1笔到最末笔)
  11.     cnt = job_num;  % cnt计数器
  12.     for k =1:ceil(job_num/w_max)  %ceil:计算大于指定数的最小整数
  13.         series = randperm(w_max)  %产生一组序列介于1~w_max
  14.         if(cnt>w_max)  %工件数目大于w_max
  15.             w(1+(k-1)*w_max:k*w_max) = series;
  16.         else
  17.             w(1+(k-1)*w_max:job_num) = series(1:cnt);
  18.         end
  19.         cnt = cnt-w_max;
  20.     end
  21. end
  22. p
  23. w
  24. %p = p';
  25. %w = w';
  26. %p = [68 75 86 21 72];
  27. %w = [3 2 1 5 4];
  28. %p = [54 32 9 47];
  29. %w = [3 2 1 4];
  30. %----------------------------------WSPT------------------------------------
  31. wspt = p./w;
  32. [sorted_val,sort_ind] = sort(wspt);
  33. sum = 0;
  34. for i =1:job_num
  35.     for j = 1:i
  36.         tmp = 1;
  37.         for k = j+1:i
  38.             tmp = tmp*(1+(job_num-1)*k^a);
  39.         end
  40.         z(j)=j^a*tmp;
  41.         sum = sum +w(sort_ind(i))*p(sort_ind(j))*z(j);
  42.     end
  43. end
  44. wspt_result = sum
  45. %-----------------------------Optimal--------------------------------------
  46. n_1 = prod(1:job_num);
  47. row = n_1;
  48. col = job_num;
  49. allorder_K = zeros(1,job_num-1);
  50. period = n_1/1000;
  51. min_result = 100000000;
  52. total =0;
  53. cnt = 0;
  54. tic;
  55. for allorder_i=1:n_1;
  56.     allorder_flag=zeros(1,job_num);
  57.     allorder_P=zeros(1,job_num);
  58.     for allorder_j=1:job_num-1
  59.         position=job_num-allorder_K(allorder_i);
  60.         allorder_j=job_num;
  61.         while(allorder_j>=position)
  62.             if (allorder_flag(allorder_j)==1)
  63.                 position=position-1;
  64.             end
  65.             allorder_j=allorder_j-1;
  66.         end
  67.         allorder_P(position)=job_num+1-allorder_i;
  68.         allorder_flag(position)=1;
  69.     end
  70.     for allorder_i=1:job_num
  71.         if(allorder_flag(allorder_i)==0)
  72.             allorder_P(allorder_i);
  73.             break;
  74.         end
  75.     end
  76.     %--------以下更新K---------------
  77.      for allorder_i=1:job_num-1
  78.         allorder_K(job_num-allorder_i)=mod(allorder_K(job_num-allorder_i)+1,allorder_i+1);            
  79.         if (allorder_K(job_num-allorder_i)~=0)
  80.             break;
  81.         end
  82.      end
  83.     %---------------------------------------------------------------------
  84.     for m=1:row
  85.         sort_ind = allorder_P;
  86.         sum = 0;
  87.         for j =1:job_num
  88.             tmp = tmp*(1+(job_num-1)*k^a);
  89.         end
  90.         z(j) = j^a * tmp;
  91.         sum = sum+w(sort_ind(i))*p(sort_ind(j))*z(j);
  92.     end
  93.     result(cnt,1)=sum;  %记录每一次结果存成行向量
  94.     min_result = min(result)
  95.     if (sum > max_result)
  96.         max_result = sum;
  97.     end
  98.     if (sum < min_result)
  99.         min_result = sum;
  100.     end
  101.     total = total + sum;
  102. end
  103. if mod (cnt,period)==0
  104.     fprintf('第%09d迭代,花费:%f秒,进度:%f%% \n',cnt,toc,100*cnt/n_1);
  105.     drawnow;
  106.     tic;
  107. end
  108. %min_result = min(result)
  109. v_min = v_result / min_result
  110. v_total(y,1) = v_min
  111. for i = 1:length (v_min)
  112.     v_SumTemp=v_min(i);
  113.     v_Acctemp=v_AccTemp+v_SumTemp;
  114. end
  115. wspt_min = wspt_result/min_result
  116. for i =1:length(wspt_min)
  117.     w_SumTemp = wspt_min(i);
  118.     w_AccTemp = w_AccTemp+w_SumTemp;
  119. end
  120. w_total(y,1) = wspt_min
  121. %------------------------final_result-------------------------------------
  122. special_mean = v_AccTemp / 20
  123. special_min = min(v_total)
  124. special_max = max(v_total)
  125. special_op = 1/job_num^a
  126. general_mean = w_AccTemp / 20
  127. general_min = min(w_total)
  128. general__max = max(w_total)
  129. general_op = ((1+job_num-1)^job_num)/job_num^a
复制代码

[ 本帖最后由 ChaChing 于 2010-5-7 14:12 编辑 ]
回复
分享到:

使用道具 举报

发表于 2010-5-7 14:12 | 显示全部楼层
养成好习惯, 请动手搜一下!
常见的程序出错问题整理 (eight), 13F
http://forum.vibunion.com/forum/thread-46001-1-1.html
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-22 01:12 , Processed in 0.050810 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表