mamut_routing_lib.td.pwlf¶
Non-Decreasing Continuous PieceWise Linear Functions (NDCPWLF).
This module is the canonical, pure-Python reference for the function algebra used by the time-dependent (TD) solution checker: arc arrival-time functions, time-window ready-time functions, and their compositions. It is deliberately kept simple and fully deterministic (plain IEEE-754 double arithmetic, no epsilon comparisons) so that it can be reimplemented independently and produce bit-identical results.
Representation: a function is the list of its breakpoints, split into two
parallel arrays xs (non-decreasing) and ys (non-decreasing). Between
two consecutive breakpoints the function is linear. Duplicate xs entries
encode a vertical step; evaluation at a step returns the smallest value.
Steps arise both as floating-point rounding artifacts of composition and as
genuine content of canonical ATFs consolidated from stepwise travel-time data
(e.g. Rifki2020, FIFO-restored by the arrival-time lower envelope: surviving
upward jumps are real steps, and the smallest-value convention is exactly the
envelope's value at the boundary). Duplicate ys entries encode a plateau
(e.g. waiting for a time window to open).
Composition follows the two-pointer event merge of Visser & Spliet (2020), with two deliberate deviations that keep the canonical spec simple:
- no normalization (redundant breakpoints are kept; values are unchanged);
- interpolation is done directly between the two enclosing breakpoints instead of maintaining slope/intercept pairs, and emitted breakpoints are clamped monotone, so the non-decreasing invariant holds structurally under any rounding.
PWLFError
¶
Bases: ValueError
Raised when NDCPWLF invariants are violated.
NDCPWLF
¶
A non-decreasing continuous piecewise linear function.
Immutable by convention: xs and ys must not be mutated after
construction.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
identity
classmethod
¶
The identity function over [low, high].
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
empty
classmethod
¶
is_empty
¶
num_breakpoints
¶
evaluate
¶
Evaluate the function at x (must lie within the domain).
At a vertical step the smallest value is returned.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
compose
¶
Return h = self ∘ g restricted to {x in dom(g) : g(x) in dom(self)}.
Two-pointer event merge over the common value axis
dom(self) ∩ img(g); O(len(self.xs) + len(g.xs)).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
min_shifted_image
¶
Return (min_k (ys[k] - xs[k]), xs[k*]) with k* the earliest argmin.
For a route ready-time function this is the optimal route duration and
the associated optimal depot departure time. The minimum of y - x
over the whole domain is attained at a breakpoint because the shifted
function is linear between breakpoints.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
make_theta
¶
Vertex TW ready-time function θ over arrival times in [0, latest].
θ(t) = max(t, earliest) + service_time: arriving before earliest
waits (plateau), arriving after latest is infeasible (out of domain).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
make_service_theta
¶
Vertex ready-time function θ without a time window, over [0, upper].
θ(t) = t + service_time, no waiting. upper is the largest arrival
time the vertex can see. It shares the dedup of make_theta, so
upper == 0 yields the single point ([0.0], [service_time]) instead
of two equal consecutive points.