January 2019
Intermediate to advanced
236 pages
5h 41m
English
You can run the genetic algorithm like this:
| | def fire(): |
| | epochs = 10 |
| | items = 12 |
| | height = 5 |
| | width = 10 |
| | |
| | generation = random_tries(items) |
| | generation0 = list(generation) # save to contrast with last epoch |
| | |
| | for i in range(1, epochs): |
| | results = [] |
| | generation = crossover(generation, width) |
| | mutate(generation) |
| | |
| | display_start_and_finish(generation0, generation, height, width) |
What you do in the display function is up to you. Plotting plots the arcs of the cannonballs from the first and last generation, so shows any improvement on the initial random attempts. There are other ways to assess your solutions. Counting discusses a few things worth counting at each epoch to see if the GA is learning. ...
Read now
Unlock full access