PyVRP / VRPLIB

Python package to read and write vehicle routing problem instances.
https://github.com/PyVRP/VRPLIB
MIT License
80 stars 6 forks source link

Line comments #103

Closed N-Wouda closed 11 months ago

N-Wouda commented 11 months ago

We use lots of VRPLIB instances in the unit tests of PyVRP. It is sometimes helpful to explain in these instances why they exist, and what aspect of PyVRP they're meant to test. E.g., an instance might have some form of particular infeasibility that we want to use in a unit test for PyVRP.

It's hard to see that when looking at just the data - a comment would be much more helpful. I know that there exists a COMMENT: field that's seen some use, but that's not enough for what I need since that field cannot be defined in arbitrary places in the file. An inline comment syntax would be much more helpful.

So, this issue basically exists to track whether we can add a comment line syntax that VRPLIB can parse. Perhaps we can ignore anything on a line after # or // or ;? Or lines that start with such a symbol? Not sure.

N-Wouda commented 11 months ago

(I'd not mind implementing this, but I think it needs a bit of discussion first)

leonlan commented 11 months ago

I think this is useful to have, but we need to think a bit more about the comment syntax. Ideally, we use something that minimizes the impact of this change and is also future-proof.

For the case where we only allow comments on distinct lines, we have a lot more freedom, since it's not expected that any data or specification line will start with ;, # or //. But when we also want to handle the case where we ignore everything after the comment line syntax, we have to deal with many more variations. I can imagine that some instances use ; or # in the COMMENT specification. One issue with // is that it is used in URLs: for example, a COMMENT specification may include an URL to the web page that is hosting the instance.

Could you maybe provide an example on how you would like to use comments in the PyVRP test instances? If it suffices to have comments only on separate lines, then I think we should implement // as comment line syntax. But if you think it'd be really useful to have comments on "data" lines as well, then we might need to think a bit more about the syntax. Maybe triple forward slashes ///?

N-Wouda commented 11 months ago

I think just line comments are fine, I don't really see a need for comments at the end of data lines. So something like "every line that starts with a ; is a comment" could work.

leonlan commented 11 months ago

OK, that we can do! Let's choose # as line comment syntax. Will you make a PR for this? This function needs to be modified to ignore the comments:

https://github.com/leonlan/VRPLIB/blob/c504de49176125fe523b6f2d931eac62eb0d2683/vrplib/parse/parse_utils.py#L4-L8

It takes the instance text as a string. Lines that are empty when stripped or lines that start with # should be ignored. All other lines are returned as a list.