liveBook · Manning

Pymoo

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

A Python framework for multi-objective optimization that provides evolutionary algorithms, metaheuristics, visualization tools, and decision-making capabilities.

pymoo is a Python framework for optimization with evolutionary algorithms and other metaheuristics. Despite its multi-objective focus, it can also run a single-objective genetic algorithm (GA). Its available algorithms include GA, differential evolution, evolutionary strategies, NSGA-II, NSGA-III, and particle swarm optimization. section 7.4

A population-based search needs starting candidates. For a two-variable problem bounded between 0 and 1, pymoo can generate 200 candidates with `FloatRandomSampling()` or Latin hypercube sampling through `LHS()`. Calling the sampler with the problem and population size, then retrieving `get("X")`, yields the candidate values. Plotting them helps reveal gaps and dispersion: initialization affects how broadly the search begins. section 7.1

Optimize a ticket price with GA

Define a `Problem` with one variable, bounds of 75–235, and an `_evaluate` method. Because the solver minimizes, set its objective to `20*x*x - 6200*x + 350000`, the negative of the profit function. Configure `GA` with a population of 100, random sampling, point crossover, polynomial mutation with rounding repair, and duplicate elimination. Run `minimize` for 100 generations. The reported price is $155 and its profit is $130,500. This is a single-objective example, not a demonstration of multi-objective optimization. section 7.4

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 configuration listing shows where sampling, crossover, mutation, duplicate elimination, generation count, and seed enter the pymoo run. section 7.4

Use a ready-made GA when the goal is to adapt operators and settings rather than implement selection, crossover, and mutation from scratch. Check that the objective’s sign matches minimization, choose sampling suited to the solution representation, and inspect the returned solution and objective value. section 7.1 section 7.4

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

How deep it goes
Works through sampling and a configured GA run, while implementing a separate binary GA from scratch for comparison.
Examples
Shows 200 sampled two-variable candidates and a ticket-pricing GA that returns a $155 price and $130,500 profit.
What it assumes
Assumes familiarity with Python code, while showing genetic-algorithm operations through a separate implementation before the library-based run.
What you can do after
Apply it via pymoo to sample bounded candidates and configure and run a single-objective genetic algorithm.
How it connects
Connects pymoo to population initialization, Latin hypercube sampling, genetic algorithms, crossover, mutation, and multi-objective optimization.

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.