Lingo计算最优解
生活随笔
收集整理的這篇文章主要介紹了
Lingo计算最优解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
建模最后就是知道結果套過程。。
文章目錄
- 線性規劃
- 二次規劃
- 集合段
線性規劃
model: title 求解線性規劃; max=2*x1+3*x2; 2*x1+x2<8; 4*x1+3*x2<15; end結果:
Global optimal solution found.Objective value: 15.00000Infeasibilities: 0.000000Total solver iterations: 1Model Class: LPTotal variables: 2Nonlinear variables: 0Integer variables: 0Total constraints: 3Nonlinear constraints: 0Total nonzeros: 6Nonlinear nonzeros: 0Model Title: 求解線性規劃Variable Value Reduced CostX1 0.000000 2.000000X2 5.000000 0.000000Row Slack or Surplus Dual Price1 15.00000 1.0000002 3.000000 0.0000003 0.000000 1.000000當x1=0,x2=5時,2×x1+3×x22×x1+3×x22×x1+3×x2取最大值。
二次規劃
model: title 求解二次規劃; [opt]max=98*x1+277*x2-x1^2-0.3*x1*x2-2*x2^2; [st1]x1+x2<100; [st2]x1<2*x2; @gin(x1);@gin(x2); end Global optimal solution found.Objective value: 11077.50Objective bound: 11077.50Infeasibilities: 0.000000Extended solver steps: 4Total solver iterations: 583Model Class: PINLPTotal variables: 2Nonlinear variables: 2Integer variables: 2Total constraints: 3Nonlinear constraints: 1Total nonzeros: 6Nonlinear nonzeros: 2Model Title: 求解二次規劃Variable Value Reduced CostX1 35.00000 -8.500002X2 65.00000 -6.500004Row Slack or Surplus Dual PriceOPT 11077.50 1.000000ST1 0.000000 0.000000ST2 95.00000 0.000000下方state是全局最優解,如果是local則是局部最優,那么此時需要在options里面勾選Use Global Solver 。
集合段
50件商品供顧客選擇,商品i占用空間為wiw_iwi?,價值為viv_ivi?,車得容量為1000,怎么選擇價值最大?
1.一種物品只能選一件,選或不選,利用01標致變量,放進車的體積加起來。
maxf=∑i=150viximaxf=\sum_{i=1}^{50}v_{i}x_{i}maxf=i=1∑50?vi?xi?
∑i=150wixi≤1000\sum_{i=1}^{50}w_{i}x_{i}\leq1000i=1∑50?wi?xi?≤1000
xi=0or1x_{i}=0or1xi?=0or1
2.一種物品可以選多件。利用整數變量。
model: title 購物; sets: s/1..50/:w,v,x; endsets data: 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, 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; enddata max=@sum(s(i):v(i)*x(i)); @sum(s(i):w(i)*x(i))<1000; @for(s(i):@gin(x(i))); end Global optimal solution found.Objective value: 6320.000Objective bound: 6320.000Infeasibilities: 0.000000Extended solver steps: 0Total solver iterations: 0Model Class: PILPTotal variables: 50Nonlinear variables: 0Integer variables: 50Total constraints: 2Nonlinear constraints: 0Total nonzeros: 100Nonlinear nonzeros: 0Model Title: 購物Variable Value Reduced CostW( 1) 80.00000 0.000000W( 2) 82.00000 0.000000W( 3) 85.00000 0.000000W( 4) 70.00000 0.000000W( 5) 72.00000 0.000000W( 6) 70.00000 0.000000W( 7) 66.00000 0.000000W( 8) 50.00000 0.000000W( 9) 55.00000 0.000000W( 10) 25.00000 0.000000W( 11) 50.00000 0.000000W( 12) 55.00000 0.000000W( 13) 40.00000 0.000000W( 14) 48.00000 0.000000W( 15) 50.00000 0.000000W( 16) 32.00000 0.000000W( 17) 22.00000 0.000000W( 18) 60.00000 0.000000W( 19) 30.00000 0.000000W( 20) 32.00000 0.000000W( 21) 40.00000 0.000000W( 22) 38.00000 0.000000W( 23) 35.00000 0.000000W( 24) 32.00000 0.000000W( 25) 25.00000 0.000000W( 26) 28.00000 0.000000W( 27) 30.00000 0.000000W( 28) 22.00000 0.000000W( 29) 50.00000 0.000000W( 30) 30.00000 0.000000W( 31) 45.00000 0.000000W( 32) 30.00000 0.000000W( 33) 60.00000 0.000000W( 34) 50.00000 0.000000W( 35) 20.00000 0.000000W( 36) 65.00000 0.000000W( 37) 20.00000 0.000000W( 38) 25.00000 0.000000W( 39) 30.00000 0.000000W( 40) 10.00000 0.000000W( 41) 20.00000 0.000000W( 42) 25.00000 0.000000W( 43) 15.00000 0.000000W( 44) 10.00000 0.000000W( 45) 10.00000 0.000000W( 46) 10.00000 0.000000W( 47) 4.000000 0.000000W( 48) 4.000000 0.000000W( 49) 2.000000 0.000000W( 50) 1.000000 0.000000V( 1) 220.0000 0.000000V( 2) 208.0000 0.000000V( 3) 198.0000 0.000000V( 4) 192.0000 0.000000V( 5) 180.0000 0.000000V( 6) 180.0000 0.000000V( 7) 165.0000 0.000000V( 8) 162.0000 0.000000V( 9) 160.0000 0.000000V( 10) 158.0000 0.000000V( 11) 155.0000 0.000000V( 12) 130.0000 0.000000V( 13) 125.0000 0.000000V( 14) 122.0000 0.000000V( 15) 120.0000 0.000000V( 16) 118.0000 0.000000V( 17) 115.0000 0.000000V( 18) 110.0000 0.000000V( 19) 105.0000 0.000000V( 20) 101.0000 0.000000V( 21) 100.0000 0.000000V( 22) 100.0000 0.000000V( 23) 98.00000 0.000000V( 24) 96.00000 0.000000V( 25) 95.00000 0.000000V( 26) 90.00000 0.000000V( 27) 88.00000 0.000000V( 28) 82.00000 0.000000V( 29) 80.00000 0.000000V( 30) 77.00000 0.000000V( 31) 75.00000 0.000000V( 32) 73.00000 0.000000V( 33) 72.00000 0.000000V( 34) 70.00000 0.000000V( 35) 69.00000 0.000000V( 36) 66.00000 0.000000V( 37) 65.00000 0.000000V( 38) 63.00000 0.000000V( 39) 60.00000 0.000000V( 40) 58.00000 0.000000V( 41) 56.00000 0.000000V( 42) 50.00000 0.000000V( 43) 30.00000 0.000000V( 44) 20.00000 0.000000V( 45) 15.00000 0.000000V( 46) 10.00000 0.000000V( 47) 8.000000 0.000000V( 48) 5.000000 0.000000V( 49) 3.000000 0.000000V( 50) 1.000000 0.000000X( 1) 0.000000 -220.0000X( 2) 0.000000 -208.0000X( 3) 0.000000 -198.0000X( 4) 0.000000 -192.0000X( 5) 0.000000 -180.0000X( 6) 0.000000 -180.0000X( 7) 0.000000 -165.0000X( 8) 0.000000 -162.0000X( 9) 0.000000 -160.0000X( 10) 40.00000 -158.0000X( 11) 0.000000 -155.0000X( 12) 0.000000 -130.0000X( 13) 0.000000 -125.0000X( 14) 0.000000 -122.0000X( 15) 0.000000 -120.0000X( 16) 0.000000 -118.0000X( 17) 0.000000 -115.0000X( 18) 0.000000 -110.0000X( 19) 0.000000 -105.0000X( 20) 0.000000 -101.0000X( 21) 0.000000 -100.0000X( 22) 0.000000 -100.0000X( 23) 0.000000 -98.00000X( 24) 0.000000 -96.00000X( 25) 0.000000 -95.00000X( 26) 0.000000 -90.00000X( 27) 0.000000 -88.00000X( 28) 0.000000 -82.00000X( 29) 0.000000 -80.00000X( 30) 0.000000 -77.00000X( 31) 0.000000 -75.00000X( 32) 0.000000 -73.00000X( 33) 0.000000 -72.00000X( 34) 0.000000 -70.00000X( 35) 0.000000 -69.00000X( 36) 0.000000 -66.00000X( 37) 0.000000 -65.00000X( 38) 0.000000 -63.00000X( 39) 0.000000 -60.00000X( 40) 0.000000 -58.00000X( 41) 0.000000 -56.00000X( 42) 0.000000 -50.00000X( 43) 0.000000 -30.00000X( 44) 0.000000 -20.00000X( 45) 0.000000 -15.00000X( 46) 0.000000 -10.00000X( 47) 0.000000 -8.000000X( 48) 0.000000 -5.000000X( 49) 0.000000 -3.000000X( 50) 0.000000 -1.000000Row Slack or Surplus Dual Price1 6320.000 1.0000002 0.000000 0.000000總結
以上是生活随笔為你收集整理的Lingo计算最优解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab guide 打开图像并将图
- 下一篇: STM32-时钟-时钟树-时钟初始化配置