VRPtoJSON
This module parses .vrp files to .json. For a specification see this site. The parser has only been validated against the Augerat et al.
instances.
Usage
The function accepts either a string or a buffer as the first parameter, and a dictionary of hooks as the second parameter.
const fs = ;const parseVRP = ;const file = fs;const instance = ;
Example Input:
NAME : ABC-123
COMMENT : (Test et al, Optimal value: 100)
TYPE : CVRP
DIMENSION : 5
EDGE_WEIGHT_TYPE : EUC_2D
CAPACITY : 100
NODE_COORD_SECTION
1 10 10
2 0 0
3 20 20
4 20 0
5 0 20
DEMAND_SECTION
1 0
2 10
3 10
4 10
5 10
DEPOT_SECTION
1
-1
EOF
Example output:
Hooks
Each key value pair in the specification part can be parsed with custom functions.
Example:
const hooks = { const words = value; const idx = words; let best = words idx + 1 ; best = best; return BEST_KNOWN: Number best }const instance = ;
This codes parses the "COMMENT" value and reads the best-known / optimum value. You have to return an dictionary of key value pairs that will be included in the final result.
New output
Notice that "COMMENT" is not included, because it was no returned by the hook function.