加油了哦
略解:
一根钢材共有以下19种切割的方案,如下:
1.5 余5.8,设有x1根钢材按此法切割
2.1 余5.2,设有x2根钢材按此法切割
2.9 余4.4,设有x3根钢材按此法切割
1.5+1.5=3 余4.3,设有x4根钢材按此法切割
1.5+2.1=3.6 余3.7,设有x5根钢材按此法切割
2.1+2.1=4.2 余3.1,设有x6根钢材按此法切割
1.5+2.9=4.4 余2.9,设有x7根钢材按此法切割
2.1+2.9=5 余2.3,设有x8根钢材按此法切割
2.9+2.9=5.8 余1.5,设有x9根钢材按此法切割
1.5+1.5+2.1=5.1 余2.2,设有x10根钢材按此法切割
1.5+1.5+2.9=5.9 余1.4,设有x11根钢材按此法切割
1.5+2.1+2.1=5.7 余1.6,设有x12根钢材按此法切割
1.5+2.1+2.9=6.5 余0.8,设有x13根钢材按此法切割
1.5+2.9+2.9=7.3 余0,设有x14根钢材按此法切割
2.1+2.1+2.1=6.3 余1,设有x15根钢材按此法切割
2.1+2.1+2.9=7.1 余0.2,设有x16根钢材按此法切割
1.5+1.5+1.5+1.5=6 余1.3,设有x17根钢材按此法切割
1.5+1.5+1.5+2.1=6.6余0.7,设有x18根钢材按此法切割
1.5+1.5+2.1+2.1=7.2余0.1,设有x19根钢材按此法切割
不等式约束条件是
x1,x2,...,x19>=0
等式约束条件是:
x1+2*x4+x5+x7+2*x10+2*x11+x12+x13+x14+4*x17+3*x18+2*x19=100
x2+x5+x6+x8+x10+x11+2*x12+x13+3*x15+2*x16+x18+2*x19=100
x3+x7+x8+2*x9+x11+x13+2*x14+x16=100
在以上约束条件下,求函数f的最小值:
f=5.8*x1+5.2*x2+4.4*x3+4.3*x4+3.7*x5+3.1*x6+2.9*x7+2.3*x8+1.5*x9+2.2*x10+1.4*x11+1.6*x12+0.8*x13+0*x14+1*x15+0.2*x16+1.3*x17+
0.7*x18+0.1*x19
运算结果:
x14=40 (1.5+2.9+2.9=7.3 余0,设有x14根钢材按此法切割)
x16=20 (2.1+2.1+2.9=7.1 余0.2,设有x16根钢材按此法切割)
x19=30 (1.5+1.5+2.1+2.1=7.2余0.1,设有x19根钢材按此法切割)
其余皆为零。
余料:
fval=7
检验:
1.5m的钢材:40+2*30=100
2.1m的钢材:40*2+20=100
2.9m的钢材:30*2+20*2=100
余料=20×0.2+30*0.1=4+3=7
一共需要7.3m的钢材x14+x16+x19=40+20+30=90(根)
分割方法,显而易见。
matlab程序如下:
function f=myfun(x);
f=5.8*x(1)+5.2*x(2)+4.4*x(3)+4.3*x(4)+3.7*x(5)+3.1*x(6)+2.9*x(7)+2.3*x(8)+1.5*x(9)+2.2*x(10)+1.4*x(11)+1.6*x(12)+0.8*x(13)
+0*x(14)+1*x(15)+0.2*x(16)+1.3*x(17)+0.7*x(18)+0.1*x(19);
在命令窗口中输入:
>>x0=0.1*[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
>>A=-1*eye(19);
>>b=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
>>Aeq=[
1 0 0 2 1 0 1 0 0 2 2 1 1 1 0 0 4 3 2
0 1 0 0 1 1 0 1 0 1 1 2 1 0 3 2 0 1 2
0 0 1 0 0 0 1 1 2 0 1 0 1 2 0 1 0 0 0];
>>beq=[100,100,100];
>>[x,fval]=fmincon(@myfun,x0,A,b,Aeq,beq);
执行结果如下:
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In C:\matlab\toolbox\optim\fmincon.m at line 213
Optimization terminated successfully:
First-order optimality measure less than options.TolFun and
maximum constraint violation is less than options.TolCon
Active Constraints:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
18
20
21
x=
Columns 1 through 11
-0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0000
Columns 12 through 19
-0.0000 -0.0000 40.0000 -0.0000 20.0000 -0.0000 -0.0000 30.0000
fval=
7.0000
[此帖子已被 qxfy 在 2003-7-14 19:57:18 编辑过] |