89
GENETIC ALGORITHMS PROGRAMMING BY THE SEAT OF YOUR GENES! JEREMY FISHER @THISISROOT JUNE 29, 2016

Genetic Algorithms: Programming by the Seat of Your Genes

Embed Size (px)

Citation preview

Page 1: Genetic Algorithms: Programming by the Seat of Your Genes

GENETIC ALGORITHMS

PROGRAMMING BY THE SEAT OF YOUR GENES!

JEREMY FISHER

!@THISISROOT

JUNE 29, 2016

Page 2: Genetic Algorithms: Programming by the Seat of Your Genes

Genetic algorithms are a biologically inspired stochastic metaheuristic for

combinatorial search and optimization.

Page 3: Genetic Algorithms: Programming by the Seat of Your Genes

Genetic algorithms are a biologically inspired stochastic metaheuristic for

combinatorial search and optimization fancy method of trial-and-error.

Page 4: Genetic Algorithms: Programming by the Seat of Your Genes

EVOLUTIONARY ALGORITHM COMPLEXITY

Binary encoding Single Point Crossover Uniform Crossover Proportionate Selection Tournament Selection

List Encoding Value Encoding Permutation Encoding Parallel GAs Ordered Crossover Partially Matched Crossover

Cycle Crossover Tree Encoding Edge Recombination Distributed GAs Multi-Objective Fitness Functions Diploidism

Coevolutionary Algorithms Genetics-Based Machine Learning Genetic Programming Estimation of Distribution Algorithms

BEGINNER ADVANCEDINTERMEDIATE

Page 5: Genetic Algorithms: Programming by the Seat of Your Genes

GENETIC ALGORITHMS IN THE WILDOperations Research

Sociology

Game Theory

Economics

Financial Trading

Biology

Page 6: Genetic Algorithms: Programming by the Seat of Your Genes

GENETIC ALGORITHM LIFECYCLE1. Create a population of random

chromosomes (solutions).

2. Score each chromosome in the population for fitness.

3. Create a new generation through mutation and crossover.

4. Repeat until done.

5. Emit the fittest chromosome as the solution.

⋆⋆⋆ ⋆⋆⋆⋆⋆⋆ ⋆⋆⋆

⋆⋆⋆ ⋆⋆⋆⋆⋆⋆ ⋆⋆⋆

⋆⋆⋆ ⋆⋆⋆⋆⋆⋆ ⋆⋆⋆

⋆⋆⋆

Page 7: Genetic Algorithms: Programming by the Seat of Your Genes

TERMINOLOGY

… 1 0 10Chromosome a.k.a.

Genotype, Organism, Creature, Member, Individual, Solution

Allele

Locus

Page 8: Genetic Algorithms: Programming by the Seat of Your Genes

TERMINOLOGY

-3 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3

-0.8

0.8

1.6

2.4

3.2

Fitness Landscape

Page 9: Genetic Algorithms: Programming by the Seat of Your Genes

!https://github.com/rawg/levis

Page 10: Genetic Algorithms: Programming by the Seat of Your Genes

0/1 KNAPSACK PROBLEM

Given a set of items, each with a quantified weight and value ($), what combination of items will:

1. Fit inside a knapsack capable of carrying a fixed amount of weight?

2. Maximize the value of the knapsack’s payload?

15 lbs

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 11: Genetic Algorithms: Programming by the Seat of Your Genes

ENCODING SCHEMES

1 0 0 1 0 1 1 0

BINARY ENCODING

10 3 22 19 65 97 22 41

VALUE ENCODING

A B C D E F G H

PERMUTATION ENCODING

G C F A B D E H

10 3 22 19

LIST ENCODING

19 65 97 35 41 10

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 12: Genetic Algorithms: Programming by the Seat of Your Genes

0/1 KNAPSACK PROBLEM

A

10 lbs | $11

B4 lbs | $8

C5 lbs | $6

D2 lbs | $12

15 lbsE

8 lbs | $5

F2 lbs | $8

G6 lbs | $4

H

7 lbs | $13

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 13: Genetic Algorithms: Programming by the Seat of Your Genes

