-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
146 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from pathlib import Path | ||
from typing import Union | ||
|
||
from .ProjectInstance import Activity, Mode, Project, ProjectInstance, Resource | ||
|
||
|
||
def parse_rcpsp_max(loc: Union[str, Path]) -> ProjectInstance: | ||
""" | ||
Parses the RCPSP/max instance format. | ||
Parameters | ||
---------- | ||
loc | ||
The location of the instance. | ||
Returns | ||
------- | ||
ProjectInstance | ||
The parsed project instance. | ||
""" | ||
|
||
with open(loc, "r") as fh: | ||
lines = iter(line.strip() for line in fh.readlines() if line.strip()) | ||
|
||
num_activities, num_renewables, *_ = map(int, next(lines).split()) | ||
num_activities += 2 # source and target | ||
activities = [] | ||
|
||
succ_lines = [next(lines).split() for _ in range(num_activities)] | ||
activity_lines = [next(lines).split() for _ in range(num_activities)] | ||
|
||
for idx in range(num_activities): | ||
_, _, num_successors, *succ = succ_lines[idx] | ||
successors = list(map(int, succ[: int(num_successors)])) | ||
delays = [int(val.strip("[]")) for val in succ[int(num_successors) :]] | ||
|
||
_, _, duration, *demands = map(int, activity_lines[idx]) | ||
|
||
activity = Activity([Mode(duration, demands)], successors, delays) | ||
activities.append(activity) | ||
|
||
capacities = map(int, next(lines).split()) | ||
resources = [Resource(capacity, renewable=True) for capacity in capacities] | ||
projects = [Project(list(range(num_activities)))] | ||
|
||
return ProjectInstance(resources, activities, projects) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
10 5 0 0 | ||
0 1 4 3 2 1 8 [0] [0] [0] [0] | ||
1 1 1 10 [2] | ||
2 1 3 4 11 7 [5] [9] [0] | ||
3 1 1 9 [3] | ||
4 1 2 11 5 [6] [4] | ||
5 1 2 11 6 [9] [-5] | ||
6 1 3 5 7 11 [-4] [-4] [10] | ||
7 1 2 8 11 [-4] [5] | ||
8 1 2 11 7 [7] [-2] | ||
9 1 1 11 [7] | ||
10 1 2 11 1 [5] [-3] | ||
11 1 0 | ||
0 1 0 0 0 0 0 0 | ||
1 1 2 5 7 8 4 6 | ||
2 1 9 10 8 0 8 10 | ||
3 1 6 9 9 0 4 5 | ||
4 1 6 0 8 0 5 5 | ||
5 1 9 0 8 6 3 4 | ||
6 1 10 8 9 4 9 9 | ||
7 1 5 6 3 0 6 9 | ||
8 1 7 6 8 2 0 10 | ||
9 1 7 0 8 10 3 0 | ||
10 1 5 0 8 0 10 0 | ||
11 1 0 0 0 0 0 0 | ||
10 10 10 10 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from numpy.testing import assert_equal | ||
|
||
from psplib import parse_rcpsp_max | ||
|
||
from .utils import relative | ||
|
||
|
||
def test_ubo10(): | ||
""" | ||
Tests that the instance ``UBO10_01.rcpsp`` is correctly parsed. | ||
""" | ||
instance = parse_rcpsp_max(relative("data/UBO10_01.sch")) | ||
|
||
capacities = [res.capacity for res in instance.resources] | ||
renewables = [res.renewable for res in instance.resources] | ||
|
||
assert_equal(instance.num_resources, 5) | ||
assert_equal(capacities, [10, 10, 10, 10, 10]) | ||
assert_equal(renewables, [True, True, True, True, True]) | ||
|
||
assert_equal(instance.num_projects, 1) | ||
assert_equal(instance.projects[0].num_activities, 12) | ||
assert_equal(instance.num_activities, 12) | ||
|
||
activity = instance.activities[2] # third activity | ||
|
||
assert_equal(activity.successors, [4, 11, 7]) | ||
assert_equal(activity.delays, [5, 9, 0]) | ||
|
||
assert_equal(activity.num_modes, 1) | ||
assert_equal(activity.modes[0].demands, [10, 8, 0, 8, 10]) | ||
assert_equal(activity.modes[0].duration, 9) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.