-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optional argument to compute edge weights (#98)
- Loading branch information
Showing
6 changed files
with
129 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
from vrplib.parse import parse_solomon, parse_vrplib | ||
|
||
|
||
def read_instance(path, instance_format="vrplib"): | ||
def read_instance(path, instance_format="vrplib", compute_edge_weights=True): | ||
""" | ||
Reads the instance from the passed-in file path. | ||
Parameters | ||
---------- | ||
path | ||
The path to the instance file. | ||
style | ||
The instance format, one of ['vrplib', 'solomon']. | ||
instance_format | ||
The instance format, one of ["vrplib", "solomon"]. Default is "vrplib". | ||
compute_edge_weights | ||
Whether to calculate edge weights based on instance specifications | ||
and node coordinates, if not explicitly provided. Defaults to True. | ||
Returns | ||
------- | ||
dict | ||
The instance data. | ||
A dictionary that contains the instance data. | ||
""" | ||
with open(path, "r") as fi: | ||
if instance_format == "vrplib": | ||
return parse_vrplib(fi.read()) | ||
return parse_vrplib(fi.read(), compute_edge_weights) | ||
elif instance_format == "solomon": | ||
return parse_solomon(fi.read()) | ||
return parse_solomon(fi.read(), compute_edge_weights) | ||
|
||
raise ValueError(f"Format style {instance_format} not known.") |