件的模型,用前面的方法,经常要花费大量的时间来输入代码或模型,下面介绍编程的方法,对于解决大型复杂的模型,效果显著。例2.1求解下面线性规划的数学模型;minz=-3x1+4x2-2x3+5x4;4x1-x2+2x3-x4=-2;x1+x2+3x3-x4≤14;-2x1+3x2-x3+2x4≥2;x1,x2,x3≥0,x4无约束;编程如下:!定义变量与常量,给出了值的为常量;sets:is/1..3/:b;js/1..4/:c,x;links(is,js):a;endsets!目标函数;min=@sum(js(J):c(J)*x(J));!约束条件;@sum(js(J):a(1,J)*x(J))=b(1);@sum(js(J):a(2,J)*x(J))<=b(2);@sum(js(J):a(3,J)*x(J))>=b(3);!自由变量;@free(x(4));!指定常量的值;data:c=-34-25;b=-2142;a=4-12-1113-1-23-12;enddata!结束;end求解可得解报告:Globaloptimalsolutionfound.Objectivevalue:2.000000Totalsolveriterations:2VariableValueReducedCostB(1)-2.0000000.000000B(2)14.000000.000000B(3)2.0000000.000000C(1)-3.0000000.000000C(2)4.0000000.000000C(3)-2.0000000.000000C(4)5.0000000.000000X(1)0.00000015.50000X(2)8.0000000.000000X(3)0.0000008.500000X(4)-6.0000000.000000A(1,1)4.0000000.000000