-
Notifications
You must be signed in to change notification settings - Fork 39
/
plot_result.py
45 lines (37 loc) · 1.55 KB
/
plot_result.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from typing import Optional
import matplotlib.pyplot as plt
from pyvrp import ProblemData
from pyvrp.Result import Result
from pyvrp.plotting.plot_diversity import plot_diversity
from pyvrp.plotting.plot_objectives import plot_objectives
from pyvrp.plotting.plot_runtimes import plot_runtimes
from pyvrp.plotting.plot_solution import plot_solution
def plot_result(
result: Result, data: ProblemData, fig: Optional[plt.Figure] = None
):
"""
Plots the results of a run, including the best solution and detailed
statistics about the algorithm's performance.
Parameters
----------
result
Result to be plotted.
data
Data instance underlying the result's solution.
fig
Optional Figure to draw on. One will be created if not provided.
"""
if not fig:
fig = plt.figure(figsize=(20, 12))
# Uses a GridSpec instance to lay-out all subplots nicely. There are
# two columns: left and right. Left has three rows, each containing a
# plot with statistics: the first plots population diversity, the
# second subpopulation objective information, and the third iteration
# runtimes. The right column plots the solution on top of the instance
# data.
gs = fig.add_gridspec(3, 2, width_ratios=(2 / 5, 3 / 5))
ax_div = fig.add_subplot(gs[0, 0])
plot_diversity(result, ax=ax_div)
plot_objectives(result, ax=fig.add_subplot(gs[1, 0], sharex=ax_div))
plot_runtimes(result, ax=fig.add_subplot(gs[2, 0], sharex=ax_div))
plot_solution(result.best, data, ax=fig.add_subplot(gs[:, 1]))