设学生i在星期j值班的时间为Xij (i=1..6,j=1..5),另设,如果Xij>0,Yij=1;否者,Yij=0 ,独立的变量Zij=1或0。
建立Lingo模型如下:
model:
!每天的时间约束;
x11+x31+x41+x51=14;
x22+x32+x42+x62=14;
x13+x33+x43+x53=14;
x24+x54=14;
x15+x35+x45+x65=14;
!每周的时间约束;
x11+x13+x15>8;
x22+x24>8;
x31+x32+x33+x35>8;
x41+x42+x43+x45>8;
x51+x53+x54>7;
x62+x65>7;
!0-1变量约束;
@bin(y11);@bin(y13);@bin(y15);
@bin(y22);@bin(y24);
@bin(y31);@bin(y32);@bin(y33);@bin(y35);
@bin(y41);@bin(y42);@bin(y43);@bin(y45);
@bin(y51);@bin(y53);@bin(y54);
@bin(y62);@bin(y65);
!每名学生每周值班不超过3次;
y11+y13+y15<3;
y22+y24<3;
y31+y32+y33+y35<3;
y41+y42+y43+y45<3;
y51+y53+y54<3;
y62+y65<3;
x11<100*y11;
x13<100*y13;
x15<100*y15;
x22<100*y22;
x24<100*y24;
x31<100*y31;
x32<100*y32;
x33<100*y33;
x35<100*y35;
x41<100*y41;
x42<100*y42;
x43<100*y43;
x45<100*y45;
x51<100*y51;
x53<100*y53;
x54<100*y54;
x62<100*y62;
x65<100*y65;
!每天值班的学生不超过3人,且至少一个研究生;
y11+y31+y41<2;
y22+y32+y42<2;
y13+y33+y43<2;
y24<2;
y15+y35+y45<2;
!0-1变量约束;
@bin(z11);@bin(z13);@bin(z15);
@bin(z22);@bin(z24);
@bin(z31);@bin(z32);@bin(z33);@bin(z35);
@bin(z41);@bin(z42);@bin(z43);@bin(z45);
@bin(z51);@bin(z53);@bin(z54);
@bin(z62);@bin(z65);
!每次值班不少于2小时;
x11<100*(1-z11);2-x11<100*z11;
x13<100*(1-z13);2-x13<100*z13;
x15<100*(1-z15);2-x15<100*z15;
x22<100*(1-z22);2-x22<100*z22;
x24<100*(1-z24);2-x24<100*z24;
x31<100*(1-z31);2-x31<100*z31;
x32<100*(1-z32);2-x32<100*z32;
x33<100*(1-z33);2-x33<100*z33;
x35<100*(1-z35);2-x35<100*z35;
x41<100*(1-z41);2-x41<100*z41;
x42<100*(1-z42);2-x42<100*z42;
x43<100*(1-z43);2-x43<100*z43;
x45<100*(1-z45);2-x45<100*z45;
x51<100*(1-z51);2-x51<100*z51;
x53<100*(1-z53);2-x53<100*z53;
x54<100*(1-z54);2-x54<100*z54;
x62<100*(1-z62);2-x62<100*z62;
x65<100*(1-z65);2-x65<100*z65;
!每个学生的时间约束;
x11<6;x13<6;x15<7;
x22<6;x24<6;
x31<4;x32<8;x33<3;x35<5;
x41<5;x42<5;x43<6;x45<4;
x51<3;x53<4;x54<8;
x62<6;x65<2;
!目标函数;
min=10*(x11+x13+x15)+10*(x22+x24)+9.9*(x31+x32+x33+x35)+9.8*(x41+x42+x43+x45)+10.8*(x51+x53+x54)+11.3*(x62+x65);
运行后得到:
Global optimal solution found.
Objective value: 716.1000
Extended solver steps: 0
Total solver iterations: 0
Variable Value Reduced Cost
X11 6.000000 0.000000
X31 0.000000 0.000000
X41 5.000000 0.000000
X51 3.000000 0.000000
X22 2.000000 0.000000
X32 7.000000 0.000000
X42 0.000000 0.000000
X62 5.000000 0.000000
X13 6.000000 0.000000
X33 0.000000 0.000000
X43 6.000000 0.000000
X53 2.000000 0.000000
X24 6.000000 0.000000
X54 8.000000 0.000000
X15 7.000000 0.000000
X35 5.000000 0.000000
X45 0.000000 0.000000
X65 2.000000 0.000000
Y11 1.000000 0.000000
Y13 1.000000 0.000000
Y15 1.000000 0.000000
Y22 1.000000 0.000000
Y24 1.000000 0.000000
Y31 0.000000 -90.00000
Y32 1.000000 0.000000
Y33 0.000000 -90.00000
Y35 1.000000 0.000000
Y41 1.000000 0.000000
Y42 0.000000 -10.00000
Y43 1.000000 0.000000
Y45 0.000000 -20.00000
Y51 1.000000 0.000000
Y53 1.000000 0.000000
Y54 1.000000 0.000000
Y62 1.000000 0.000000
Y65 1.000000 0.000000
Z11 0.000000 0.000000
Z13 0.000000 0.000000
Z15 0.000000 0.000000
Z22 0.000000 -10.00000
Z24 0.000000 0.000000
Z31 1.000000 0.000000
Z32 0.000000 0.000000
Z33 1.000000 0.000000
Z35 0.000000 0.000000
Z41 0.000000 0.000000
Z42 1.000000 0.000000
Z43 0.000000 0.000000
Z45 1.000000 0.000000
Z51 0.000000 0.000000
Z53 0.000000 0.000000
Z54 0.000000 0.000000
Z62 0.000000 0.000000
Z65 0.000000 0.000000
Row Slack or Surplus Dual Price
1 0.000000 -10.80000
2 0.000000 -9.900000
3 0.000000 -10.80000
4 0.000000 -10.80000
5 0.000000 -10.00000
6 11.00000 0.000000
7 0.000000 0.000000
8 4.000000 0.000000
9 3.000000 0.000000
10 6.000000 0.000000
11 0.000000 -1.400000
12 0.000000 0.000000
13 1.000000 0.000000
14 1.000000 0.000000
15 1.000000 0.000000
16 0.000000 0.000000
17 1.000000 0.000000
18 94.00000 0.000000
19 94.00000 0.000000
20 93.00000 0.000000
21 98.00000 0.000000
22 94.00000 0.000000
23 0.000000 0.9000000
24 93.00000 0.000000
25 0.000000 0.9000000
26 95.00000 0.000000
27 95.00000 0.000000
28 0.000000 0.1000000
29 94.00000 0.000000
30 0.000000 0.2000000
31 97.00000 0.000000
32 98.00000 0.000000
33 92.00000 0.000000
34 95.00000 0.000000
35 98.00000 0.000000
36 0.000000 0.000000
37 0.000000 0.000000
38 0.000000 0.000000
39 1.000000 0.000000
40 0.000000 0.000000
41 94.00000 0.000000
42 4.000000 0.000000
43 94.00000 0.000000
44 4.000000 0.000000
45 93.00000 0.000000
46 5.000000 0.000000
47 98.00000 0.000000
48 0.000000 0.1000000
49 94.00000 0.000000
50 4.000000 0.000000
51 0.000000 0.000000
52 98.00000 0.000000
53 93.00000 0.000000
54 5.000000 0.000000
55 0.000000 0.000000
56 98.00000 0.000000
57 95.00000 0.000000
58 3.000000 0.000000
59 95.00000 0.000000
60 3.000000 0.000000
61 0.000000 0.000000
62 98.00000 0.000000
63 94.00000 0.000000
64 4.000000 0.000000
65 0.000000 0.000000
66 98.00000 0.000000
67 97.00000 0.000000
68 1.000000 0.000000
69 98.00000 0.000000
70 0.000000 0.000000
71 92.00000 0.000000
72 6.000000 0.000000
73 95.00000 0.000000
74 3.000000 0.000000
75 98.00000 0.000000
76 0.000000 0.000000
77 0.000000 0.8000000
78 0.000000 0.8000000
79 0.000000 0.000000
80 4.000000 0.000000
81 0.000000 0.8000000
82 4.000000 0.000000
83 1.000000 0.000000
84 3.000000 0.000000
85 0.000000 0.1000000
86 0.000000 1.000000
87 5.000000 0.000000
88 0.000000 1.000000
89 4.000000 0.000000
90 0.000000 0.000000
91 2.000000 0.000000
92 0.000000 0.000000
93 1.000000 0.000000
94 0.000000 0.1000000
95 716.1000 -1.000000
故,最优值为716.1元,最优的时间值班时间安排为:
每天的值班时间表
学生 周一 周二 周三 周四 周五
1 6 0 6 0 7
2 0 2 0 6 0
3 0 7 0 0 5
4 5 0 6 0 0
5 3 0 2 8 0
6 0 5 0 0 2
为了便于你理解,模型没有使用LINGO的集设定方式来编程,以上程序一目了然,其中@bin()函数表示限定为0-1变量。
温馨提示:内容为网友见解,仅供参考