The Travelling Salesperson Problem

Plots

Plot the following graphs of the evolution process:

  • Error bars graph (raw scores).
  • Error bars graph (fitness scores).
  • Max/min/avg/std. dev. graph (raw scores).
  • Max/min/avg/std. dev. graph (fitness scores).
  • Raw and Fitness min/max difference graph.

In [ ]:
%matplotlib inline
from pyevolve_plot import plot_errorbars_raw, plot_errorbars_fitness, \
                          plot_maxmin_raw, plot_maxmin_fitness, \
                          plot_diff_raw, plot_pop_heatmap_raw

In [ ]:
plot_errorbars_raw('tsp.db','ex1')

In [ ]:
plot_errorbars_fitness('tsp.db','ex1')

In [ ]:
plot_maxmin_raw('tsp.db','ex1')

In [ ]:
plot_maxmin_fitness('tsp.db','ex1')

In [ ]:
plot_diff_raw('tsp.db','ex1')

 Route images

Plot the images of the routes stored in the 'tspimg' folder.


In [ ]:
import matplotlib.pyplot as plt
from PIL import Image

In [ ]:
import glob
images = glob.glob("tspimg/tsp_result_*.png")

In [ ]:
for im in images:
    tsp_result = Image.open(im)
    print("Generation %d" % int(im[18:-4]))
    plt.imshow(tsp_result)
    plt.show()

In [ ]:
print('Final best individual')
tsp_result = Image.open('tspimg/tsp_result.png')
plt.imshow(tsp_result);

In [ ]: