Plots client time windows, as vertical bars sorted by time window. Parameters ---------- data Data instance. title Title to add to the plot. ax Axes object to draw the plot on. One will be created if not provided.
(
data: ProblemData,
title: str = "Time windows",
ax: plt.Axes | None = None,
)
| 6 | |
| 7 | |
| 8 | def plot_time_windows( |
| 9 | data: ProblemData, |
| 10 | title: str = "Time windows", |
| 11 | ax: plt.Axes | None = None, |
| 12 | ): |
| 13 | """ |
| 14 | Plots client time windows, as vertical bars sorted by time window. |
| 15 | |
| 16 | Parameters |
| 17 | ---------- |
| 18 | data |
| 19 | Data instance. |
| 20 | title |
| 21 | Title to add to the plot. |
| 22 | ax |
| 23 | Axes object to draw the plot on. One will be created if not provided. |
| 24 | """ |
| 25 | if not ax: |
| 26 | _, ax = plt.subplots() |
| 27 | |
| 28 | tw = np.array([[c.tw_early, c.tw_late] for c in data.clients()]) |
| 29 | |
| 30 | # Lexicographic sort so for equal start we get shorter TW first |
| 31 | tw = tw[np.lexsort((tw[:, 1], tw[:, 0]))] |
| 32 | |
| 33 | lines = [ |
| 34 | ((loc, early), (loc, late)) |
| 35 | for loc, (early, late) in enumerate(tw, data.num_depots - 1) |
| 36 | ] |
| 37 | ax.add_collection(LineCollection(lines, linewidths=1)) |
| 38 | ax.set_xlim([0, data.num_locations]) |
| 39 | ax.set_ylim([tw.min(), tw.max()]) |
| 40 | |
| 41 | ax.set_title(title) |
| 42 | ax.set_xlabel("Client (sorted by TW)") |
| 43 | ax.set_ylabel("Time window") |
no test coverage detected