liveBook · Manning

Genetic operation

As explained in Optimization Algorithms: AI techniques for design, planning, and control problems

A genetic operator is a variation operation that modifies or combines candidate individuals to generate evolutionary alternatives.

A genetic operation creates candidate solutions from selected parents in an evolutionary search. The two main operations are crossover, which combines parts of parents, and mutation, which introduces random changes. Together they let a population test alternatives rather than rely only on its initial candidates. section 7.2.3 section 7.1

In a binary genetic algorithm, apply the operations after parent selection:

  • Crossover: choose whether to cross two parents, then choose a split point and exchange chromosome segments. A crossover probability controls how often this happens. section 7.4
  • Mutation: inspect genes and flip a bit when its mutation-probability test succeeds. Random changes add diversity and can help prevent stagnation. section 7.2.3 section 7.4
  • Evaluate the resulting candidates with the fitness function, then select survivors for the next generation. An offspring need not be new or better: crossover can reproduce an existing solution. section 7.2.3 section 7.3.5

Ticket-price chromosomes

Suppose ticket prices are encoded as eight-bit chromosomes. Crossing 01001101 (77) and 10010001 (145) after the third bit can produce 01010001 (81): the first three bits come from one parent, the remaining five from the other. This is a possible combination, not a guarantee of improved profit. In the worked population, mutation also changes the chromosome for 77 into a candidate for 103; fitness and survivor selection determine whether such candidates persist. section 7.3.2 section 7.3.5

Choose operators to suit the representation: binary, real-valued, and permutation candidates call for different handling. Operator settings also affect the balance between exploring different candidates and staying near existing ones. For the ticket-pricing implementation, a binary GA uses one-point crossover and bit mutation; a pymoo version instead configures point crossover, polynomial mutation, and rounding repair. Treat probabilities as settings to experiment with, not universal defaults. section 7.2.3 section 7.4 section 8.0 section 7.3.5

problem = TicketPrice()                                                  #1
algorithm = GA(
    pop_size=100,
    sampling=FloatRandomSampling(),
    crossover=PointCrossover(prob=0.8, n_points=2),
    mutation = PolynomialMutation(prob=0.3, repair=RoundingRepair()),
    eliminate_duplicates=True
)                                                                        #2
  
res = minimize(problem, algorithm, ('n_gen', 100), seed=1, verbose=True) #3
  
print(f"Optimal ticket price ($): {res.X}")                              #4
print(f"Profit ($): {-res.F}")                                           #5

The pymoo configuration shows where crossover probability, mutation probability, rounding repair, and population size enter a practical GA run. section 7.4

How Optimization Algorithms: AI techniques for design, planning, and control problems covers it

How deep it goes
Works through binary one-point crossover and bit mutation in Python, then configures alternative operators in pymoo.
Examples
Uses eight-bit ticket-price candidates, generated offspring, a binary Python GA, and a pymoo GA configuration.
What it assumes
Assumes basic Python for implementation while developing binary chromosome encoding, fitness evaluation, and parent selection in the ticket-price example.
What you can do after
Build it from scratch in Python with crossover and mutation, or apply configured operators via pymoo.
How it connects
Links crossover and mutation to chromosome representation, fitness functions, parent selection, survivor selection, and exploration versus exploitation.

Also explained in

Compare how 2 books explain genetic operation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Optimization Algorithms: AI techniques for design, planning, and control problems. The section links point to the parts of the book it draws on.