《matlab求贪婪算法装箱问题的练习.doc》由会员分享,可在线阅读,更多相关《matlab求贪婪算法装箱问题的练习.doc(2页珍藏版)》请在三一办公上搜索。
1、利用matlab编程FFD算法完成装箱问题:设有6种物品,它们的体积分别为:60、45、35、20、20和20单位体积,箱子的容积为100个单位体积。建立box_main.mfunctionbox_count,b=box_main(v)vmax=100;sort(v,descend);n=length(v);b=zeros(1,n);for i=1:n b(i)=vmax;endbox_count=1;for i=1:n for j=1:box_count if v(i)=x(i,2) car=car-x(i,2); item_count=item_count+1; else break; e
2、ndendy=zeros(item_count,2);for i=1:item_count y(i,1)=x(i,1); y(i,2)=x(i,2);end end主程序为:v= 220, 208, 198, 192, 180, 180, 165, 162, 160, 158,155, 130, 125, 122, 120, 118, 115, 110, 105, 101, 100, 100, 98,96, 95, 90, 88, 82, 80, 77, 75, 73, 72, 70, 69, 66, 65, 63, 60, 58,56, 50, 30, 20, 15, 10, 8, 5, 3
3、, 1;w= 80, 82, 85, 70, 72, 70, 66, 50, 55, 25, 50, 55, 40, 48,50, 32, 22, 60, 30, 32, 40, 38, 35, 32, 25, 28, 30, 22, 50, 30, 45,30, 60, 50, 20, 65, 20, 25, 30, 10, 20, 25, 15, 10, 10, 10, 4, 4, 2,1;car=1000;item_count,y=chaoshi(v,w,car);y;结果为:ans = Columns 1 through 11 158 58 115 95 82 118 105 69 65 162 90 25 10 22 25 22 32 30 20 20 50 28 Columns 12 through 22 101 125 155 96 88 160 98 56 220 192 100 32 40 50 32 30 55 35 20 80 70 38 Columns 23 through 26 180 77 122 20870 30 48 82最大总价值为3095元,可装入体积为996