LINGO小练习——物流配送问题——混合整数规划模型MILP

LINGO小练习——物流配送问题——混合整数规划模型MILP_第1张图片
贴吧里看到的题,稍微做了一下,虽然建的是MILP模型,但奇怪的是电脑运了一宿还是Feasible状态得不出Gobal optimal的结果,开了两个版本的LINGO 11和17 算了23小时,结果一直是318不变,感觉最优解就是318,可能是某项约束太宽了或者维数太大了,整数线性模型LINGO都算的很慢,这也不算是严格的旅行商模型吧,我在模型里并没有加TSP约束,因为从题目中看不出来要求小车是每天都回到基地的,仅要求2个供应商满足6个市场的需求即可。有知道的可以评论告诉我下。
题目的意思我整理了下,供应商1和2每天制造固定的商品(Production),满足S1-S6每天对应的需求(Needs),剩余的商品可以遗留到下一天使用,最后对每天的路线进行规划配送(线路上的数字代表成本)最优配送成本(Cost)。
6天、8个地点(2个基地,6个市场)、2台小车依次进行物流配送;
设:
x n j k i 1 = { 1 0 小车 1 第 i 天第 n 次从 j 地去往 k 地 else x n j k i 2 = { 1 0 小车 2 第 i 天第 n 次从 j 地去往 k 地 else x_{njk}^{i1}=\left\{ \begin{array}{c} 1\\ 0\\ \end{array} \right. \begin{array}{c} \text{小车}1\text{第}i\text{天第}n\text{次从}j\text{地去往}k\text{地}\\ \text{else}\\ \end{array} \\ x_{njk}^{i2}=\left\{ \begin{array}{c} 1\\ 0\\ \end{array} \right. \begin{array}{c} \text{小车}2\text{第}i\text{天第}n\text{次从}j\text{地去往}k\text{地}\\ \text{else}\\ \end{array} xnjki1={10小车1i天第n次从j地去往kelsexnjki2={10小车2i天第n次从j地去往kelse
我们设P1为7地,P2为8地;每天小车1都从P1出发,小车2都从P2出发:
∑ k = 1 8 x 17 k i 1 = ∑ k = 1 8 x 18 k i 2 = 1 \sum_{k=1}^8{x_{17k}^{i1}}=\sum_{k=1}^8{x_{18k}^{i2}}=1 k=18x17ki1=k=18x18ki2=1
每次决策只有一个,只能走相邻,并且连续:
∑ k = 1 8 x n j k i 1 = ∑ k = 1 8 x n k j i + 11       ∑ k = 1 8 x n j k i 2 = ∑ k = 1 8 x n k j i + 12 x n j k i 1 + d i j ⩽ 2 x n j k i 2 + d i j ⩽ 2 d i j = { 1 2 相邻 不相邻 \sum_{k=1}^8{x_{njk}^{i1}}=\sum_{k=1}^8{x_{nkj}^{i+1 1}}\,\,\begin{matrix} & \\ \end{matrix}\,\,\sum_{k=1}^8{x_{njk}^{i2}}=\sum_{k=1}^8{x_{nkj}^{i+1 2}} \\ \begin{matrix} & \\ \end{matrix} \\ x_{njk}^{i1}+d_{ij}\leqslant 2\begin{matrix} & \\ \end{matrix}x_{njk}^{i2}+d_{ij}\leqslant 2\begin{matrix} & \\ \end{matrix}d_{ij}=\left\{ \begin{array}{c} 1\\ 2\\ \end{array} \right. \begin{array}{c} \text{相邻}\\ \text{不相邻}\\ \end{array} \\ k=18xnjki1=k=18xnkji+11k=18xnjki2=k=18xnkji+12xnjki1+dij2xnjki2+dij2dij={12相邻不相邻
设置两个0-1变量 z i j 1 z i j 2 \begin{matrix}z_{ij}^{1}&z_{ij}^{2}\end{matrix} zij1zij2表示小车 1 、 2 1、2 12是否到达第 i i i j j j地,和正整数变量 q i j 1 q i j 2 \begin{matrix}q_{ij}^{1}&q_{ij}^{2}\\\end{matrix} qij1qij2表示小车1/2第 i i i天对 j j j地的供给,满足需求约束:
q i j 1 ⩽ 100 z i j 1 q i j 2 ⩽ 100 z i j 2 q i j 1 + q i j 2 = N e e d s i j \\ \begin{matrix} q_{ij}^{1}\leqslant 100z_{ij}^{1}& q_{ij}^{2}\leqslant 100z_{ij}^{2}\\ \end{matrix} \\ \begin{matrix} & \\ \end{matrix} \\ q_{ij}^{1}+q_{ij}^{2}=Needs_{ij} qij1100zij1qij2100zij2qij1+qij2=Needsij
最后我们对剩余量(Residual)加到下一天的剩余量当中:
P r i 1 = P i 1 + r i 1 P r i 2 = P i 2 + r i 2    r i + 1 1 = P r i 1 − ∑ j = 1 8 q i j 1 r i + 1 2 = P r i 2 − ∑ j = 1 8 q i j 2 \begin{matrix} Pr_{i}^{1}=P_{i}^{1}+r_{i}^{1}& Pr_{i}^{2}=P_{i}^{2}+r_{i}^{2}\\ \end{matrix}\,\, \\ \begin{matrix} & \\ \end{matrix} \\ \begin{matrix} r_{i+1}^{1}=Pr_{i}^{1}-\sum_{j=1}^8{q_{ij}^{1}}& r_{i+1}^{2}=Pr_{i}^{2}-\sum_{j=1}^8{q_{ij}^{2}}\\ \end{matrix} \\ Pri1=Pi1+ri1Pri2=Pi2+ri2ri+11=Pri1j=18qij1ri+12=Pri2j=18qij2
最后总的最小化目标函数就是一周配送成本最小化:
min ⁡ = ∑ i = 1 6 ∑ n = 1 8 ∑ j = 1 8 ∑ k = 1 8 ∑ q = 1 2 c o s t i j x n j k i q \min =\sum_{i=1}^6{\sum_{n=1}^8{\sum_{j=1}^8{\sum_{k=1}^8{\sum_{q=1}^2{cost_{ij}x_{njk}^{iq}}}}}} min=i=16n=18j=18k=18q=12costijxnjkiq
将已知数据整理好就可以建立LINGO模型进行求解了。
LINGO小练习——物流配送问题——混合整数规划模型MILP_第2张图片
代码附在这里:

model:
sets:
a1/1…8/;
a2/1…6/:r1,r2,P1,P2,Pr1,Pr2,Pcost1,Pcost2;
a3(a2,a1,a1,a1):x,y;
a4(a2,a1,a1);
a5(a2,a1):q1,q2,z1,z2,Needs;
a6(a1,a1):d,cost;
a7(a1,a1,a1);
endsets
@for(a3(i,n,j,k):@bin(x(i,n,j,k)));
@for(a3(i,n,j,k):@bin(y(i,n,j,k)));!0-1constraint;
@for(a5(i,j):@bin(z1(i,j)));
@for(a5(i,j):@bin(z2(i,j)));
@for(a3(i,n,j,k):x(i,n,j,k)+d(j,k)<=2);
@for(a3(i,n,j,k):y(i,n,j,k)+d(j,k)<=2);!dist constraint;
@for(a4(i,n,k)|n#lt#8:@sum(a1(j):x(i,n+1,k,j)-x(i,n,j,k))=0);
@for(a4(i,n,k)|n#lt#8:@sum(a1(j):y(i,n+1,k,j)-y(i,n,j,k))=0);!continous constraint;
@for(a5(i,n):@sum(a6(j,k):x(i,n,j,k))=1);!decision only;
@for(a5(i,n):@sum(a6(j,k):y(i,n,j,k))=1);
@for(a5(i,j):z1(i,j)<=@sum(a6(n,k):x(i,n,k,j)));!reach if;
@for(a5(i,j):z2(i,j)<=@sum(a6(n,k):y(i,n,k,j)));
@for(a5(i,j):q1(i,j)<=64z1(i,j));!supply quantity;
@for(a5(i,j):q2(i,j)<=64
z2(i,j));!supply quantity;
@for(a5(i,j):@gin(q1(i,j)));
@for(a5(i,j):@gin(q2(i,j)));
@for(a2(i):P1(i)=Pr1(i)+r1(i));
@for(a2(i):P2(i)=Pr2(i)+r2(i));
@for(a2(i)|i#lt#6:r1(i+1)=P1(i)-@sum(a2(j):q1(i,j)));!residual calc;
@for(a2(i)|i#lt#6:r2(i+1)=P2(i)-@sum(a2(j):q2(i,j)));!residual calc;
r1(1)=0;
r2(1)=0;
@for(a5(i,j):q1(i,j)+q2(i,j)=Needs(i,j));
@for(a2(i):@sum(a1(j):x(i,1,7,j))=1);
@for(a2(i):@sum(a1(j):y(i,1,8,j))=1);
@for(a2(i):Pcost1(i)=@sum(a7(n,j,k):x(i,n,j,k)*cost(j,k)));
@for(a2(i):Pcost2(i)=@sum(a7(n,j,k):y(i,n,j,k)*cost(j,k)));
min=@sum(a2(i):Pcost1(i)+Pcost2(i));
data:
@text()=@writefor(a3(i,n,j,k)|x(i,n,j,k)#eq#1 :‘供应商1第’,i,‘天第’,n,‘次从’,j,‘地去往’,k,‘地’,@newline(1));
@text()=@writefor(a3(i,n,j,k)|y(i,n,j,k)#eq#1 :‘供应商2第’,i,‘天第’,n,‘次从’,j,‘地去往’,k,‘地’,@newline(1));
@text()=@writefor(a5(i,j)|z1(i,j)#eq#1:‘供应商1第’,i,‘天在’,j,‘地提供’,q1(i,j),‘物资’,@newline(1));
@text()=@writefor(a5(i,j)|z2(i,j)#eq#1:‘供应商2第’,i,‘天在’,j,‘地提供’,q2(i,j),‘物资’,@newline(1));
d=
1 1 1 2 2 2 1 2
1 1 2 1 2 2 1 1
1 2 1 1 2 1 2 2
2 1 1 1 2 1 2 1
2 2 2 2 1 1 2 1
2 2 1 1 1 1 2 2
1 1 2 2 2 2 1 2
2 1 2 1 1 2 2 1;
Needs=
50 40 38 23 34 22 0 0
60 44 38 23 34 23 0 0
59 43 45 19 32 34 0 0
64 44 38 23 34 23 0 0
34 43 45 29 32 34 0 0
50 23 28 23 34 22 0 0;
Pr1=200 232 234 235 190 180;
Pr2=59 56 55 67 78 45;
cost=
0 18 8 2 2 2 14 2
18 0 2 9 2 2 10 15
8 2 0 8 2 13 2 2
2 9 8 0 2 10 2 11
2 2 2 2 0 9 2 8
2 2 13 10 9 0 2 2
14 10 2 2 2 2 0 2
2 15 2 11 8 2 2 0;
enddata

你可能感兴趣的:(LINGO,动态规划,算法,数学建模,美国大学生数学建模竞赛,线性规划)