资源描述:
《大连海事大学matlab平时作业范本4》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、43厂址选择问题maxz=75xI2+75x2i+50xI3+50x3I+1OOx23+1OOx32+150y】]+240y12+210y21+120y22+160y31+220y32s.t.3yn+3y12+x12+X】3X21一兀3i<203y21+3y221X[2+X21+X23—兀32—&<3y31+3y32一X13一X23+X9+X32W24yii+y2i+y3i=7人2+『22+『32=13y2i+y?255所有变量均不小于01.源代码:f=[07550750100501000150240021012001602200]•fA=[011-100-100330000
2、000;0-101010--10000330000;00-100-1110000000330;000000000000110000];b=[20;16;24;5];Aeq=[000000000100100100;000000000010010010];beq=[7;13];lb=zeros(18,1);[x,fval]=linprog(f,Azb,Aeq,beqzlb);2.程序运行:00.00000.00001.000000.00000.00000.000007.00000.00000.00000.00008.00000fval=3.4850e+0032.结杲分析:B地向A
3、地运送1万吨原料,ABC三地的建厂规模分别为7、5、8万吨。最小总费用3485万元4.4生产计划问题max7=4・X
4、+3・x?s.t.2x]+x2<10“Xj+x2<8x2<7xpx2>01.源代码:c=[-4-3];a=[21;1l;01];b=[1087];lb=zeros(2,1);[x,fval]=1inprog(c,a,b,[],[],lb);2.程序运行:2.00006.0000fval=-26.00003.结果分析:甲机床2台,乙机床6台,最大总利润2万6000元5.4背包问题一遗传算法1.源代码:1).主程序clearall;closeall;popsize
5、=50;chromlength=6;pm=0•5;a=[3,4,3,4,6,3];c=[12,12,9,16,30,12];b=12;pop=round(rand(popsize,chromlength));whilei<=200fit=fitness(pop,aAb,c);maxi=max(fit);[poplzpopnew]=selection(fit,pop);pop2=pmutation(popl,azb,pm);pop=pop2;i=i+lenddisp('最优解为:,);disp(popnew(1,:));disp(*物品总价值为:J;disp(maxi);2).
6、适应度子程序functionfit=fitness(pop,a,b,c);[pxzpy]=size(pop);total=zeros(pxz1);fit=zeros(pxA1);fori=l:pxforj=l:pytotal(i)=total(i)+pop(izj)*a(j);endiftotal(i)>bfit(i,1)=0;elseforj=l:pyfit(i)=fit(i)+pop(i,j)*c(j);endendend3).选择子程序function[popl,popnew]=selection(fit,pop);[pxzpy]=size(pop);[fitlznum
7、]=sort(fit,1descend1);fori=l:10popnew(i,:)=pop(num(i)A:);endpopl=[popnew;popnew];4).变异子程序function[popl,popnew]=selection(fit,pop);[pxzpy]=size(pop);[fitlznum]=sort(fit,1descend1);fori=l:10popnew(i,:)=pop(num(i)A:);endpopl=[popnew;popnew];1.程序运行:最优解为:100011物品总价值等于:545.5指派问题1.源代码:f=[335332521
8、51646410];aeq=[l111000000000000;0000111100000000;0000000011110000;0000000000001111;1000100010001000;0100010001000100;0010001000100010;0001000100010001];beq=[11111111];lb=zeros(16,1);[xffval]=bintprog(f,[]Azaeq,beqzlb);1.程序运行:x=0100000100101000fval=106.4基