{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Workbook for Chapter 12 of Explorations in Computing"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Section 12.6: Crossovers"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Execute these cells to initialize the notebook:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from PythonLabs.TSPLab import *"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib tk"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Exercises: "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T66. Create a new map with 20 cities and display it on the canvas:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T67. Call `esearch` to see what kind of tour it can find using point mutations only in 500 generations and a population of 50 tours:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T68. Repeat the previous expression, but this time tell `esearch` to use a combination of point mutations and crossovers:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T69. At this point you might be wondering, if crossovers are so effective, why even have point mutations? Type the expression that tells `esearch` to use only crossover mutations:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T70. Repeat the previous expression a few more times. Do the tours made using only crossovers have anything in common?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"♦ Make a map with 30 cities and draw it on the canvas:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"♦ Call `esearch` using the same parameters you used for the map with 20 cities:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"♦ One way to see if `esearch` can find a better tour is to let it run longer. Repeat the previous expression, but increase the number of generations to 1,000:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"♦ Another possibility for getting a better tour is to use a larger population size. Type this expression to use the original number of generations (500) but twice the population size:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"♦ Do some more experiments on your own. Try increasing the number of generations up to 2,500, and the population size up to 300. In general, which strategy is more effective, letting the search run for more generations or increasing the population size?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"♦ If you want to see how well this genetic algorithm works on larger maps, try making maps of up to 100 cities, and using population sizes of up to 1,000. The canvas only has room for 400 cities, so with more than 100 cities the map will be very crowded. The population size can be as big as you want, but obviously the larger the population size, the longer it will take to make each new generation."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}