代码如下
sets:
W/1..7/: TL, D, MW, MA, MB, MC, MA1, MA2, MA3, MB1
, MB2, MC1, MC2, MC3,RW, RA, RB, RC, RA1, RA2, RA3, RB1
, RB2, RC1, RC2, RC3, P, S;
Cost/1..12/: Pcost, Scost;
U(W, Cost): X;
! 决策变量;
! U(W,C): M, R ;
endsets
data:
Pcost = 240 120 40 60 50 160 80 100 180 60 40 70;
Scost = 5 2 5 3 6 1.5 4 5 1.7 3 2 3;
D = 39 36 38 40 37 33 40;
TL = 4500 2500 2750 2100 2500 2750 1500;
enddata
min=@sum(W(i):S(i) + P(i));
! 每天要达到需求;
! 每天最多能组装的A B C组件数量;
MA(1) <= @smin(@floor((MA1(1))/6),
@floor((MA2(1)) / 8),
@floor((MA3(1)) / 2));
MB(1) <= @smin(@floor((MB1(1)) / 2),
@floor((MB2(1)) / 4));
MC(1) <= @smin(@floor((MC1(1)) / 8),
@floor((MC2(1)) / 2),
@floor((MC3(1)) / 12));
@for(W(i)| i #ge# 2:MA(i) <= @smin(@floor((MA1(i)+RA1(i-1))/6),
@floor((MA2(i)+RA2(i-1)) / 8),
@floor((MA3(i)+RA3(i-1)) / 2)));
@for(W(i)| i #ge# 2:MB(i) <= @smin(@floor((MB1(i)+RB1(i-1)) / 2),
@floor((MB2(i)+RB2(i-1)) / 4)));
@for(W(i)| i #ge# 2:MC(i) <= @smin(@floor((MC1(i)+RC1(i-1)) / 8),
@floor((MC2(i)+RC2(i-1)) / 2),
@floor((MC3(i)+RC3(i-1)) / 12)));
! 小组件的库存量;
RA1(1) = MA1(1) - 6 * MA(1);
RA2(1) = MA2(1) - 8 * MA(1);
RA3(1) = MA3(1) - 2 * MA(1);
RB1(1) = MB1(1) - 2 * MB(1);
RB2(1) = MB2(1) - 4 * MB(1);
RC1(1) = MC1(1) - 8 * MC(1);
RC2(1) = MC2(1) - 2 * MC(1);
RC3(1) = MC3(1) - 12 * MC(1);
@for(W(i)| i #ge# 2:RA1(i) = MA1(i) + RA1(i-1) - 6 * MA(i));
@for(W(i)| i #ge# 2:RA2(i) = MA2(i) + RA2(i-1) - 8 * MA(i));
@for(W(i)| i #ge# 2:RA3(i) = MA3(i) + RA3(i-1) - 2 * MA(i));
@for(W(i)| i #ge# 2:RB1(i) = MB1(i) + RB1(i-1) - 2 * MB(i));
@for(W(i)| i #ge# 2:RB2(i) = MB2(i) + RB2(i-1) - 4 * MB(i));
@for(W(i)| i #ge# 2:RC1(i) = MC1(i) + RC1(i-1) - 8 * MC(i));
@for(W(i)| i #ge# 2:RC2(i) = MC2(i) + RC2(i-1) - 2 * MC(i));
@for(W(i)| i #ge# 2:RC3(i) = MC3(i) + RC3(i-1) - 12 * MC(i));
! 大组件组装机器人;
@for(W(i)| i #ge# 2:MW(i) <= @smin(@floor((MA(i)+RA(i-1)) / 3),
@floor((MB(i)+RB(i-1)) / 4),
@floor((MC(i)+RC(i-1)) / 5)));
MW(1) <= @smin(@floor((MA(1)) / 3),
@floor((MB(1)) / 4),
@floor((MC(1)) / 5));
! 大组件的库存量;
RA(1) = MA(1) - 3 * MW(1);
RB(1) = MB(1) - 4 * MW(1);
RC(1) = MC(1) - 5 * MW(1);
@for(W(i)| i #ge# 2:RA(i) = MA(i) + RA(i-1) - 3 * MW(i));
@for(W(i)| i #ge# 2:RB(i) = MB(i) + RB(i-1) - 4 * MW(i));
@for(W(i)| i #ge# 2:RC(i) = MC(i) + RC(i-1) - 5 * MW(i));
! 机器人的库存数量;
@for(W(i)| i #ge# 2:RW(i) = MW(i) + RW(i-1) - D(i));
RW(1) = MW(1) - D(1);
! 工时的约束;
@for(W(i):3*MA(i) + 5*MB(i) + 5*MC(i) <= TL(i));
! 没有库存的约束;
RW(7) = 0;
RA(7) = 0;
RB(7) = 0;
RC(7) = 0;
RA1(7) = 0;
RA2(7) = 0;
RA3(7) = 0;
RB1(7) = 0;
RB2(7) = 0;
RC1(7) = 0;
RC2(7) = 0;
RC3(7) = 0;
@for(W(i):S(i) = Scost(1) * RW(i) +
Scost(2) * RA(i) + Scost(3) * RA1(i) +
Scost(4) * RA2(i) + Scost(5) * RA3(i) +
Scost(6) * RB(i) + Scost(7) * RB1(i) +
Scost(8) * RB2(i) + Scost(9) * RC(i) +
Scost(10) * RC1(i) + Scost(11) * RC2(i) +
Scost(12) * RC3(i));
@for(W(i):P(i) = @sum(Cost(j):Pcost(j) * X(i, j)));
@for(W(i):@for(Cost(j):@bin(X(i,j))));
@for(W(i):X(i,1) = @if(MW(i) #gt# 0, 1, 0));
@for(W(i):X(i,2) = @if(MA(i) #gt# 0, 1, 0));
@for(W(i):X(i,3) = @if(MA1(i) #gt# 0, 1, 0));
@for(W(i):X(i,4) = @if(MA2(i) #gt# 0, 1, 0));
@for(W(i):X(i,5) = @if(MA3(i) #gt# 0, 1, 0));
@for(W(i):X(i,6) = @if(MB(i) #gt# 0, 1, 0));
@for(W(i):X(i,7) = @if(MB1(i) #gt# 0, 1, 0));
@for(W(i):X(i,8) = @if(MB2(i) #gt# 0, 1, 0));
@for(W(i):X(i,9) = @if(MC(i) #gt# 0, 1, 0));
@for(W(i):X(i,10) = @if(MC1(i) #gt# 0, 1, 0));
@for(W(i):X(i,11) = @if(MC2(i) #gt# 0, 1, 0));
@for(W(i):X(i,12) = @if(MC3(i) #gt# 0, 1, 0));
后面几题的代码等我写出来了会再更新
感谢收看