数学规划模型实例一、lingo中的输入输出函数@text函数该函数被用在数据部分,用来将所需的数据输出至文本文件中。其语法为:@text(filename)这里filename是文件名,可以采用相对路径和绝对路径两种表示方式。如果忽略filename,那么数据就被输出到标准输出设备(大多数情形都是屏幕)。@text函数仅能出现在模型数据部分的一条语句的左边。@file函数该函数用从外部文件中输入数据,可以放在模型中任何地方。语法格式为@file(filename)这里filename是文件名,可以采用相对路径和绝对路径两种表示方式。执行一次@file输入1个记录,记录之间的分隔符为~。@table函数该函数以表格形式输出数据,只能在数据段(DATA)中使用。3例6.1(职员时序安排模型)一项工作一周7天都需要有人(比如护士工作),每天(周一至周日)所需的最少职员数为20、16、13、16、19、14和12,并要求每个职员一周连续工作5天,试求每周所需最少职员数,并给出安排。注意这里我们考虑稳定后的情况。决策变量:xi第周i天开始上班的人数;目标函数:71miniix4周一至周日所需的最少人数:20,16,13,16,19,14,12目标函数:71miniix2045671xxxxx1656712xxxxx1367123xxxxx1671234xxxxx1912345xxxxx1423456xxxxx1234567xxxxx..tsxi为整数jiijdxts51)7,2mod(..7,,2,1jsets:day/mon..sun/:x,d;endsets[obj]min=@sum(day:x);@for(day(j):@sum(day(i)|i#le#5:x(@wrap(j+i+2,7)))=d);@for(day:@gin(x));data:d=20,16,13,16,19,14,12;@text()=day'开始上班的人数为'x;Enddata,min71iix,jiijdxts511)7,1mod(..7,,2,1j目标函数:MON开始上班的人数为8.0000000TUE开始上班的人数为2.0000000WED开始上班的人数为0.0000000THU开始上班的人数为6.0000000FRI开始上班的人数为3.0000000SAT开始上班的人数为3.0000000SUN开始上班的人数为0.0000000二、线性规划模型特点:目标函数与约束条件均为一次的。线性规划的一般模型niiixcz1min..tsniiijxa1ib),(),,2,1(mjiiihxl),,2,1(ni(一)运输问题例6.2(运输规划模型)某产品有6个产地Ai和8个销售地Bj(i=1,2,…,6,j=1,2,…,8),产地到销地的单位运价见下表,问如何安排运输可使运输总费用最小。B1B2B3B4B5B6B7B8产量A16267425960A24953858255A35219743351A47673927143A52395726541A65522814352销量3537223241324338单位运价表:产地总产量和:302销地总销量和:280产大于销的模型。产地Ai:总产量ai销地Bi:总销量bi产地Ai到销地Bj:单位运价cij运输量xiji=1,2,…,6;j=1,2,…,8决策变量:产地Ai到销地Bj的运输量xij从产地Ai到销地Bj的运费cijxij从Ai到各销地的运费81jijijxc总运费6181ijijijxc目标函数:6811minijijijcx产地Ai:总产量ai销地Bi:总销量bi产地Ai到销地Bj:单位运价cij运输量xiji=1,2,…,6;j=1,2,…,8产地总产量和:302销地总销量和:280为产大于销的模型。目标函数:6811minijijijcx运往Bj的总运量:jiijbx61从Aj运出的总量:81ijijxa对变量xij的限制:0ijxi=1,2,…,6;j=1,2,…,8sets:chdi/w1..w6/:a;xdi/v1..v8/:b;link(chdi,xdi):c,x;endsets[obj]min=@sum(link:c*x);@for(xdi(j):@sum(chdi(i):x(i,j))=b(j));@for(chdi(i):@sum(xdi(j):x(i,j))=a(i));data:a=60,55,51,43,41,52;b=35,37,22,32,41,32,43,38;c=6,2,6,7,4,2,5,9,4,9,5,3,8,5,8,2,5,2,1,9,7,4,3,3,7,6,7,3,9,2,7,1,2,3,9,5,7,2,6,5,5,5,2,2,8,1,4,3;@text()=@table(x);enddata6811minijijijcxs.t:81ijijxajiijbx610ijxV1V2V3V4V5V6V7V8W10190041000W2100320000W30110000400W4000005038W5347000000W60022002730Objectivevalue:664.0000例2(转运问题)某产品有两个生产地,产量分别为9,8个单位,四个销售地需求量分别为3,5,4,5个单位,该产品从产地需经过中转站中的一个中转后,再运往21,AA4321,,,BBBB321,,CCC销售地,其中产地到中转站、中转站到销地的运费单价见表,试求总费用最小的运输方案。中转站产地销地A1A2B1B2B3B4C11357——C221967—C3—2—674第i个产地的产量,第j个销地的销量,iajbijc第i个产地到第j个中转站的运费单价,jkd第j个中转站到第k个销地的运费单价,决策变量:ijx第i个产地到第j个中转站的运量,jky第j个中转站到第k个销地的运量,目标函数:33241111minijijjkjkijjkzcxdy约束:(产地的运出量不大于生产量)31,1,2ijijxai(中转站的运入量等于运出量)24111,2,3ijjkikxyj目标函数:33241111minijijjkjkijjkzcxdy31,1,2ijijxai24111,2,3ijjkikxyj(销地的运入量等于需求量)411,2,3,4jkkjybk(产地的运出量不大于生产量)(中转站的运入量等于运出量),ijjkxy为非负整数sets:chdi/A1,A2/:a;zhon/C1,C2,C3/;xdi/B1..B4/:b;link1(chdi,zhon):c,x;link2(zhon,xdi):d,y;endsetsmin=@sum(link1:c*x)+@sum(link2:d*y);@for(chdi(i):@sum(zhon(j):x(i,j))=a(i));@for(zhon(j):@sum(chdi(i):x(i,j))=@sum(xdi(k):y(j,k)));@for(xdi(k):@sum(zhon(j):y(j,k))=b(k));33241111minijijjkjkijjkzcxdy31,1,2ijijxai24111,2,3ijjkikxyj411,2,3,4jkkjybk,ijjkxy为非负整数@for(link1:@gin(x));@for(link2:@gin(y));data:a=9,8;b=3,5,4,5;c=1,2,500,3,1,2;d=5,7,500,500,9,6,7,500,500,6,7,4;@text()=@table(x);@text()=@table(y);enddata33241111minijijjkjkijjkzcxdy31,1,2ijijxai24111,2,3ijjkikxyj411,2,3,4jkkjybk,ijjkxy为非负整数Objectivevalue:121.0000C1C2C3A1630A2035B1B2B3B4C13300C20240C30005(二)指派问题例6.3将九种不同型号的装备配给9个部队,由于各部队的特点与条件不同,不同的装备在不同部队中产生效能不同,问如何分配可保证每个部队各分得一种装备,且使总效能最大(装备在不同部队的效能见下表)。0.240.420.150.460.340.690.030.570.690.310.040.600.690.110.240.450.350.270.310.240.080.140.540.610.370.480.340.490.060.280.130.650.410.550.250.360.630.150.310.600.060.410.470.190.310.450.020.370.140.690.290.610.180.460.450.070.260.150.180.430.550.660.080.320.240.580.640.430.450.090.050.200.330.560.410.130.650.070.220.460.11123456789ABCDEFGHI装备部队设,0,1ijx第i个部队分配第j种装备目标函数:9191maxijijijxa:..ts191iijx191jijxxij=0或1(i,j=1,2,…,9)第i个部队不分配第j种装备9191maxijijijxa191iijx191jijxxij=0或1(i,j=1,2,…,9)sets:army/ar1..ar9/;equi/eq1..eq9/;link(army,equi):a,x;endsets[obj]max=@sum(link:a*x);@for(equi(i):@sum(army(j):x(i,j))=1);@for(army(j):@sum(equi(i):x(i,j))=1);@for(link:@bin(x));data:a=@file(F:\数学软件\lingoli\dali002.txt);@text(F:\数学软件\lingoli\li002.txt)=@table(x);enddataEQ1EQ2EQ3EQ4EQ5EQ6EQ7EQ8EQ9AR1000000001AR2000100000AR3000001000AR4000010000AR5100000000AR6000000100AR7000000010AR8001000000AR90100000000.240.420.150.460.340.690.030.570.690.310.040.600.690.110.240.450.350.270.310.240.080.140.540.610.370.480.340.490.060.280.130.650.410.550.250.360.630.150.310.600.060.410.470.190.310.450.020.370.140.690.290.610.180.460.450.070.260.150.180.430.550.660.080.320.240.580.640.430.450.090.050.200.330.560.410.130.650.070.220.460.11123456789ABCDEFGHI装备部队例4设有甲、乙、丙、丁四个人,各有能力去完成A,