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)
Plots coordinates for clients and depot.
- Parameters:
- data
Data instance.
- title, optional
Title to add to the plot.
- ax, optional
Axes object to draw the plot on. One will be created if not provided.
- plot_demands(data: ProblemData, title: str | None = None, ax: Axes | None = None)
Plots demands for clients, as vertical bars sorted by demand.
- Parameters:
- data
Data instance.
- title, optional
Title to add to the plot.
- ax, optional
Axes object to draw the plot on. One will be created if not provided.
- plot_diversity(result: Result, ax: Axes | None = None)
Plots population diversity statistics.
- Parameters:
- result
Result for which to plot diversity.
- ax, optional
Axes object to draw the plot on. One will be created if not provided.
- Raises:
StatisticsNotCollectedError
Raised when statistics have not been collected.
- plot_instance(data: ProblemData, fig: Figure | None = None)
Plots client coordinate, time window and demand data of the given instance.
- Parameters:
- data
Data instance.
- fig, optional
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))
Plots each subpopulation’s objective values.
- Parameters:
- result
Result for which to plot objectives.
- num_to_skip
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 object to draw the plot on. One will be created if not provided.
- ylim_adjust
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).
- Raises:
StatisticsNotCollectedError
Raised when statistics have not been collected.
- plot_result(result: Result, data: ProblemData, fig: Figure | None = None)
Plots the results of a run, including the best solution and detailed statistics about the algorithm’s performance (if available).
- Parameters:
- result
Result to be plotted.
- data
Data instance underlying the result’s solution.
- fig, optional
Optional Figure to draw on. One will be created if not provided.
- plot_route_schedule(data: ProblemData, route: List[int], legend: bool = True, title: str | None = None, ax: Axes | None = None)
Plots a route schedule. This function plots multiple time statistics as a function of distance traveled:
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.
- Parameters:
- data
Data instance for which to plot the route schedule.
- route
Route (list of clients) whose schedule to plot.
- legend, optional
Whether or not to show the legends. Default True.
- title, optional
Title to add to the plot.
- ax, optional
Axes object to draw the plot on. One will be created if not provided.
- plot_runtimes(result: Result, ax: Axes | None = None)
Plots iteration runtimes.
- Parameters:
- result
Result for which to plot runtimes.
- ax, optional
Axes object to draw the plot on. One will be created if not provided.
- Raises:
StatisticsNotCollectedError
Raised when statistics have not been collected.
- plot_solution(solution: Individual, data: ProblemData, plot_customers: bool = False, ax: Axes | None = None)
Plots the given solution.
- Parameters:
- solution
Solution to plot.
- data
Data instance underlying the solution.
- plot_customers, optional
Whether to plot customers as dots. Default False, which plots only the solution’s routes.
- ax, optional
Axes object to draw the plot on. One will be created if not provided.
- plot_time_windows(data: ProblemData, title: str = 'Time windows', ax: Axes | None = None)
Plots client time windows, as vertical bars sorted by time window.
- Parameters:
- data
Data instance.
- title, optional
Title to add to the plot.
- ax, optional
Axes object to draw the plot on. One will be created if not provided.