diff --git a/README.md b/README.md index 16539952..f9e9682c 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ debug or help in using `VROOM`. - **cvrplib_to_json** converts a CVRPLIB file to json. - **vrptw_to_json** converts a VRPTW file to json. - **pdptw_to_json** converts a PDPTW file to json. +- **hvrp_to_json** converts a HVRP file to json. - **add_osrm_matrix** creates a "standalone" version of a json input instance by adding a `matrix` key using OSRM. @@ -30,3 +31,4 @@ instructions for: - [CVRP](benchmarks/CVRP) - [VRPTW](benchmarks/VRPTW) - [PDPTW](benchmarks/PDPTW) +- [HVRP](benchmarks/HVRP) diff --git a/benchmarks/HVRP/BKS.json b/benchmarks/HVRP/BKS.json new file mode 100644 index 00000000..928bb3a6 --- /dev/null +++ b/benchmarks/HVRP/BKS.json @@ -0,0 +1,162 @@ +{ + "vfmpv03": { + "jobs": 20, + "total_amount": 354, + "total_capacity": 5600, + "vehicles": 100, + "best_known_cost": 623.22, + "class": "VFMP_V" + }, + "vfmpv04": { + "jobs": 20, + "total_amount": 354, + "total_capacity": 5800, + "vehicles": 60, + "best_known_cost": 387.18, + "class": "VFMP_V" + }, + "vfmpv05": { + "jobs": 20, + "total_amount": 354, + "total_capacity": 5600, + "vehicles": 100, + "best_known_cost": 742.87, + "class": "VFMP_V" + }, + "vfmpv06": { + "jobs": 20, + "total_amount": 354, + "total_capacity": 5800, + "vehicles": 60, + "best_known_cost": 415.03, + "class": "VFMP_V" + }, + "vfmpv13": { + "jobs": 50, + "total_amount": 973, + "total_capacity": 24000, + "vehicles": 300, + "best_known_cost": 1491.86, + "class": "VFMP_V" + }, + "vfmpv14": { + "jobs": 50, + "total_amount": 973, + "total_capacity": 29000, + "vehicles": 150, + "best_known_cost": 603.21, + "class": "VFMP_V" + }, + "vfmpv15": { + "jobs": 50, + "total_amount": 777, + "total_capacity": 15500, + "vehicles": 150, + "best_known_cost": 999.82, + "class": "VFMP_V" + }, + "vfmpv16": { + "jobs": 50, + "total_amount": 777, + "total_capacity": 13000, + "vehicles": 150, + "best_known_cost": 1131.0, + "class": "VFMP_V" + }, + "vfmpv17": { + "jobs": 75, + "total_amount": 1364, + "total_capacity": 54000, + "vehicles": 300, + "best_known_cost": 1038.6, + "class": "VFMP_V" + }, + "vfmpv18": { + "jobs": 75, + "total_amount": 1364, + "total_capacity": 72750, + "vehicles": 450, + "best_known_cost": 1800.8, + "class": "VFMP_V" + }, + "vfmpv19": { + "jobs": 100, + "total_amount": 1458, + "total_capacity": 60000, + "vehicles": 300, + "best_known_cost": 1105.44, + "class": "VFMP_V" + }, + "vfmpv20": { + "jobs": 100, + "total_amount": 1458, + "total_capacity": 40000, + "vehicles": 300, + "best_known_cost": 1530.43, + "class": "VFMP_V" + }, + "HVRP14": { + "jobs": 50, + "total_amount": 973, + "total_capacity": 1100, + "vehicles": 7, + "best_known_cost": 607.53, + "class": "HFVRP" + }, + "HVRP16": { + "jobs": 50, + "total_amount": 777, + "total_capacity": 820, + "vehicles": 9, + "best_known_cost": 1144.94, + "class": "HFVRP" + }, + "HVRP15": { + "jobs": 50, + "total_amount": 777, + "total_capacity": 820, + "vehicles": 9, + "best_known_cost": 1015.29, + "class": "HFVRP" + }, + "HVRP13": { + "jobs": 50, + "total_amount": 973, + "total_capacity": 1020, + "vehicles": 17, + "best_known_cost": 1518.05, + "class": "HFVRP" + }, + "HVRP17": { + "jobs": 75, + "total_amount": 1364, + "total_capacity": 1430, + "vehicles": 11, + "best_known_cost": 1061.96, + "class": "HFVRP" + }, + "HVRP18": { + "jobs": 75, + "total_amount": 1364, + "total_capacity": 1430, + "vehicles": 14, + "best_known_cost": 1823.58, + "class": "HFVRP" + }, + "HVRP20": { + "jobs": 100, + "total_amount": 1458, + "total_capacity": 1520, + "vehicles": 13, + "best_known_cost": 1534.17, + "class": "HFVRP" + }, + "HVRP19": { + "jobs": 100, + "total_amount": 1458, + "total_capacity": 1900, + "vehicles": 10, + "best_known_cost": 1117.51, + "class": "HFVRP" + } +} diff --git a/benchmarks/HVRP/HFVRP/HVRP13.txt b/benchmarks/HVRP/HFVRP/HVRP13.txt new file mode 100644 index 00000000..f5d0ff7d --- /dev/null +++ b/benchmarks/HVRP/HFVRP/HVRP13.txt @@ -0,0 +1,65 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 50 6 999999.0 0.0 1517.84 1518.05 + 4 20 0 1.0 + 2 30 0 1.1 + 4 40 0 1.2 + 4 70 0 1.7 + 2 120 0 2.5 + 1 200 0 3.2 + 40 40 + 22 22 18 + 36 26 26 + 21 45 11 + 45 35 30 + 55 20 21 + 33 34 19 + 50 50 15 + 55 45 16 + 26 59 29 + 40 66 26 + 55 65 37 + 35 51 16 + 62 35 12 + 62 57 31 + 62 24 8 + 21 36 19 + 33 44 20 + 9 56 13 + 62 48 15 + 66 14 22 + 44 13 28 + 26 13 12 + 11 28 6 + 7 43 27 + 17 64 14 + 41 46 18 + 55 34 17 + 35 16 29 + 52 26 13 + 43 26 22 + 31 76 25 + 22 53 28 + 26 29 27 + 50 40 19 + 55 50 10 + 54 10 12 + 60 15 14 + 47 66 24 + 30 60 16 + 30 50 33 + 12 17 15 + 15 14 11 + 16 19 18 + 21 48 17 + 50 30 21 + 51 42 27 + 50 15 19 + 48 21 20 + 12 38 5 + 15 56 22 + + diff --git a/benchmarks/HVRP/HFVRP/HVRP14.txt b/benchmarks/HVRP/HFVRP/HVRP14.txt new file mode 100644 index 00000000..50c126cc --- /dev/null +++ b/benchmarks/HVRP/HFVRP/HVRP14.txt @@ -0,0 +1,62 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 50 3 999999.0 0.0 607.53 607.53 + 4 120 0 1.0 + 2 160 0 1.1 + 1 300 0 1.4 + 40 40 + 22 22 18 + 36 26 26 + 21 45 11 + 45 35 30 + 55 20 21 + 33 34 19 + 50 50 15 + 55 45 16 + 26 59 29 + 40 66 26 + 55 65 37 + 35 51 16 + 62 35 12 + 62 57 31 + 62 24 8 + 21 36 19 + 33 44 20 + 9 56 13 + 62 48 15 + 66 14 22 + 44 13 28 + 26 13 12 + 11 28 6 + 7 43 27 + 17 64 14 + 41 46 18 + 55 34 17 + 35 16 29 + 52 26 13 + 43 26 22 + 31 76 25 + 22 53 28 + 26 29 27 + 50 40 19 + 55 50 10 + 54 10 12 + 60 15 14 + 47 66 24 + 30 60 16 + 30 50 33 + 12 17 15 + 15 14 11 + 16 19 18 + 21 48 17 + 50 30 21 + 51 42 27 + 50 15 19 + 48 21 20 + 12 38 5 + 15 56 22 + + diff --git a/benchmarks/HVRP/HFVRP/HVRP15.txt b/benchmarks/HVRP/HFVRP/HVRP15.txt new file mode 100644 index 00000000..e53526b7 --- /dev/null +++ b/benchmarks/HVRP/HFVRP/HVRP15.txt @@ -0,0 +1,61 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 50 3 999999.0 0.0 1015.29 1015.29 + 4 50 0 1.0 + 3 100 0 1.6 + 2 160 0 2.0 + 30 40 + 37 52 7 + 49 49 30 + 52 64 16 + 20 26 9 + 40 30 21 + 21 47 15 + 17 63 19 + 31 62 23 + 52 33 11 + 51 21 5 + 42 41 19 + 31 32 29 + 5 25 23 + 12 42 21 + 36 16 10 + 52 41 15 + 27 23 3 + 17 33 41 + 13 13 9 + 57 58 28 + 62 42 8 + 42 57 8 + 16 57 16 + 8 52 10 + 7 38 28 + 27 68 7 + 30 48 15 + 43 67 14 + 58 48 6 + 58 27 19 + 37 69 11 + 38 46 12 + 46 10 23 + 61 33 26 + 62 63 17 + 63 69 6 + 32 22 9 + 45 35 15 + 59 15 14 + 5 6 7 + 10 17 27 + 21 10 13 + 5 64 11 + 30 15 16 + 39 10 10 + 32 39 5 + 25 32 25 + 25 55 17 + 48 28 18 + 56 37 10 + diff --git a/benchmarks/HVRP/HFVRP/HVRP16.txt b/benchmarks/HVRP/HFVRP/HVRP16.txt new file mode 100644 index 00000000..f4a25879 --- /dev/null +++ b/benchmarks/HVRP/HFVRP/HVRP16.txt @@ -0,0 +1,61 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 50 3 999999.0 0.0 1144.94 1144.94 + 2 40 0 1.0 + 4 80 0 1.6 + 3 140 0 2.1 + 30 40 + 37 52 7 + 49 49 30 + 52 64 16 + 20 26 9 + 40 30 21 + 21 47 15 + 17 63 19 + 31 62 23 + 52 33 11 + 51 21 5 + 42 41 19 + 31 32 29 + 5 25 23 + 12 42 21 + 36 16 10 + 52 41 15 + 27 23 3 + 17 33 41 + 13 13 9 + 57 58 28 + 62 42 8 + 42 57 8 + 16 57 16 + 8 52 10 + 7 38 28 + 27 68 7 + 30 48 15 + 43 67 14 + 58 48 6 + 58 27 19 + 37 69 11 + 38 46 12 + 46 10 23 + 61 33 26 + 62 63 17 + 63 69 6 + 32 22 9 + 45 35 15 + 59 15 14 + 5 6 7 + 10 17 27 + 21 10 13 + 5 64 11 + 30 15 16 + 39 10 10 + 32 39 5 + 25 32 25 + 25 55 17 + 48 28 18 + 56 37 10 + diff --git a/benchmarks/HVRP/HFVRP/HVRP17.txt b/benchmarks/HVRP/HFVRP/HVRP17.txt new file mode 100644 index 00000000..dd9f1b32 --- /dev/null +++ b/benchmarks/HVRP/HFVRP/HVRP17.txt @@ -0,0 +1,87 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 75 4 999999.0 0.0 1061.96 1061.96 + 4 50 0 1.0 + 4 120 0 1.2 + 2 200 0 1.5 + 1 350 0 1.8 + 40 40 + 22 22 18 + 36 26 26 + 21 45 11 + 45 35 30 + 55 20 21 + 33 34 19 + 50 50 15 + 55 45 16 + 26 59 29 + 40 66 26 + 55 65 37 + 35 51 16 + 62 35 12 + 62 57 31 + 62 24 8 + 21 36 19 + 33 44 20 + 9 56 13 + 62 48 15 + 66 14 22 + 44 13 28 + 26 13 12 + 11 28 6 + 7 43 27 + 17 64 14 + 41 46 18 + 55 34 17 + 35 16 29 + 52 26 13 + 43 26 22 + 31 76 25 + 22 53 28 + 26 29 27 + 50 40 19 + 55 50 10 + 54 10 12 + 60 15 14 + 47 66 24 + 30 60 16 + 30 50 33 + 12 17 15 + 15 14 11 + 16 19 18 + 21 48 17 + 50 30 21 + 51 42 27 + 50 15 19 + 48 21 20 + 12 38 5 + 15 56 22 + 29 39 12 + 54 38 19 + 55 57 22 + 67 41 16 + 10 70 7 + 6 25 26 + 65 27 14 + 40 60 21 + 70 64 24 + 64 4 13 + 36 6 15 + 30 20 18 + 20 30 11 + 15 5 28 + 50 70 9 + 57 72 37 + 45 42 30 + 38 33 10 + 50 4 8 + 66 8 11 + 59 5 3 + 35 60 1 + 27 24 6 + 40 20 10 + 40 37 20 + diff --git a/benchmarks/HVRP/HFVRP/HVRP18.txt b/benchmarks/HVRP/HFVRP/HVRP18.txt new file mode 100644 index 00000000..884b5d05 --- /dev/null +++ b/benchmarks/HVRP/HFVRP/HVRP18.txt @@ -0,0 +1,89 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 75 6 999999.0 0.0 1823.58 1823.58 + 4 20 0 1.0 + 4 50 0 1.3 + 2 100 0 1.9 + 2 150 0 2.4 + 1 250 0 2.9 + 1 400 0 3.2 + 40 40 + 22 22 18 + 36 26 26 + 21 45 11 + 45 35 30 + 55 20 21 + 33 34 19 + 50 50 15 + 55 45 16 + 26 59 29 + 40 66 26 + 55 65 37 + 35 51 16 + 62 35 12 + 62 57 31 + 62 24 8 + 21 36 19 + 33 44 20 + 9 56 13 + 62 48 15 + 66 14 22 + 44 13 28 + 26 13 12 + 11 28 6 + 7 43 27 + 17 64 14 + 41 46 18 + 55 34 17 + 35 16 29 + 52 26 13 + 43 26 22 + 31 76 25 + 22 53 28 + 26 29 27 + 50 40 19 + 55 50 10 + 54 10 12 + 60 15 14 + 47 66 24 + 30 60 16 + 30 50 33 + 12 17 15 + 15 14 11 + 16 19 18 + 21 48 17 + 50 30 21 + 51 42 27 + 50 15 19 + 48 21 20 + 12 38 5 + 15 56 22 + 29 39 12 + 54 38 19 + 55 57 22 + 67 41 16 + 10 70 7 + 6 25 26 + 65 27 14 + 40 60 21 + 70 64 24 + 64 4 13 + 36 6 15 + 30 20 18 + 20 30 11 + 15 5 28 + 50 70 9 + 57 72 37 + 45 42 30 + 38 33 10 + 50 4 8 + 66 8 11 + 59 5 3 + 35 60 1 + 27 24 6 + 40 20 10 + 40 37 20 + diff --git a/benchmarks/HVRP/HFVRP/HVRP19.txt b/benchmarks/HVRP/HFVRP/HVRP19.txt new file mode 100644 index 00000000..2c8c35b1 --- /dev/null +++ b/benchmarks/HVRP/HFVRP/HVRP19.txt @@ -0,0 +1,111 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand +100 3 999999.0 0.0 1080.68 1117.51 +4 100 0 1.0 +3 200 0 1.4 +3 300 0 1.7 + 35 35 + 41 49 10 + 35 17 7 + 55 45 13 + 55 20 19 + 15 30 26 + 25 30 3 + 20 50 5 + 10 43 9 + 55 60 16 + 30 60 16 + 20 65 12 + 50 35 19 + 30 25 23 + 15 10 20 + 30 5 8 + 10 20 19 + 5 30 2 + 20 40 12 + 15 60 17 + 45 65 9 + 45 20 11 + 45 10 18 + 55 5 29 + 65 35 3 + 65 20 6 + 45 30 17 + 35 40 16 + 41 37 16 + 64 42 9 + 40 60 21 + 31 52 27 + 35 69 23 + 53 52 11 + 65 55 14 + 63 65 8 + 2 60 5 + 20 20 8 + 5 5 16 + 60 12 31 + 40 25 9 + 42 7 5 + 24 12 5 + 23 3 7 + 11 14 18 + 6 38 16 + 2 48 1 + 8 56 27 + 13 52 36 + 6 68 30 + 47 47 13 + 49 58 10 + 27 43 9 + 37 31 14 + 57 29 18 + 63 23 2 + 53 12 6 + 32 12 7 + 36 26 18 + 21 24 28 + 17 34 3 + 12 24 13 + 24 58 19 + 27 69 10 + 15 77 9 + 62 77 20 + 49 73 25 + 67 5 25 + 56 39 36 + 37 47 6 + 37 56 5 + 57 68 15 + 47 16 25 + 44 17 9 + 46 13 8 + 49 11 18 + 49 42 13 + 53 43 14 + 61 52 3 + 57 48 23 + 56 37 6 + 55 54 26 + 15 47 16 + 14 37 11 + 11 31 7 + 16 22 41 + 4 18 35 + 28 18 26 + 26 52 9 + 26 35 15 + 31 67 3 + 15 19 1 + 22 22 2 + 18 24 22 + 26 27 27 + 25 24 20 + 22 27 11 + 25 21 12 + 19 21 10 + 20 26 9 + 18 18 17 + diff --git a/benchmarks/HVRP/HFVRP/HVRP20.txt b/benchmarks/HVRP/HFVRP/HVRP20.txt new file mode 100644 index 00000000..ae3cd666 --- /dev/null +++ b/benchmarks/HVRP/HFVRP/HVRP20.txt @@ -0,0 +1,111 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand +100 3 999999.0 0.0 1534.17 1534.17 +6 60 0 1.0 +4 140 0 1.7 +3 200 0 2 + 35 35 + 41 49 10 + 35 17 7 + 55 45 13 + 55 20 19 + 15 30 26 + 25 30 3 + 20 50 5 + 10 43 9 + 55 60 16 + 30 60 16 + 20 65 12 + 50 35 19 + 30 25 23 + 15 10 20 + 30 5 8 + 10 20 19 + 5 30 2 + 20 40 12 + 15 60 17 + 45 65 9 + 45 20 11 + 45 10 18 + 55 5 29 + 65 35 3 + 65 20 6 + 45 30 17 + 35 40 16 + 41 37 16 + 64 42 9 + 40 60 21 + 31 52 27 + 35 69 23 + 53 52 11 + 65 55 14 + 63 65 8 + 2 60 5 + 20 20 8 + 5 5 16 + 60 12 31 + 40 25 9 + 42 7 5 + 24 12 5 + 23 3 7 + 11 14 18 + 6 38 16 + 2 48 1 + 8 56 27 + 13 52 36 + 6 68 30 + 47 47 13 + 49 58 10 + 27 43 9 + 37 31 14 + 57 29 18 + 63 23 2 + 53 12 6 + 32 12 7 + 36 26 18 + 21 24 28 + 17 34 3 + 12 24 13 + 24 58 19 + 27 69 10 + 15 77 9 + 62 77 20 + 49 73 25 + 67 5 25 + 56 39 36 + 37 47 6 + 37 56 5 + 57 68 15 + 47 16 25 + 44 17 9 + 46 13 8 + 49 11 18 + 49 42 13 + 53 43 14 + 61 52 3 + 57 48 23 + 56 37 6 + 55 54 26 + 15 47 16 + 14 37 11 + 11 31 7 + 16 22 41 + 4 18 35 + 28 18 26 + 26 52 9 + 26 35 15 + 31 67 3 + 15 19 1 + 22 22 2 + 18 24 22 + 26 27 27 + 25 24 20 + 22 27 11 + 25 21 12 + 19 21 10 + 20 26 9 + 18 18 17 + diff --git a/benchmarks/HVRP/README.md b/benchmarks/HVRP/README.md new file mode 100644 index 00000000..318ee3fe --- /dev/null +++ b/benchmarks/HVRP/README.md @@ -0,0 +1,37 @@ +# HVRP benchmark classes + +## Instances + +The `VFMP_V` folder contains instances available +[here](http://fc.isima.fr/~lacomme/hvrp/hvrp.html). See +[Prins](https://dl.acm.org/doi/abs/10.1016/j.engappai.2008.10.006) for +a description of this class of problem. + +# Solving + +Assuming the `vroom` command is somewhere in your path, just run the +provided scripts on the benchmark classes you want to use. + +``` +./generate.sh VFMP_V HFVRP +./run.sh VFMP_V HFVRP +``` + +Includes: + +- parsing all `*.txt` files to generate `VROOM` input files in `json` format +- solving all instances +- retrieving comparisons to best known solutions for all instances +- logging global indicators + +# Notes + +## Costs evaluation + +All results reported in the literature for the above benchmarks use +double precision for costs. + +Our workaround is to round costs with the usual TSPLIB convention +**after** multiplying double precision values by 1000 to keep a fair +amount of precision. Then this "scaling" is taken into account while +comparing our results to best known solutions. diff --git a/benchmarks/HVRP/VFMP_V/vfmpv03.txt b/benchmarks/HVRP/VFMP_V/vfmpv03.txt new file mode 100644 index 00000000..4f9e35d9 --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv03.txt @@ -0,0 +1,32 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 20 5 999999.0 0.0 616.38 623.22 + 20 20 0 1.0 + 20 30 0 1.1 + 20 40 0 1.2 + 20 70 0 1.7 + 20 120 0 2.5 + 30 40 + 37 52 7 + 49 49 30 + 52 64 16 + 20 26 9 + 40 30 21 + 21 47 15 + 17 63 19 + 31 62 23 + 52 33 11 + 51 21 5 + 42 41 19 + 31 32 29 + 5 25 23 + 12 42 21 + 36 16 10 + 52 41 15 + 27 23 3 + 17 33 41 + 13 13 9 + 57 58 28 diff --git a/benchmarks/HVRP/VFMP_V/vfmpv04.txt b/benchmarks/HVRP/VFMP_V/vfmpv04.txt new file mode 100644 index 00000000..7197767e --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv04.txt @@ -0,0 +1,30 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 20 3 999999.0 0.0 376.94 387.18 + 20 60 0 1.0 + 20 80 0 1.1 + 20 150 0 1.4 + 30 40 + 37 52 7 + 49 49 30 + 52 64 16 + 20 26 9 + 40 30 21 + 21 47 15 + 17 63 19 + 31 62 23 + 52 33 11 + 51 21 5 + 42 41 19 + 31 32 29 + 5 25 23 + 12 42 21 + 36 16 10 + 52 41 15 + 27 23 3 + 17 33 41 + 13 13 9 + 57 58 28 diff --git a/benchmarks/HVRP/VFMP_V/vfmpv05.txt b/benchmarks/HVRP/VFMP_V/vfmpv05.txt new file mode 100644 index 00000000..b2f6d93f --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv05.txt @@ -0,0 +1,32 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 20 5 999999.0 0.0 739.72 742.87 + 20 20 0 1.0 + 20 30 0 1.1 + 20 40 0 1.2 + 20 70 0 1.7 + 20 120 0 2.5 + 20 20 + 37 52 7 + 49 49 30 + 52 64 16 + 20 26 9 + 40 30 21 + 21 47 15 + 17 63 19 + 31 62 23 + 52 33 11 + 51 21 5 + 42 41 19 + 31 32 29 + 5 25 23 + 12 42 21 + 36 16 10 + 52 41 15 + 27 23 3 + 17 33 41 + 13 13 9 + 57 58 28 diff --git a/benchmarks/HVRP/VFMP_V/vfmpv06.txt b/benchmarks/HVRP/VFMP_V/vfmpv06.txt new file mode 100644 index 00000000..1770b49c --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv06.txt @@ -0,0 +1,30 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 20 3 999999.0 0.0 406.82 415.03 + 20 60 0 1.0 + 20 80 0 1.1 + 20 150 0 1.4 + 20 20 + 37 52 7 + 49 49 30 + 52 64 16 + 20 26 9 + 40 30 21 + 21 47 15 + 17 63 19 + 31 62 23 + 52 33 11 + 51 21 5 + 42 41 19 + 31 32 29 + 5 25 23 + 12 42 21 + 36 16 10 + 52 41 15 + 27 23 3 + 17 33 41 + 13 13 9 + 57 58 28 diff --git a/benchmarks/HVRP/VFMP_V/vfmpv13.txt b/benchmarks/HVRP/VFMP_V/vfmpv13.txt new file mode 100644 index 00000000..936401ce --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv13.txt @@ -0,0 +1,65 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 50 6 999999.0 0.0 1491.86 1491.86 + 50 20 0 1.0 + 50 30 0 1.1 + 50 40 0 1.2 + 50 70 0 1.7 + 50 120 0 2.5 + 50 200 0 3.2 + 40 40 + 22 22 18 + 36 26 26 + 21 45 11 + 45 35 30 + 55 20 21 + 33 34 19 + 50 50 15 + 55 45 16 + 26 59 29 + 40 66 26 + 55 65 37 + 35 51 16 + 62 35 12 + 62 57 31 + 62 24 8 + 21 36 19 + 33 44 20 + 9 56 13 + 62 48 15 + 66 14 22 + 44 13 28 + 26 13 12 + 11 28 6 + 7 43 27 + 17 64 14 + 41 46 18 + 55 34 17 + 35 16 29 + 52 26 13 + 43 26 22 + 31 76 25 + 22 53 28 + 26 29 27 + 50 40 19 + 55 50 10 + 54 10 12 + 60 15 14 + 47 66 24 + 30 60 16 + 30 50 33 + 12 17 15 + 15 14 11 + 16 19 18 + 21 48 17 + 50 30 21 + 51 42 27 + 50 15 19 + 48 21 20 + 12 38 5 + 15 56 22 + + diff --git a/benchmarks/HVRP/VFMP_V/vfmpv14.txt b/benchmarks/HVRP/VFMP_V/vfmpv14.txt new file mode 100644 index 00000000..8a393b01 --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv14.txt @@ -0,0 +1,62 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 50 3 999999.0 0.0 603.21 603.21 + 50 120 0 1.0 + 50 160 0 1.1 + 50 300 0 1.4 + 40 40 + 22 22 18 + 36 26 26 + 21 45 11 + 45 35 30 + 55 20 21 + 33 34 19 + 50 50 15 + 55 45 16 + 26 59 29 + 40 66 26 + 55 65 37 + 35 51 16 + 62 35 12 + 62 57 31 + 62 24 8 + 21 36 19 + 33 44 20 + 9 56 13 + 62 48 15 + 66 14 22 + 44 13 28 + 26 13 12 + 11 28 6 + 7 43 27 + 17 64 14 + 41 46 18 + 55 34 17 + 35 16 29 + 52 26 13 + 43 26 22 + 31 76 25 + 22 53 28 + 26 29 27 + 50 40 19 + 55 50 10 + 54 10 12 + 60 15 14 + 47 66 24 + 30 60 16 + 30 50 33 + 12 17 15 + 15 14 11 + 16 19 18 + 21 48 17 + 50 30 21 + 51 42 27 + 50 15 19 + 48 21 20 + 12 38 5 + 15 56 22 + + diff --git a/benchmarks/HVRP/VFMP_V/vfmpv15.txt b/benchmarks/HVRP/VFMP_V/vfmpv15.txt new file mode 100644 index 00000000..4b0f9064 --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv15.txt @@ -0,0 +1,61 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 50 3 999999.0 0.0 999.82 999.82 + 50 50 0 1.0 + 50 100 0 1.6 + 50 160 0 2.0 + 30 40 + 37 52 7 + 49 49 30 + 52 64 16 + 20 26 9 + 40 30 21 + 21 47 15 + 17 63 19 + 31 62 23 + 52 33 11 + 51 21 5 + 42 41 19 + 31 32 29 + 5 25 23 + 12 42 21 + 36 16 10 + 52 41 15 + 27 23 3 + 17 33 41 + 13 13 9 + 57 58 28 + 62 42 8 + 42 57 8 + 16 57 16 + 8 52 10 + 7 38 28 + 27 68 7 + 30 48 15 + 43 67 14 + 58 48 6 + 58 27 19 + 37 69 11 + 38 46 12 + 46 10 23 + 61 33 26 + 62 63 17 + 63 69 6 + 32 22 9 + 45 35 15 + 59 15 14 + 5 6 7 + 10 17 27 + 21 10 13 + 5 64 11 + 30 15 16 + 39 10 10 + 32 39 5 + 25 32 25 + 25 55 17 + 48 28 18 + 56 37 10 + diff --git a/benchmarks/HVRP/VFMP_V/vfmpv16.txt b/benchmarks/HVRP/VFMP_V/vfmpv16.txt new file mode 100644 index 00000000..10fcb335 --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv16.txt @@ -0,0 +1,61 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 50 3 999999.0 0.0 1131.00 1131.00 + 50 40 0 1.0 + 50 80 0 1.6 + 50 140 0 2.1 + 30 40 + 37 52 7 + 49 49 30 + 52 64 16 + 20 26 9 + 40 30 21 + 21 47 15 + 17 63 19 + 31 62 23 + 52 33 11 + 51 21 5 + 42 41 19 + 31 32 29 + 5 25 23 + 12 42 21 + 36 16 10 + 52 41 15 + 27 23 3 + 17 33 41 + 13 13 9 + 57 58 28 + 62 42 8 + 42 57 8 + 16 57 16 + 8 52 10 + 7 38 28 + 27 68 7 + 30 48 15 + 43 67 14 + 58 48 6 + 58 27 19 + 37 69 11 + 38 46 12 + 46 10 23 + 61 33 26 + 62 63 17 + 63 69 6 + 32 22 9 + 45 35 15 + 59 15 14 + 5 6 7 + 10 17 27 + 21 10 13 + 5 64 11 + 30 15 16 + 39 10 10 + 32 39 5 + 25 32 25 + 25 55 17 + 48 28 18 + 56 37 10 + diff --git a/benchmarks/HVRP/VFMP_V/vfmpv17.txt b/benchmarks/HVRP/VFMP_V/vfmpv17.txt new file mode 100644 index 00000000..dc45974c --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv17.txt @@ -0,0 +1,87 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 75 4 999999.0 0.0 1038.60 1038.60 + 75 50 0 1.0 + 75 120 0 1.2 + 75 200 0 1.5 + 75 350 0 1.8 + 40 40 + 22 22 18 + 36 26 26 + 21 45 11 + 45 35 30 + 55 20 21 + 33 34 19 + 50 50 15 + 55 45 16 + 26 59 29 + 40 66 26 + 55 65 37 + 35 51 16 + 62 35 12 + 62 57 31 + 62 24 8 + 21 36 19 + 33 44 20 + 9 56 13 + 62 48 15 + 66 14 22 + 44 13 28 + 26 13 12 + 11 28 6 + 7 43 27 + 17 64 14 + 41 46 18 + 55 34 17 + 35 16 29 + 52 26 13 + 43 26 22 + 31 76 25 + 22 53 28 + 26 29 27 + 50 40 19 + 55 50 10 + 54 10 12 + 60 15 14 + 47 66 24 + 30 60 16 + 30 50 33 + 12 17 15 + 15 14 11 + 16 19 18 + 21 48 17 + 50 30 21 + 51 42 27 + 50 15 19 + 48 21 20 + 12 38 5 + 15 56 22 + 29 39 12 + 54 38 19 + 55 57 22 + 67 41 16 + 10 70 7 + 6 25 26 + 65 27 14 + 40 60 21 + 70 64 24 + 64 4 13 + 36 6 15 + 30 20 18 + 20 30 11 + 15 5 28 + 50 70 9 + 57 72 37 + 45 42 30 + 38 33 10 + 50 4 8 + 66 8 11 + 59 5 3 + 35 60 1 + 27 24 6 + 40 20 10 + 40 37 20 + diff --git a/benchmarks/HVRP/VFMP_V/vfmpv18.txt b/benchmarks/HVRP/VFMP_V/vfmpv18.txt new file mode 100644 index 00000000..c259bb8d --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv18.txt @@ -0,0 +1,89 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand + 75 6 999999.0 0.0 1800.80 1800.80 + 75 20 0 1.0 + 75 50 0 1.3 + 75 100 0 1.9 + 75 150 0 2.4 + 75 250 0 2.9 + 75 400 0 3.2 + 40 40 + 22 22 18 + 36 26 26 + 21 45 11 + 45 35 30 + 55 20 21 + 33 34 19 + 50 50 15 + 55 45 16 + 26 59 29 + 40 66 26 + 55 65 37 + 35 51 16 + 62 35 12 + 62 57 31 + 62 24 8 + 21 36 19 + 33 44 20 + 9 56 13 + 62 48 15 + 66 14 22 + 44 13 28 + 26 13 12 + 11 28 6 + 7 43 27 + 17 64 14 + 41 46 18 + 55 34 17 + 35 16 29 + 52 26 13 + 43 26 22 + 31 76 25 + 22 53 28 + 26 29 27 + 50 40 19 + 55 50 10 + 54 10 12 + 60 15 14 + 47 66 24 + 30 60 16 + 30 50 33 + 12 17 15 + 15 14 11 + 16 19 18 + 21 48 17 + 50 30 21 + 51 42 27 + 50 15 19 + 48 21 20 + 12 38 5 + 15 56 22 + 29 39 12 + 54 38 19 + 55 57 22 + 67 41 16 + 10 70 7 + 6 25 26 + 65 27 14 + 40 60 21 + 70 64 24 + 64 4 13 + 36 6 15 + 30 20 18 + 20 30 11 + 15 5 28 + 50 70 9 + 57 72 37 + 45 42 30 + 38 33 10 + 50 4 8 + 66 8 11 + 59 5 3 + 35 60 1 + 27 24 6 + 40 20 10 + 40 37 20 + diff --git a/benchmarks/HVRP/VFMP_V/vfmpv19.txt b/benchmarks/HVRP/VFMP_V/vfmpv19.txt new file mode 100644 index 00000000..692f8531 --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv19.txt @@ -0,0 +1,111 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand +100 3 999999.0 0.0 1105.44 1105.44 +100 100 0 1.0 +100 200 0 1.4 +100 300 0 1.7 + 35 35 + 41 49 10 + 35 17 7 + 55 45 13 + 55 20 19 + 15 30 26 + 25 30 3 + 20 50 5 + 10 43 9 + 55 60 16 + 30 60 16 + 20 65 12 + 50 35 19 + 30 25 23 + 15 10 20 + 30 5 8 + 10 20 19 + 5 30 2 + 20 40 12 + 15 60 17 + 45 65 9 + 45 20 11 + 45 10 18 + 55 5 29 + 65 35 3 + 65 20 6 + 45 30 17 + 35 40 16 + 41 37 16 + 64 42 9 + 40 60 21 + 31 52 27 + 35 69 23 + 53 52 11 + 65 55 14 + 63 65 8 + 2 60 5 + 20 20 8 + 5 5 16 + 60 12 31 + 40 25 9 + 42 7 5 + 24 12 5 + 23 3 7 + 11 14 18 + 6 38 16 + 2 48 1 + 8 56 27 + 13 52 36 + 6 68 30 + 47 47 13 + 49 58 10 + 27 43 9 + 37 31 14 + 57 29 18 + 63 23 2 + 53 12 6 + 32 12 7 + 36 26 18 + 21 24 28 + 17 34 3 + 12 24 13 + 24 58 19 + 27 69 10 + 15 77 9 + 62 77 20 + 49 73 25 + 67 5 25 + 56 39 36 + 37 47 6 + 37 56 5 + 57 68 15 + 47 16 25 + 44 17 9 + 46 13 8 + 49 11 18 + 49 42 13 + 53 43 14 + 61 52 3 + 57 48 23 + 56 37 6 + 55 54 26 + 15 47 16 + 14 37 11 + 11 31 7 + 16 22 41 + 4 18 35 + 28 18 26 + 26 52 9 + 26 35 15 + 31 67 3 + 15 19 1 + 22 22 2 + 18 24 22 + 26 27 27 + 25 24 20 + 22 27 11 + 25 21 12 + 19 21 10 + 20 26 9 + 18 18 17 + diff --git a/benchmarks/HVRP/VFMP_V/vfmpv20.txt b/benchmarks/HVRP/VFMP_V/vfmpv20.txt new file mode 100644 index 00000000..8b1157ca --- /dev/null +++ b/benchmarks/HVRP/VFMP_V/vfmpv20.txt @@ -0,0 +1,111 @@ + //Lines 1:5 : these comments + //Line 6 : customers (N), vehicle types (T), range, service time, LB, BKS + //Lines 7:T+6 : per type: number, capacity, fixed cost, cost per distance unit + //Line T+7 : depot coordinates X and Y + //Lines T+8:T+N+7: per customer: coordinates X and Y and demand +100 3 999999.0 0.0 1530.43 1530.43 +100 60 0 1.0 +100 140 0 1.7 +100 200 0 2 + 35 35 + 41 49 10 + 35 17 7 + 55 45 13 + 55 20 19 + 15 30 26 + 25 30 3 + 20 50 5 + 10 43 9 + 55 60 16 + 30 60 16 + 20 65 12 + 50 35 19 + 30 25 23 + 15 10 20 + 30 5 8 + 10 20 19 + 5 30 2 + 20 40 12 + 15 60 17 + 45 65 9 + 45 20 11 + 45 10 18 + 55 5 29 + 65 35 3 + 65 20 6 + 45 30 17 + 35 40 16 + 41 37 16 + 64 42 9 + 40 60 21 + 31 52 27 + 35 69 23 + 53 52 11 + 65 55 14 + 63 65 8 + 2 60 5 + 20 20 8 + 5 5 16 + 60 12 31 + 40 25 9 + 42 7 5 + 24 12 5 + 23 3 7 + 11 14 18 + 6 38 16 + 2 48 1 + 8 56 27 + 13 52 36 + 6 68 30 + 47 47 13 + 49 58 10 + 27 43 9 + 37 31 14 + 57 29 18 + 63 23 2 + 53 12 6 + 32 12 7 + 36 26 18 + 21 24 28 + 17 34 3 + 12 24 13 + 24 58 19 + 27 69 10 + 15 77 9 + 62 77 20 + 49 73 25 + 67 5 25 + 56 39 36 + 37 47 6 + 37 56 5 + 57 68 15 + 47 16 25 + 44 17 9 + 46 13 8 + 49 11 18 + 49 42 13 + 53 43 14 + 61 52 3 + 57 48 23 + 56 37 6 + 55 54 26 + 15 47 16 + 14 37 11 + 11 31 7 + 16 22 41 + 4 18 35 + 28 18 26 + 26 52 9 + 26 35 15 + 31 67 3 + 15 19 1 + 22 22 2 + 18 24 22 + 26 27 27 + 25 24 20 + 22 27 11 + 25 21 12 + 19 21 10 + 20 26 9 + 18 18 17 + diff --git a/benchmarks/HVRP/generate.sh b/benchmarks/HVRP/generate.sh new file mode 100755 index 00000000..45536461 --- /dev/null +++ b/benchmarks/HVRP/generate.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Loop over list of folder in input. +for class in "$@" +do + echo "* Move to ${class} class folder" + cd ${class} + + # Generate json files from *.txt files on the first execution. + echo "* Writing json input files" + for file in `ls -rS *.txt` + do + json_file=${file%.txt}.json + [ -f ${json_file} ] || python ../../../src/hvrp_to_json.py ${file} + done + + cd ../ +done diff --git a/benchmarks/HVRP/run.sh b/benchmarks/HVRP/run.sh new file mode 100755 index 00000000..274fa012 --- /dev/null +++ b/benchmarks/HVRP/run.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Number of threads for solving. +t=8 +# Exploration level. +x=1 +sol_folder="solutions_t_${t}_x_${x}" + +solutions=() + +# Loop over list of folder in input. +for class in "$@" +do + echo "* Solving with ${t} threads and exploration level ${x}, output written to ${class}/${sol_folder}" + mkdir ${class}/${sol_folder} + + for file in `ls ${class}/*.json` + do + base_file=`basename ${file}` + sol_file=${class}/${sol_folder}/${base_file%.json}_sol.json + solutions+=($sol_file) + [ -f ${sol_file} ] || echo "Solving ${file%.json}" + [ -f ${sol_file} ] || vroom -i ${file} -o ${sol_file} -t ${t} -x ${x} + done +done + +echo "* Compare all results to best known solutions." +python ../compare_to_BKS.py BKS.json ${solutions[@]} > ${sol_folder}.csv +echo " - output written to ${sol_folder}.csv" diff --git a/benchmarks/compare_to_BKS.py b/benchmarks/compare_to_BKS.py index fbcfd0f6..0a073475 100755 --- a/benchmarks/compare_to_BKS.py +++ b/benchmarks/compare_to_BKS.py @@ -5,9 +5,25 @@ # Compare a set of computed solutions to best known solutions on the # same problems. -# See src/vrptw_to_json.py and src/pdptw_to_json.py +# See src/vrptw_to_json.py, src/pdptw_to_json.py and +# src/hvrp_to_json.py. CUSTOM_PRECISION = 1000 BENCH_DOUBLE_PRECISION = 100 +CUSTOM_PRECISION_CLASSES = [ + 'solomon', + 'homberger', + 'li_lim', + 'VFMP_V', + 'HFVRP' +] + +def uses_custom_precision(bench): + custom = False + for current_class in CUSTOM_PRECISION_CLASSES: + if current_class in bench: + custom = True + break + return custom def s_round(v, d): if d == 0: @@ -58,14 +74,20 @@ def log_comparisons(BKS, files): BK_cost = indicators['best_known_cost'] bench = indicators['class'] - if 'solomon' in bench or 'homberger' in bench or 'li_lim' in bench: + if uses_custom_precision(bench): BK_cost = int(BENCH_DOUBLE_PRECISION * BK_cost) nb_job = indicators['jobs'] jobs.append(nb_job) nb_vehicle = indicators['vehicles'] vehicles.append(nb_vehicle) - tightness = round(float(indicators['total_amount']) / (nb_vehicle * indicators['capacity']), 3) + + if 'capacity' in indicators: + total_capacity = nb_vehicle * indicators['capacity'] + else: + total_capacity = indicators['total_capacity'] + + tightness = round(float(indicators['total_amount']) / total_capacity, 3) tightnesses.append(tightness) line = [ instance, @@ -88,7 +110,7 @@ def log_comparisons(BKS, files): line.append(len(solution['routes'])) cost = solution['summary']['cost'] - if 'solomon' in bench or 'homberger' in bench or 'li_lim' in bench: + if uses_custom_precision(bench): cost = int(round(BENCH_DOUBLE_PRECISION * float(cost) / CUSTOM_PRECISION)) line.append(cost) diff --git a/src/hvrp_to_json.py b/src/hvrp_to_json.py new file mode 100644 index 00000000..f232aba8 --- /dev/null +++ b/src/hvrp_to_json.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import json, sys, os +from utils.benchmark import * + +# Generate a json-formatted problem from a HVRP file. + +# Those benchmarks use double precision for matrix costs and results +# are usually reported with 2 decimal places. As a workaround, we +# multiply all costs by CUSTOM_PRECISION before performing the usual +# integer rounding. Comparisons in benchmarks/compare_to_BKS.py are +# adjusted accordingly. +CUSTOM_PRECISION = 1000 + +FIRST_LINE = 5 + +def parse_meta(line): + l = line.split() + return { + "JOBS": int(l[0]), + "VEHICLE_TYPES": int(l[1]), + "LOWER_BOUND": float(l[4]), + "BKS": float(l[5]) + } + +def parse_jobs(lines, jobs, coords): + for i in range(len(lines)): + l = lines[i].split() + if len(l) < 3: + print("Too few columns in customer line.") + exit(2) + + current_coords = [int(l[0]), int(l[1])] + jobs.append({ + 'id': i, + 'location': current_coords, + 'location_index': len(coords), + 'delivery': [int(l[2])] + }) + coords.append(current_coords) + +def parse_hvrp(input_file): + with open(input_file, 'r') as f: + lines = f.readlines() + + meta = parse_meta(lines[FIRST_LINE]) + + coords = [] + + # # Useful to generate first draft for BKS file. + # BKS = { + # input_file: { + # "class": "vfmp_v", + # "best_known_cost": meta['BKS'], + # "jobs": meta['JOBS'], + # "total_amount": 0, + # "total_capacity": 0, + # "vehicles": 0 + # } + # } + + # Handle depot and vehicles. + depot_line = lines[FIRST_LINE + 1 + meta['VEHICLE_TYPES']] + coords.append([int(x) for x in depot_line.split()]) + + vehicles = [] + + for v_type in range(1, meta['VEHICLE_TYPES'] + 1): + line = lines[FIRST_LINE + v_type] + l = line.split() + + v_number = int(l[0]) + v_capacity = int(l[1]) + v_fixed_cost = int(l[2]) + v_du_cost = float(l[3]) + + # BKS[input_file]['vehicles'] += v_number + # BKS[input_file]['total_capacity'] += v_number * v_capacity + + if v_fixed_cost != 0: + # Not handled yet! + print("Non-fixed cost!") + exit(1) + + for n in range(v_number): + vehicles.append({ + 'id': v_type * 1000 + n, + 'profile': 'euc_2D', + 'start': coords[0], + 'start_index': 0, + 'end': coords[0], + 'end_index': 0, + 'capacity': [v_capacity], + 'speed_factor': 1/v_du_cost + }) + + jobs = [] + + jobs_start = FIRST_LINE + meta['VEHICLE_TYPES'] + 2 + parse_jobs(lines[jobs_start: jobs_start + meta['JOBS']], jobs, coords) + + matrix = get_matrix(coords, CUSTOM_PRECISION) + + meta['VEHICLES'] = len(vehicles) + + # for n in range(len(jobs)): + # BKS[input_file]['total_amount'] += jobs[n]['delivery'][0] + + # # Uncomment to generate BKS file. + # print(json.dumps(BKS)) + # exit(0) + + return { + 'meta': meta, + 'vehicles': vehicles, + 'jobs': jobs, + 'matrices':{ + 'euc_2D': { + 'durations': matrix + } + } + } + +if __name__ == "__main__": + input_file = sys.argv[1] + instance_name = input_file[:input_file.rfind('.txt')] + output_name = instance_name + '.json' + + print('- Writing problem ' + input_file + ' to ' + output_name) + json_input = parse_hvrp(input_file) + + json_input['meta']['NAME'] = instance_name + + with open(output_name, 'w') as out: + json.dump(json_input, out)