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.

Parameters:
data: ProblemData

Data instance.

title: str = 'Coordinates'

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_demands(data: ProblemData, title: str | None = None, ax: Axes | None = None)[source]

Plots demands for clients, as vertical bars sorted by demand.

Parameters:
data: ProblemData

Data instance.

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_diversity(result: Result, ax: Axes | None = None)[source]

Plots population diversity statistics.

Parameters:
result: Result

Result for which to plot diversity.

ax: Axes | None = None

Axes object to draw the plot on. One will be created if not provided.

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]) where best 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.

Parameters:
result: Result

Result to be plotted.

data: ProblemData

Data instance underlying the result’s solution.

fig: Figure | None = None

Optional Figure to draw on. One will be created if not provided.

plot_route_schedule(data: ProblemData, route: Route, 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.

Parameters:
data: ProblemData

Data instance for which to plot the route schedule.

route: Route

Route (list of clients) whose schedule to plot.

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_runtimes(result: Result, ax: Axes | None = None)[source]

Plots iteration runtimes.

Parameters:
result: Result

Result for which to plot runtimes.

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.

plot_time_windows(data: ProblemData, title: str = 'Time windows', ax: Axes | None = None)[source]

Plots client time windows, as vertical bars sorted by time window.

Parameters:
data: ProblemData

Data instance.

title: str = 'Time windows'

Title to add to the plot.

ax: Axes | None = None

Axes object to draw the plot on. One will be created if not provided.