Skip to content

Commit e75f6a6

Browse files
authored
Add edge weight type CEIL_2D (#130)
1 parent 442c486 commit e75f6a6

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ You can set the `compute_distances` argument in `read_instance` to disable this
163163
Following the VRPLIB conventions, the edge weights are computed based on the `EDGE_WEIGHT_TYPE` specification, and in some cases the `EDGE_WEIGHT_FORMAT` specification. `vrplib` currently supports two categories of edge weight types:
164164
- `*_2D`: Euclidean distances based on the node coordinates data.
165165
- `EUC_2D`: Double precision distances without rounding.
166-
- `FLOOR_2D`: Round down all distances to down to an integer.
166+
- `FLOOR_2D`: Round down all distances to an integer.
167+
- `CEIL_2D`: Round up all distances to an integer.
167168
- `EXACT_2D`: Multiply the distances by 1000, round to the nearest integer.
168169
- `EXPLICIT`: the distance data is explicitly provided, in partial or full form. The `EDGE_WEIGHT_FORMAT` specification must be present. We support the following two edge weight formats:
169170
- `LOWER_ROW`: Lower row triangular matrix without diagonal entries.

tests/parse/test_parse_distances.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_unknown_edge_weight_type_and_format(
3535

3636

3737
@pytest.mark.parametrize(
38-
"edge_weight_type", ["EUC_2D", "FLOOR_2D", "EXACT_2D"]
38+
"edge_weight_type", ["EUC_2D", "FLOOR_2D", "CEIL_2D", "EXACT_2D"]
3939
)
4040
def test_raise_no_coordinates_euclidean_distances(edge_weight_type):
4141
"""
@@ -51,6 +51,7 @@ def test_raise_no_coordinates_euclidean_distances(edge_weight_type):
5151
[
5252
("EUC_2D", [[0, np.sqrt(2)], [np.sqrt(2), 0]]),
5353
("FLOOR_2D", [[0, 1], [1, 0]]),
54+
("CEIL_2D", [[0, 2], [2, 0]]),
5455
("EXACT_2D", [[0, 1414], [1414, 0]]),
5556
],
5657
)

vrplib/parse/parse_distances.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def parse_distances(
5656
if edge_weight_type == "EXACT_2D":
5757
return np.round(distance * 1000)
5858

59+
if edge_weight_type == "CEIL_2D":
60+
return np.ceil(distance)
61+
5962
if edge_weight_type == "EXPLICIT":
6063
if edge_weight_format == "LOWER_ROW":
6164
# TODO Eilon instances edge weight specifications are incorrect in

0 commit comments

Comments
 (0)