BINARY ENCODING

A B C D E F G H

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 14: Genetic Algorithms: Programming by the Seat of Your Genes

BINARY ENCODING

A B C D E F G H

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 15: Genetic Algorithms: Programming by the Seat of Your Genes

BINARY ENCODING

A B C D E F G H10 lbs

$114 lbs $8

5 lbs $6

2 lbs $12

8 lbs $5

2 lbs $8

6 lbs $4

7 lbs $13

1 0 1 0 1 0 1 0

WEIGHT: 29 lbs VALUE: $26

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 16: Genetic Algorithms: Programming by the Seat of Your Genes

INITIALIZE THE POPULATION

1 0 1 1 0 1 1 0

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 17: Genetic Algorithms: Programming by the Seat of Your Genes

INITIALIZE THE POPULATION

1 0 1 1 0 1 1 01 1

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 18: Genetic Algorithms: Programming by the Seat of Your Genes

INITIALIZE THE POPULATION

1 0 1 1 0 0 0 0

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 19: Genetic Algorithms: Programming by the Seat of Your Genes

INITIALIZE THE POPULATION

0 0 1 1 0 1 0 1

7. SOLUTION6. MUTATION5. CROSSOVER4. FITNESS3. CREATION3. CREATION2. ENCODING1. PROBLEM 7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 20: Genetic Algorithms: Programming by the Seat of Your Genes

FITNESS FUNCTION

Maximize value

Maximize weight to limit

def score(self, chromosome): weight, value = self.assess(chromosome)

if weight > self.max_weight: return 0.0

if value <= 0: return 0.0

wt = 1 / (1 + self.max_weight - weight) vl = 1 - 1 / value return wt + vl * self.value_bias

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 21: Genetic Algorithms: Programming by the Seat of Your Genes

FITNESS FUNCTION

def score(self, chromosome): weight, value = self.assess(chromosome)

if weight > self.max_weight: return 0.0

return 1 - 1 / value

Maximize value

Don’t exceed weight limit

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 22: Genetic Algorithms: Programming by the Seat of Your Genes

FITNESS FUNCTION

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-1

-0.75

-0.5

-0.25

0.25

0.5

0.75

1

1.25

1.5

1.75

2

2.25

2.5

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

y=1-1/xy=x

Page 23: Genetic Algorithms: Programming by the Seat of Your Genes

PROPORTIONATE SELECTION

1 0 1 1 0 1 10 0 0 1 0 1 1 01 1 0 0 1 1 1 10 0 1 1 1 1 0 10

1 0 0 1 0 0 11 1 1 0 1 0 0 10 0 0 1 0 0 1 10 1 0 0 1 0 1 11

$40 $30 $25 $20

$20 $15 $10 $5

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 24: Genetic Algorithms: Programming by the Seat of Your Genes

PROPORTIONATE SELECTION

$40 $30 $25 $20 $20 $15 $10 $5

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 25: Genetic Algorithms: Programming by the Seat of Your Genes

PROPORTIONATE SELECTION

Most direct path to convergence

Enables elitism

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 26: Genetic Algorithms: Programming by the Seat of Your Genes

TOURNAMENT SELECTION

1 0 1 1 0 1 10 0 0 1 0 1 1 01 1 0 0 1 1 1 10 0 1 1 1 1 0 10

1 0 0 1 0 0 11 1 1 0 1 0 0 10 0 0 1 0 0 1 10 1 0 0 1 0 1 11

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 27: Genetic Algorithms: Programming by the Seat of Your Genes

TOURNAMENT SELECTION

1 0 1 1 0 1 10 0 0 1 0 1 1 01 1 0 0 1 1 1 10 0 1 1 1 1 0 10

1 0 0 1 0 0 11 1 1 0 1 0 0 10 0 0 1 0 0 1 10 1 0 0 1 0 1 11

$30 $20

$15

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 28: Genetic Algorithms: Programming by the Seat of Your Genes

TOURNAMENT SELECTION

