第1个回答 推荐于2021-01-19
代码如下:
model:
sets:
std/1..6/:c;
day/1..5/;
time(std,day):maxt,t;!t代表每个学生各天实际值班的时间,并且t<=maxt;
endsets
data:
c=10 10 9.9 9.8 10.8 11.3;
maxt=6 0 6 0 7
0 6 0 6 0
4 8 3 0 5
5 5 6 0 4
3 0 4 8 0
0 6 0 0 3;
enddata
min=@sum(std(i):c(i)*(@sum(day(j):t(i,j))));
@for(day(j):@sum(std(i):t(i,j))=14);!上午8点至晚10点共14个钟头;
@for(time:t<=maxt);
@for(std(i)|i#LE#4:@sum(day(j):t(i,j))>=8);
@for(std(i)|i#GT#4:@sum(day(j):t(i,j))>=7);
end
运行结果:
Global optimal solution found at iteration: 0
Objective value: 710.0000
Variable Value Reduced Cost
C( 1) 10.00000 0.000000
C( 2) 10.00000 0.000000
C( 3) 9.900000 0.000000
C( 4) 9.800000 0.000000
C( 5) 10.80000 0.000000
C( 6) 11.30000 0.000000
MAXT( 1, 1) 6.000000 0.000000
MAXT( 1, 2) 0.000000 0.000000
MAXT( 1, 3) 6.000000 0.000000
MAXT( 1, 4) 0.000000 0.000000
MAXT( 1, 5) 7.000000 0.000000
MAXT( 2, 1) 0.000000 0.000000
MAXT( 2, 2) 6.000000 0.000000
MAXT( 2, 3) 0.000000 0.000000
MAXT( 2, 4) 6.000000 0.000000
MAXT( 2, 5) 0.000000 0.000000
MAXT( 3, 1) 4.000000 0.000000
MAXT( 3, 2) 8.000000 0.000000
MAXT( 3, 3) 3.000000 0.000000
MAXT( 3, 4) 0.000000 0.000000
MAXT( 3, 5) 5.000000 0.000000
MAXT( 4, 1) 5.000000 0.000000
MAXT( 4, 2) 5.000000 0.000000
MAXT( 4, 3) 6.000000 0.000000
MAXT( 4, 4) 0.000000 0.000000
MAXT( 4, 5) 4.000000 0.000000
MAXT( 5, 1) 3.000000 0.000000
MAXT( 5, 2) 0.000000 0.000000
MAXT( 5, 3) 4.000000 0.000000
MAXT( 5, 4) 8.000000 0.000000
MAXT( 5, 5) 0.000000 0.000000
MAXT( 6, 1) 0.000000 0.000000
MAXT( 6, 2) 6.000000 0.000000
MAXT( 6, 3) 0.000000 0.000000
MAXT( 6, 4) 0.000000 0.000000
MAXT( 6, 5) 3.000000 0.000000
T( 1, 1) 5.000000 0.000000
T( 1, 2) 0.000000 0.1000000
T( 1, 3) 5.000000 0.000000
T( 1, 4) 0.000000 0.000000
T( 1, 5) 2.000000 0.000000
T( 2, 1) 0.000000 0.000000
T( 2, 2) 2.000000 0.000000
T( 2, 3) 0.000000 0.000000
T( 2, 4) 6.000000 0.000000
T( 2, 5) 0.000000 0.000000
T( 3, 1) 4.000000 0.000000
T( 3, 2) 3.000000 0.000000
T( 3, 3) 3.000000 0.000000
T( 3, 4) 0.000000 0.000000
T( 3, 5) 5.000000 0.000000
T( 4, 1) 5.000000 0.000000
T( 4, 2) 5.000000 0.000000
T( 4, 3) 6.000000 0.000000
T( 4, 4) 0.000000 0.000000
T( 4, 5) 4.000000 0.000000
T( 5, 1) 0.000000 0.8000000
T( 5, 2) 0.000000 0.9000000
T( 5, 3) 0.000000 0.8000000
T( 5, 4) 8.000000 0.000000
T( 5, 5) 0.000000 0.8000000
T( 6, 1) 0.000000 0.000000
T( 6, 2) 4.000000 0.000000
T( 6, 3) 0.000000 0.000000
T( 6, 4) 0.000000 0.000000
T( 6, 5) 3.000000 0.000000
Row Slack or Surplus Dual Price
1 710.0000 -1.000000
2 0.000000 -10.00000
3 0.000000 -9.900000
4 0.000000 -10.00000
5 0.000000 -10.80000
6 0.000000 -10.00000
7 1.000000 0.000000
8 0.000000 0.000000
9 1.000000 0.000000
10 0.000000 0.8000000
11 5.000000 0.000000
12 0.000000 0.1000000
13 4.000000 0.000000
14 0.000000 0.1000000
15 0.000000 0.9000000
16 0.000000 0.1000000
17 0.000000 0.1000000
18 5.000000 0.000000
19 0.000000 0.1000000
20 0.000000 0.9000000
21 0.000000 0.1000000
22 0.000000 0.2000000
23 0.000000 0.1000000
24 0.000000 0.2000000
25 0.000000 1.000000
26 0.000000 0.2000000
27 3.000000 0.000000
28 0.000000 0.000000
29 4.000000 0.000000
30 0.000000 0.000000
31 0.000000 0.000000
32 0.000000 0.1000000
33 2.000000 0.000000
34 0.000000 0.1000000
35 0.000000 0.9000000
36 0.000000 0.1000000
37 4.000000 0.000000
38 0.000000 -0.1000000
39 7.000000 0.000000
40 12.00000 0.000000
41 1.000000 0.000000
42 0.000000 -1.400000
希望对您有所帮助!本回答被提问者采纳