Creates and returns a :class:`~pyvrp._pyvrp.ProblemData` instance from this model's attributes. Parameters ---------- missing_value Distance and duration value to use for missing edges. Defaults to :const:`~pyvrp.constants.MAX_VALUE`,
(self, missing_value: int = MAX_VALUE)
| 451 | return vehicle_type |
| 452 | |
| 453 | def data(self, missing_value: int = MAX_VALUE) -> ProblemData: |
| 454 | """ |
| 455 | Creates and returns a :class:`~pyvrp._pyvrp.ProblemData` instance |
| 456 | from this model's attributes. |
| 457 | |
| 458 | Parameters |
| 459 | ---------- |
| 460 | missing_value |
| 461 | Distance and duration value to use for missing edges. Defaults to |
| 462 | :const:`~pyvrp.constants.MAX_VALUE`, a large number. Note that this |
| 463 | value cannot exceed :const:`~pyvrp.constants.MAX_VALUE`. |
| 464 | """ |
| 465 | locs = self.locations |
| 466 | loc2idx = {id(loc): idx for idx, loc in enumerate(locs)} |
| 467 | |
| 468 | # First we create the base distance and duration matrices. These are |
| 469 | # shared by all routing profiles. |
| 470 | fill_value = min(missing_value, MAX_VALUE) |
| 471 | base_distance = np.full((len(locs), len(locs)), fill_value, np.int64) |
| 472 | base_duration = np.full((len(locs), len(locs)), fill_value, np.int64) |
| 473 | np.fill_diagonal(base_distance, 0) |
| 474 | np.fill_diagonal(base_duration, 0) |
| 475 | |
| 476 | for edge in self._edges: |
| 477 | frm = loc2idx[id(edge.frm)] |
| 478 | to = loc2idx[id(edge.to)] |
| 479 | base_distance[frm, to] = edge.distance |
| 480 | base_duration[frm, to] = edge.duration |
| 481 | |
| 482 | # Now we create the profile-specific distance and duration matrices. |
| 483 | # These are based on the base matrices. |
| 484 | distances = [] |
| 485 | durations = [] |
| 486 | for profile in self._profiles: |
| 487 | prof_distance = base_distance.copy() |
| 488 | prof_duration = base_duration.copy() |
| 489 | |
| 490 | for edge in profile.edges: |
| 491 | frm = loc2idx[id(edge.frm)] |
| 492 | to = loc2idx[id(edge.to)] |
| 493 | prof_distance[frm, to] = edge.distance |
| 494 | prof_duration[frm, to] = edge.duration |
| 495 | |
| 496 | distances.append(prof_distance) |
| 497 | durations.append(prof_duration) |
| 498 | |
| 499 | # When the user has not provided any profiles, we create an implicit |
| 500 | # first profile from the base matrices. |
| 501 | if not self._profiles: |
| 502 | distances = [base_distance] |
| 503 | durations = [base_duration] |
| 504 | |
| 505 | return ProblemData( |
| 506 | self._clients, |
| 507 | self._depots, |
| 508 | self.vehicle_types, |
| 509 | distances, |
| 510 | durations, |