Plotting tools¶
The pyvrp.plotting
module contains various functions for plotting problem instances and solutions to those problem instances.
These can be used to better understand your problem, and to help investigate the solutions returned by the genetic algorithm.
-
plot_coordinates(data: ProblemData, title: str =
'Coordinates'
, ax: Axes | None =None
)[source]¶ Plots coordinates for clients and depot.
-
plot_demands(data: ProblemData, dimension: int =
0
, title: str | None =None
, ax: Axes | None =None
)[source]¶ Plots demands for clients, as vertical bars sorted by demand.
- Parameters:
- Raises:
ValueError – When the load dimension is out of bounds for the given data instance.
-
plot_diversity(result: Result, ax: Axes | None =
None
)[source]¶ Plots population diversity statistics.
-
plot_instance(data: ProblemData, fig: Figure | None =
None
)[source]¶ Plots client coordinate, time window and demand data of the given instance.
- Parameters:
- data: ProblemData¶
Data instance.
- fig: Figure | None =
None
¶ Optional Figure to draw on. One will be created if not provided.
-
plot_objectives(result: Result, num_to_skip: int | None =
None
, ax: Axes | None =None
, ylim_adjust: tuple[float, float] =(0.95, 1.15)
)[source]¶ Plots each subpopulation’s objective values.
- Parameters:
- result: Result¶
Result for which to plot objectives.
- num_to_skip: int | None =
None
¶ Number of initial iterations to skip when plotting. Early iterations often have very high objective values, and obscure what’s going on later in the search. The default skips the first 5% of iterations.
- ax: Axes | None =
None
¶ Axes object to draw the plot on. One will be created if not provided.
- ylim_adjust: tuple[float, float] =
(0.95, 1.15)
¶ Bounds the y-axis to
(best * ylim_adjust[0], best * ylim_adjust[1])
wherebest
denotes the best found feasible objective value. Default (0.95, 1.15).
-
plot_result(result: Result, data: ProblemData, fig: Figure | None =
None
)[source]¶ Plots the results of a run, including the best solution and detailed statistics about the algorithm’s performance.
-
plot_route_schedule(data: ProblemData, route: Route, load_dimension: int =
0
, legend: bool =True
, title: str | None =None
, ax: Axes | None =None
)[source]¶ Plots a route schedule. This function plots multiple time statistics as a function of distance travelled:
Solid: earliest possible trajectory / time, using time warp if the route is infeasible.
Shaded: slack up to latest possible trajectory / time, only if no time warp on the route.
Dash-dotted: driving and service time, excluding wait time and time warp.
Dotted: pure driving time.
Grey shaded background: remaining load in the vehicle for the provided load dimension.
- Parameters:
- data: ProblemData¶
Data instance for which to plot the route schedule.
- route: Route¶
Route (list of clients) whose schedule to plot.
- load_dimension: int =
0
¶ Load dimension to plot. Defaults to the first dimension, if it exists.
- legend: bool =
True
¶ Whether or not to show the legends. Default True.
- title: str | None =
None
¶ Title to add to the plot.
- ax: Axes | None =
None
¶ Axes object to draw the plot on. One will be created if not provided.
-
plot_solution(solution: Solution, data: ProblemData, plot_clients: bool =
False
, ax: Axes | None =None
)[source]¶ Plots the given solution.
- Parameters:
- solution: Solution¶
Solution to plot.
- data: ProblemData¶
Data instance underlying the solution.
- plot_clients: bool =
False
¶ Whether to plot all clients as dots. Default False, which plots only the solution’s routes.
- ax: Axes | None =
None
¶ Axes object to draw the plot on. One will be created if not provided.