资源描述
LINGO 求解常见数学规划问题通用程序ma=ex1求解线性规划model: sets: row/1.m/:b;arange/1.n/:x,c; link(row, arange):a; endsets data:b=b(l),b(2),b(m);c=c(l),c(2),c(n);a_a(l,l),a(l,2),a(2,1),a(2,2),卫(l,n),a(2,n),a(m,l),a(m,2),enddata,a(m,n);max=sum(arange(j):c(j)*x(j);for(row(i):sum(arange(j):a(i,j)*x(j)=0);end2.求解运输问题Sets:row/1.m/:a;!产地的个数arrange/1.n/:b;!销地的个数link(row,arrange):c,x;endsetsdata:b=b(l),b(2),b(n);a=a(1),a(2),a(m);c=c(l,l),c(l,2),c(1,n),c(2,1),c(2,2),c(2,n),c(m,1),c(m,2),c(m,n);enddatamin=sum(link(i,j):c(i,j)*x(i,j);for(row(i):sum(arrange(j):x(i,j)=a(i);for(arrange(j):sum(row(i):x(i,j)=b(j);for(link:x=0);end3.整数规划求解(1).一般整数规划问题Sets:num_i/1.m/:b;!m 表示数组的维数num_j/1.n/:x,c; !n 表示数组的维数 link(num_i,num_j):a;endsetsdata:b=b(l),b(2),b(m); !约束条件右端项系数 c=c(l),c(2),c(n);!目标函数系数a=a(1,1),a(1,2),a(1,n),a(2,1),a(2,2),a(2,n),a(m,l),a(m,2),a(m,n);!约束条件系数矩阵enddata max=sum(num_j(j):c(j)*x(j);for(num_i(i):sum(num_j(j):a(i,j)*x(j)=0);for(num_j(j):gin(x(j);end(2) 一般 0l 规划问题Model:Sets:num_i/l.m/:b;num_j/1.n/:x,c;link(num_i, num_j):a;endsetsdata:b=b(l),b(2),b(m); !约束条件右端项系数c=c(l),c(2),c(n);!目标函数系数a=a(1,1),a(1,2),a(1,n),a(2,1),a(2,2),a(2,n),enddata max=sum(num_j(j):c(j)*x(j); for(num_i(i):sum(num_j(j):a(i,j)*x(j)0 0 = 1,2,Z)jModel:Sets:Num_i/l.m/; Num_j/l.l/;Num_k/l.n/:xO,x;Endsetsmit:xO=xO(l), x0(2),xO(n);endinitmin=f(x); for(num_i(i):hi(x)= =0); for(num_j (j):gj(x)=0); for(num_k(k): x(k)=0); End (2)二次规划模型!赋初值以缩小|最优解的寻找范围minf (x)=Zx + 另另c x xjk j kj=1另 a x+ bA 0 ij jij=1xA0,c=cjjk kjj=1 k =1(i = 1,2,m )g, k=i, 2,nModel:Sets:Num_i/1.m/:b;Num_j/1.n/:c,x;Num_k/1.n/:;Link_ij(num_i,num_j):a;Link_jk(num_j,num_k):c1;EndsetsData:c=c(1),c(2),c(n);b=b,b(2),b(m);a_a(l,l), a(l,2),a(2,1), a(2,2), ,a(1,n),a(2,n).a(m,1), a(m,2),a(m,n),enddatainit:,x0(n);x0=x0(1),x0(2), endinit min=sum(num_j(j):c(j)*x(j)+sum(link_jk(j,k):c(j, k)*x(j)*x(k);for(num_i(i):sum(num_j(j):a(i,j)*x(j)+b(i)=0; for(num_j(j):x(j)=0);end
展开阅读全文