1 0 1 1 0 1 10 0 0 1 0 1 1 01 1 0 0 1 1 1 10 0 1 1 1 1 0 10

1 0 0 1 0 0 11 1 1 0 1 0 0 10 0 0 1 0 0 1 10 1 0 0 1 0 1 11

$30 $20

$15

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 29: Genetic Algorithms: Programming by the Seat of Your Genes

TOURNAMENT SELECTION

Fewer fitness function invocations

Built-in scaling

1 0 1 1 0 1 10 0 0 1 0 1 1 01 1 0 0 1 1 1 10 0 1 1 1 1 0 10

1 0 0 1 0 0 11 1 1 0 1 0 0 10 0 0 1 0 0 1 10 1 0 0 1 0 1 11

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 30: Genetic Algorithms: Programming by the Seat of Your Genes

SINGLE-POINT CROSSOVER

1 0 1 1 0 1 0 1

1 1 0 1 1 1 1 0X

0 1 0 1

1 1 0 1 1 1 1 0

1 0 1 1

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 31: Genetic Algorithms: Programming by the Seat of Your Genes

SINGLE-POINT CROSSOVER

1 0 1 1 0 1 0 1

1 1 0 1 1 1 1 0X

0 1 0 1

1 1 0 1

1 1 1 01 0 1 1

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 32: Genetic Algorithms: Programming by the Seat of Your Genes

UNIFORM CROSSOVER

1 0 1 1 0 1 0 1

1 1 0 1 1 1 1 0X

1 0 1

1 1 0 1 1 1 0

1 0 1 1 0

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 33: Genetic Algorithms: Programming by the Seat of Your Genes

UNIFORM CROSSOVER

1 0 1 1 0 1 0 1

1 1 0 1 1 1 1 0X

1

0

1

1

1

0

1

1

1 01

0

1

1

0

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 34: Genetic Algorithms: Programming by the Seat of Your Genes

COMPARISON

SINGLE POINT CROSSOVER UNIFORM CROSSOVER

num_items=64, population_size=10, iterations=15, elitism=0, seed=“Knapsack01”

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Best Mean WorstBest Mean Worst

Page 35: Genetic Algorithms: Programming by the Seat of Your Genes

MEASURING PERFORMANCE

Solution fitness

Clock time to converge

Iterations to converge

Number of solutions explored

Inheritability

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 36: Genetic Algorithms: Programming by the Seat of Your Genes

POINT MUTATION

1 0 0 1 0 1 1 00

1

X

1 0 0 1 1 1 0

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 37: Genetic Algorithms: Programming by the Seat of Your Genes

7. SOLUTION

SOLUTION

6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

0 0 0 0 1 0 0 1 1 0 1 0 0 0 0 0

0 0 1 1 1 0 0 0 0 0 1 1 0 1 1 0

Page 38: Genetic Algorithms: Programming by the Seat of Your Genes

7. SOLUTION

SOLUTION

6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

0 0 1 1 0 1 1 0

A B C D E F G H10 lbs

$114 lbs $8

5 lbs $6

2 lbs $12

8 lbs $5

2 lbs $8

6 lbs $4

7 lbs $13

WEIGHT: 15 lbs VALUE: $30

Page 39: Genetic Algorithms: Programming by the Seat of Your Genes

SEATING CHART PROBLEM

What seating arrangement will:

1. Seat people of the same job together?

2. Separate loud jobs from quiet jobs?

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 40: Genetic Algorithms: Programming by the Seat of Your Genes

SEATING CHART PROBLEMID Name Role Seat0 Sandra Rodgers Engineer 01 Kirk Spence Engineer 32 Terry Burton Engineer 23 Cindy Hill Engineer 44 Steve Thompson Engineer 65 Laura Juel Engineer 56 Emily Cook Engineer C7 Daniel Barrett Manager 88 Cedric White Manager 99 Emily Grimaud Sales E10 Joseph Johnson Sales B11 Raymond Seery Sales F

0 1

4

2 3

8

C

5 6 7

9 A B

D E F

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 41: Genetic Algorithms: Programming by the Seat of Your Genes

