Skip to content

Commit 92f23dc

Browse files
committed
Bugfix incorrect resource skills
1 parent 56f5784 commit 92f23dc

File tree

3 files changed

+185
-4
lines changed

3 files changed

+185
-4
lines changed

psplib/parse_mslib.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def parse_mslib(loc: Union[str, Path]) -> ProjectInstance:
3030
# Workforce module.
3131
next(lines)
3232
resource_skills = [
33-
list(map(bool, next(lines).split())) for _ in range(num_resources)
33+
list(map(int, next(lines).split())) for _ in range(num_resources)
3434
]
3535

3636
# Workforce module with skill levels.
@@ -43,13 +43,17 @@ def parse_mslib(loc: Union[str, Path]) -> ProjectInstance:
4343
list(map(int, next(lines).split())) for _ in range(num_activities)
4444
]
4545

46-
# All other lines are for extensions to MSRCPSP.
47-
skills = list(range(len(resource_skills[0])))
46+
# All other lines are for extensions to MSRCPSP
47+
# ...
4848

4949
# Resources always have capacity 1 because they can only process one
5050
# activity at a time.
5151
resources = [
52-
Resource(capacity=1, renewable=True, skills=skills)
52+
Resource(
53+
capacity=1,
54+
renewable=True,
55+
skills=[bool(s) for s in skills], # convert 0/1s
56+
)
5357
for skills in resource_skills
5458
]
5559

@@ -68,4 +72,5 @@ def parse_mslib(loc: Union[str, Path]) -> ProjectInstance:
6872
]
6973

7074
project = Project(list(range(len(activities))))
75+
skills = list(range(len(resource_skills[0])))
7176
return ProjectInstance(resources, activities, [project], skills)

tests/data/MSLIB_Set1_11.msrcp

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
\* Project Module *\
2+
32 9 4 5
3+
4+
63
5+
6+
54
7+
8+
0 16 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 31
9+
3 9 7 18 19 21 22 24 26 29 30
10+
1 5 21 22 25 26 27
11+
4 4 19 20 23 24
12+
8 3 21 25 26
13+
5 3 19 20 23
14+
6 2 20 23
15+
1 2 18 27
16+
1 2 18 22
17+
6 2 19 22
18+
3 2 19 28
19+
1 2 20 25
20+
7 2 18 21
21+
6 1 24
22+
3 1 18
23+
1 1 18
24+
5 1 18
25+
10 1 32
26+
4 1 32
27+
4 1 32
28+
2 1 32
29+
8 1 32
30+
9 1 32
31+
6 1 32
32+
1 1 32
33+
10 1 32
34+
10 1 32
35+
1 1 32
36+
3 1 32
37+
7 1 32
38+
1 1 32
39+
0 0
40+
41+
\* Workforce Module *\
42+
1 1 0 0
43+
1 1 0 0
44+
0 1 0 0
45+
1 0 0 1
46+
1 1 0 0
47+
0 0 1 1
48+
0 0 1 1
49+
0 0 1 0
50+
0 0 1 1
51+
52+
\* Workforce Module with Skill Levels *\
53+
4 3 0 0
54+
1 5 0 0
55+
0 4 0 0
56+
5 0 0 4
57+
1 2 0 0
58+
0 0 2 4
59+
0 0 3 4
60+
0 0 2 0
61+
0 0 4 3
62+
63+
\* Skill Requirements Module *\
64+
0 0 0 0
65+
2 0 0 0
66+
0 0 3 0
67+
3 0 0 0
68+
0 0 3 0
69+
0 3 0 0
70+
2 0 0 0
71+
0 0 0 1
72+
0 0 1 0
73+
0 0 3 0
74+
0 0 3 0
75+
0 0 3 0
76+
0 0 4 0
77+
0 0 4 0
78+
0 3 0 0
79+
2 0 0 0
80+
0 3 0 0
81+
0 0 4 0
82+
0 4 0 0
83+
2 0 0 0
84+
1 0 0 0
85+
0 0 4 0
86+
0 2 0 0
87+
0 0 1 0
88+
0 0 2 0
89+
0 0 0 2
90+
4 0 0 0
91+
4 0 0 0
92+
0 0 0 4
93+
4 0 0 0
94+
0 3 0 0
95+
0 0 0 0
96+
97+
\* Skill Level Requirements Module *\
98+
-1
99+
4 5
100+
2 2 3
101+
1 4 5
102+
2 2 3
103+
2 3 5
104+
4 5
105+
4
106+
2
107+
2 2 4
108+
2 3 4
109+
2 2 4
110+
2 2 3 4
111+
2 2 3 4
112+
2 3 5
113+
1 4
114+
3 4 5
115+
2 2 3 4
116+
2 3 4 5
117+
1 5
118+
1
119+
2 2 3 4
120+
3 4
121+
2
122+
2 3
123+
3 4
124+
1 1 4 5
125+
1 1 4 5
126+
3 4 4 4
127+
1 1 4 5
128+
2 3 5
129+
-1
130+
131+
\* Cost Module
132+
100 1
133+
134+
6 12 18 24 30
135+
6 12 18 24 30
136+
4 8 12 16 20
137+
3 6 9 12 15
138+
139+
0.08 0.16 0.24 0.32 0.4
140+
0.04 0.08 0.12 0.16 0.2
141+
0.08 0.16 0.24 0.32 0.4
142+
0.03 0.06 0.09 0.12 0.15
143+
144+
\* Common Resource Usage Module *\
145+
15
146+
147+
46 45 29 24 24
148+
42 37 32 31 29
149+
46 36 36 36 35
150+
38 38 37 24 23
151+
152+
\* Rework Module *\
153+
0.69 0.68 0.61 0.56 0.55
154+
0.7 0.68 0.67 0.57 0.57
155+
0.8 0.65 0.64 0.64 0.61
156+
0.72 0.69 0.6 0.59 0.55

tests/test_parse_mslib.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,23 @@ def test_mslib_set1():
3636
assert_equal(mode.skill_requirements, [0, 3, 0, 0])
3737

3838
assert_equal(instance.num_skills, 4)
39+
40+
41+
def test_bug_resource_skills():
42+
"""
43+
Tests that a bug where resources had the wrong skills is fixed.
44+
"""
45+
instance = parse_mslib(relative("data/MSLIB_Set1_11.msrcp"))
46+
47+
capacities = [res.capacity for res in instance.resources]
48+
renewables = [res.renewable for res in instance.resources]
49+
50+
assert_equal(instance.num_resources, 9)
51+
assert_equal(capacities, [1] * 9)
52+
assert_equal(renewables, [True] * 9)
53+
54+
resource = instance.resources[0]
55+
assert_equal(resource.skills, [1, 1, 0, 0])
56+
57+
resource = instance.resources[2]
58+
assert_equal(resource.skills, [0, 1, 0, 0])

0 commit comments

Comments
 (0)