用yalmip解非线性混合整数规划的时候为什么结果都是NaN

2024-11-24 11:37:43
推荐回答(1个)
回答1:

MATLAB求解线性的整数规划可以用分支定界法,但实现起来还是比较困难。可以去下载一个叫YALMIP的工具箱,用他可以解决线性规划,非线性规划,整数规划,混合规划,强烈推荐把这个工具整合到matlab中去,这个工具是私人的,不过可以免费下载使用。不过最好的方法是用LINGO求解。有了YALMIP工具箱,输入也变的相对简单,代码如下:x=intvar(2,7);f=[0.487,0.520,0.613,0.720,0.487,0.520,0.640;0.487,0.520,0.613,0.720,0.487,0.520,0.640]*x';F=set(x>=0);F=F+set(x(1,1)+x(2,1)<=8)+set(x(1,2)+x(2,2)<=7)+set(x(1,3)+x(2,3)<=9)+set(x(1,4)+x(2,4)]<=6)+set(x(1,5)+x(2,5)<=6)+set(x(1,6)+x(2,6)<=4);F=F+set([2,3,1,0.5,4,2,7;2,3,1,0.5,4,2,7]*.x'<=[40;40])+set([0.487,0.52,0.613,0.72,0.487,0.52,0.64;0.487,0.52,0.613,0.72,0.487,0.52,0.64].*x'<=[10.2;10.2])+set([0,0,0,0,0.487,0.52,0.64;0,0,0,0,0.487,0.52,0.64].*x'<=[3.027;3.027]);solvesdp(F,-f)下面用lingo求解:model:max=0.487*x11+0.52*x12+0.613*x13+0.72*x14+0.487*x15+0.52*x16+0.64*x17+0.487*x21+0.52*x22+0.613*x23+0.72*x24+0.487*x25+0.52*x26+0.64*x27;x11+x21<=8;x12+x22<=7;x13+x23<=9;x14+x24<=6;x15+x25<=6;x16+x26<=4;2*x11+3*x12+x13+0.5*x14+4*x15+2*x16+x17<=40;2*x21+3*x22+x23+0.5*x24+4*x25+2*x26+x27<=40;0.487*x11+0.52*x12+0.613*x13+0.72*x14+0.487*x15+0.52*x16+0.64*x27<=10.2;0.487*x21+0.52*x22+0.613*x23+0.72*x24+0.487*x25+0.52*x26+0.64*x17<=10.2;0.487*x15+0.52*x16+0.64*x17<=3.027;0.487*x25+0.52*x26+0.64*x27<=3.027;@gin(x11);@gin(x12);@gin(x13);@gin(x14);@gin(x15);@gin(x16);@gin(x17);@gin(x21);@gin(x22);@gin(x23);@gin(x24);@gin(x25);@gin(x26);@gin(x27);end运行结果:(由于字数超限,运行结果已删除)