PERMUTATION ENCODINGID Name Role Seat0 Sandra Rodgers Engineer 01 Kirk Spence Engineer 32 Terry Burton Engineer 23 Cindy Hill Engineer 44 Steve Thompson Engineer 65 Laura Juel Engineer 56 Emily Cook Engineer C7 Daniel Barrett Manager 88 Cedric White Manager 99 Emily Grimaud Sales E10 Joseph Johnson Sales B11 Raymond Seery Sales F

0 1

4

2 3

8

C

5 6 7

9 A B

D E F

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 42: Genetic Algorithms: Programming by the Seat of Your Genes

PERMUTATION ENCODING

0 12 3 45 67 8 910 11

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 43: Genetic Algorithms: Programming by the Seat of Your Genes

PERMUTATION ENCODING

0 12 3 45 67 8 910 1112 13 14 15

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 44: Genetic Algorithms: Programming by the Seat of Your Genes

NAÏVE VECTORIZATION0 1

4

2 3

8

C

5 6 7

9 A B

D E F

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 45: Genetic Algorithms: Programming by the Seat of Your Genes

HILBERT VECTORIZATION0 1

3

E F

4

5

2 D C

7 8 B

6 9 A

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 46: Genetic Algorithms: Programming by the Seat of Your Genes

PRESERVING LOCALITY

NAÏVE VECTORIZATION HILBERT VECTORIZATION

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 150 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

vector index

dist

ance

to

orig

in

vector index

dist

ance

to

orig

in

Page 47: Genetic Algorithms: Programming by the Seat of Your Genes

PERFORMANCE COMPARISON

NAÏVE VECTORIZATION HILBERT VECTORIZATION

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

map_size=7x7, population_size=200, iterations=30, elitism=0, seed=“SeatingChart”, crossover=PMX

Best Mean Worst Best Mean Worst

Page 48: Genetic Algorithms: Programming by the Seat of Your Genes

INITIALIZE THE POPULATION

2 6 0 1 4 7 3 5

1 7 5 0 4 2 3 6

7 3 1 0 2 6 5 4

7. SOLUTION6. MUTATION5. CROSSOVER4. FITNESS3. CREATION3. CREATION2. ENCODING1. PROBLEM 7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 49: Genetic Algorithms: Programming by the Seat of Your Genes

FITNESS FUNCTION0 1

4

2 3

C

5 6 7

A B

D E F

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

8 9

Page 50: Genetic Algorithms: Programming by the Seat of Your Genes

FITNESS FUNCTION0 1

4

2 3

C

5 6 7

A B

D E F

44.033.411.00

48.44

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

8 9

Page 51: Genetic Algorithms: Programming by the Seat of Your Genes

FITNESS FUNCTION0 1

4

2 3

8

C

5 6 7

9 A B

D E F

30.38

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 52: Genetic Algorithms: Programming by the Seat of Your Genes

FITNESS FUNCTION0 1

4

2 3

8

C

5 6 7

9 A B

D E F

-30.3848.44

18.06

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 53: Genetic Algorithms: Programming by the Seat of Your Genes

FITNESS FUNCTION

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

def score(self, chromosome): seats_role = self.seats_by_role(chromosome)

# Tally attractive score attraction = 0.0 for role, coords in seats_role.iteritems(): attraction += spatial.total_edge_length(coords)

# Tally repulsive score repulsion = 0.0 for role, repulsors in self.repulsion.iteritems(): …

return self.max_distance - attraction + repulsion

Page 54: Genetic Algorithms: Programming by the Seat of Your Genes

ORDERED CROSSOVER (OX)

X

2 6 0 1 4 7 3 5

1 7 5 0 4 2 3 67 5 4 3

2 6 0 1

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 55: Genetic Algorithms: Programming by the Seat of Your Genes

ORDERED CROSSOVER (OX)

X

2 6 0 1 4 7 3 5

1 7 5 0 4 2 3 67 5 4 3

2 6 0 1

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 56: Genetic Algorithms: Programming by the Seat of Your Genes

ORDERED CROSSOVER (OX)

X

