Stores an edge connecting two locations. Raises ------ ValueError When either distance or duration is a negative value, or when self loops have nonzero distance or duration values.
| 23 | |
| 24 | |
| 25 | class Edge: |
| 26 | """ |
| 27 | Stores an edge connecting two locations. |
| 28 | |
| 29 | Raises |
| 30 | ------ |
| 31 | ValueError |
| 32 | When either distance or duration is a negative value, or when self |
| 33 | loops have nonzero distance or duration values. |
| 34 | """ |
| 35 | |
| 36 | __slots__ = ["distance", "duration", "frm", "to"] |
| 37 | |
| 38 | def __init__( |
| 39 | self, |
| 40 | frm: Client | Depot, |
| 41 | to: Client | Depot, |
| 42 | distance: int, |
| 43 | duration: int, |
| 44 | ): |
| 45 | if distance < 0 or duration < 0: |
| 46 | raise ValueError("Cannot have negative edge distance or duration.") |
| 47 | |
| 48 | if id(frm) == id(to) and (distance != 0 or duration != 0): |
| 49 | raise ValueError("A self loop must have 0 distance and duration.") |
| 50 | |
| 51 | if max(distance, duration) > MAX_VALUE: |
| 52 | msg = """ |
| 53 | The given distance or duration value is very large. This may impact |
| 54 | numerical stability. Consider rescaling your input data. |
| 55 | """ |
| 56 | warn(msg, ScalingWarning) |
| 57 | |
| 58 | self.frm = frm |
| 59 | self.to = to |
| 60 | self.distance = distance |
| 61 | self.duration = duration |
| 62 | |
| 63 | |
| 64 | class Profile: |