Skip to content

Commit bb2eebf

Browse files
committed
PyVRP - Modulate min_penalty
1 parent 5a76a01 commit bb2eebf

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

wrappers/pyvrp_wrapper.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import math
23
import sys
34
import numpy as np
45
from pyvrp import Model, ProblemData, Client, Depot, VehicleType, ClientGroup, SolveParams, PenaltyParams
@@ -34,7 +35,14 @@ def main(input_path, output_path, timeout=None):
3435
data = ProblemData.from_dict(json_data)
3536
m = Model.from_data(data)
3637
# Solve the problem
37-
penalty_params = PenaltyParams(min_penalty=1e10, max_penalty=1e10)
38+
# ProblemData exposes clients as a method, not as a list attribute.
39+
clients = list(data.clients())
40+
# Closest power of two for the number of clients (rounded to nearest).
41+
num_clients = len(clients)
42+
closest_power_two_exponent = 0 if num_clients <= 0 else round(math.log(num_clients, 3))
43+
min_penalty = 10 ** (1 + closest_power_two_exponent)
44+
penalty_params = PenaltyParams(min_penalty=min_penalty, max_penalty=1e10)
45+
# penalty_params = PenaltyParams(min_penalty=smallest_prize * 1e-5, max_penalty=cumulated_prizes * 1e-2)
3846
solve_params = SolveParams(penalty=penalty_params)
3947
result = m.solve(stop=MaxRuntime(int(timeout)), params=solve_params)
4048

0 commit comments

Comments
 (0)