2 6 0 1 4 7 3 5

1 7 5 0 4 2 3 6

7 5 4 32 6 0 1

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 57: Genetic Algorithms: Programming by the Seat of Your Genes

PARTIALLY MATCHED CROSSOVER (PMX)

X

2 6 0 1 4 7 3 5

0 1 5 7 42 3 6

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

5 7 2

Page 58: Genetic Algorithms: Programming by the Seat of Your Genes

PARTIALLY MATCHED CROSSOVER (PMX)

X

2 6 0 1 4 7 3 5

0 1 5 7 42 3 6

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

5 7 2

Page 59: Genetic Algorithms: Programming by the Seat of Your Genes

PARTIALLY MATCHED CROSSOVER (PMX)

X

2 6 0 1 4 7 3 5

0 1 5 7 42 3 6

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

5 7 2

0

Page 60: Genetic Algorithms: Programming by the Seat of Your Genes

PARTIALLY MATCHED CROSSOVER (PMX)

X

2 6 0 1 4 7 3 5

0 1 5 7 42 3 6

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

5 7 2 0

Page 61: Genetic Algorithms: Programming by the Seat of Your Genes

PARTIALLY MATCHED CROSSOVER (PMX)

X

2 6 0 1 4 7 3 5

0 1 5 7 42 3 6

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

5 7 2 0

1

Page 62: Genetic Algorithms: Programming by the Seat of Your Genes

PARTIALLY MATCHED CROSSOVER (PMX)

X

2 6 0 1 4 7 3 5

0 1 5 7 42 3 6

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

5 7 2 01

Page 63: Genetic Algorithms: Programming by the Seat of Your Genes

PARTIALLY MATCHED CROSSOVER (PMX)

X

2 6 0 1 4 7 3 5

0 1 5 7 42 3 6

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

5 7 2 01

4

Page 64: Genetic Algorithms: Programming by the Seat of Your Genes

PARTIALLY MATCHED CROSSOVER (PMX)

X

2 6 0 1 4 7 3 5

0 1 5 7 42 3 6

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

5 7 2 014

Page 65: Genetic Algorithms: Programming by the Seat of Your Genes

PARTIALLY MATCHED CROSSOVER (PMX)

X

2 6 0 1 4 7 3 5

0 1 5 7 42 3 6

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

5 7 2 014

6 3

Page 66: Genetic Algorithms: Programming by the Seat of Your Genes

PARTIALLY MATCHED CROSSOVER (PMX)

X

2 6 0 1 4 7 3 5

0 1 5 7 42 3 6

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

5 7 2 014 6 3

Page 67: Genetic Algorithms: Programming by the Seat of Your Genes

PERFORMANCE COMPARISON

ORDERED PARTIALLY MATCHED

7. SOLUTION6. MUTATION5. CROSSOVER

map_size=7x7, population_size=200, iterations=30, elitism=0, seed=“SeatingChart”, map_type=naive

Best Mean Worst Best Mean Worst

4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 68: Genetic Algorithms: Programming by the Seat of Your Genes

SWAP MUTATION

X 2 6 0 1 4 7 3 5

2 60 14 7 3 5

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 69: Genetic Algorithms: Programming by the Seat of Your Genes

SOLUTION

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 70: Genetic Algorithms: Programming by the Seat of Your Genes

SOLUTION

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 71: Genetic Algorithms: Programming by the Seat of Your Genes

SOLUTION

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 72: Genetic Algorithms: Programming by the Seat of Your Genes

SOLUTION

7. SOLUTION6. MUTATION5. CROSSOVER4. SELECTION3. FITNESS2. CREATION1. ENCODING0. PROBLEM

Page 73: Genetic Algorithms: Programming by the Seat of Your Genes

UNBOUNDED KNAPSACK PROBLEM

Given a set of items, each with a quantified weight and value ($), what combination of those items in any amounts will:

1. Fit inside a knapsack capable of carrying a fixed amount of weight?

2. Maximize the value of the knapsack’s payload?

15 lbs

Page 74: Genetic Algorithms: Programming by the Seat of Your Genes

UNBOUNDED KNAPSACK PROBLEM

A

10 lbs | $11

B4 lbs | $8

C5 lbs | $6

D2 lbs | $12

20 lbsE

8 lbs | $5

F2 lbs | $8

G6 lbs | $4

H

7 lbs | $13

Page 75: Genetic Algorithms: Programming by the Seat of Your Genes

LIST ENCODING

B D E F H

B D E F

A B D E HH

B D AC

E H A

Page 76: Genetic Algorithms: Programming by the Seat of Your Genes

UNBOUNDED KNAPSACK PROBLEM

Encoding ListCrossover Cut and Splice / Single Point

Selection ProportionateMutation Point

Page 77: Genetic Algorithms: Programming by the Seat of Your Genes

TRAVELING SALESMAN PROBLEM

Minimize the total distance required to visit all stops along a route.

Page 78: Genetic Algorithms: Programming by the Seat of Your Genes

TRAVELING SALESMAN PROBLEM

Encoding PermutationCrossover Ordered or Edge Recombination

Selection ProportionateMutation Swap

Page 79: Genetic Algorithms: Programming by the Seat of Your Genes

NURSE SCHEDULING PROBLEM

There must always be n nurses scheduled.

A nurse cannot be scheduled while on PTO.

A nurse cannot be scheduled for more than two consecutive shifts.

A nurse should have at least two shifts off between scheduled shifts.

A nurse’s shift preferences should be respected.

7 days / week 3 shifts / day

Page 80: Genetic Algorithms: Programming by the Seat of Your Genes

NURSE SCHEDULING PROBLEM

Name Shift Mon Tue Wed Thu Fri Sat SunGrace 1Constance 3 PTO PTORonald 2Robyn 2 PTO PTOJudy 1Amy 1, 2Brad 3Valarie 1 PTOJames 2Thelma 2, 3 PTO… … … … … … … … …

Page 81: Genetic Algorithms: Programming by the Seat of Your Genes

NURSE SCHEDULING PROBLEM

Encoding Binary (with constraints)Crossover Single Point Crossover

Selection ProportionateMutation Point

Page 82: Genetic Algorithms: Programming by the Seat of Your Genes

ENCODING CONSTRAINTS

1 0

Grace

0

Mon1 2 3

Tues

1 0

1 2 …

… 0 1

Constance

0

Mon1 2 3

Thurs

1 0

1 2 3

1 …

…… …Shift

Day

Page 83: Genetic Algorithms: Programming by the Seat of Your Genes

WHEN TO EVOLVE

Use a GA on problems when:

There may not be an exact solution

Search spaces are large

The fitness landscape is complex

The best solutions lie on a Pareto front

Page 84: Genetic Algorithms: Programming by the Seat of Your Genes

GENETIC ALGORITHMS

SIMULATED ANNEALINGVS

Finds better solutions

Global search

Easily parallelized

Broader applications

Finds solutions faster

Local search

Page 85: Genetic Algorithms: Programming by the Seat of Your Genes

GENETIC ALGORITHMS

BRANCH & BOUNDVS

Approximate solutions

Better able to cope with large, complex problems

Best solution, guaranteed

Limited to small problems

O(n log n)

Page 86: Genetic Algorithms: Programming by the Seat of Your Genes

GENETIC ALGORITHMS

GRADIENT DESCENTVS

Discrete optimization

Wins at complex fitness landscapes

No calculus required =)

Continuous optimization

Wins at speed

Page 87: Genetic Algorithms: Programming by the Seat of Your Genes

GENETIC ALGORITHMS

NEURAL NETWORKSVS

Optimization

Classification (GBML)

Human Comparable Design

Classification†

Pattern recognition

† Also for screenplay creation

Page 88: Genetic Algorithms: Programming by the Seat of Your Genes

FURTHER READING

Page 89: Genetic Algorithms: Programming by the Seat of Your Genes

LIFE FINDS A WAY…

Special Thanks To:

Brook Graham Dr. Wes Kerr Kyle Putnam

Paul Sipe Jennifer Wadella