# Population¶

class PyGMO.population

This class represents the concept of a population as a collection of PyGMO.individual evaluated w.r.t. a PyGMO.problem. A population in PyGMO makes sure that all the individuals it contains are consistent w.r.t. the problem and it constantly keeps its PyGMO.champion updated. Also (relevant only for multi-objective problems) the population, keeps constantly updated 1) a domination list that is a list containing, per individual I, the indexes of the individuals I dominates, and 2) a domination count that is a list containing, per individual I, the number of individuals that dominate individual I. From an evolutionary point of view one can see the population as a set of individuals living in an environment (the problem) which defines their fitness values

__init__((PyGMO.problem)prob[, (int)n_individuals, (int)seed])

Constructs a population containing n_individuals (default is an empty population) evaluated w.r.t. prob. Each individual gets initialized at random with his chromosome in [problem.lb, problem.ub] and his velocity in [(problem.lb-problem.ub)/2, (problem.ub- problem.lb)/2]. The initialization process of the population can be seeded by providing the argument seed.

from PyGMO import *
prob = problem.schwefel(50)
pop1 = population(prob) #empty population
pop2 = population(prob,20) #population with 20 individuals
pop3 = population(prob,20,123) #population with 20 individuals intialized with seed=123

__init__((PyGMO.population)pop)

Constructs a new population performing a deep-copy of a second population pop.

from PyGMO import *
prob = problem.schwefel(50)
pop1 = population(prob,10) #population with 10 individuals
pop2 = population(pop1)    #a second identical population with 10 individuals
#(the problem and the individuals are copies of the original pop1)

push_back((list) x)

Appends an individual having chromosme x to the population, if compatible with the problem. Its velocity is initialized at random, its memory is set equal to the current position.

NOTE: There is no way to push_back into a population directly an PyGMO.individual This design choice was made as there would be no way to ensure efficiently that the information contained in the PyGMO.individual is consistent (if not by wasting one function evaluation) with the PyGMO.problem defining the population

from PyGMO import *
prob = problem.schwefel(2)
pop = population(prob)
pop.push_back([1.12,2.34])

erase((int) idx)

Erases the individual with index idx from the population. Domination list and domination count are updated accordingly.

NOTE: after such an operation all indexes will be renamed so that if the individual with idx = n is erased, after the erase has completed the individual that had idx=n+1 will have idx = n

from PyGMO import *
prob = problem.schwefel(2)
pop = population(prob,5)
pop.erase(0)

set_x((int)idx, (list) x)

Sets the chromosome of the PyGMO.individual with index idx in the population to x. Updates autatically the memory and the population champion

from PyGMO import *
prob = problem.schwefel(2)
pop = population(prob,2)
pop.set_x(0,[3.12,4.56])

set_v((int)idx, (list) v)

Sets the velocity of the PyGMO.individual with index idx in the population to v

from PyGMO import *
prob = problem.schwefel(2)
pop = population(prob,2)
pop.set_v(0,[0.12,-0.22])

get_domination_list((int)idx)

Returns a list containing all the indexes of the individual dominated by the individual with index idx

from PyGMO import *
prob = problem.zdt(1)
pop = population(prob,10)
ls = pop.get_domination_list(1)

get_domination_count((int)idx)

Returns the domination count for the individual idx (that is how many individuals in the population dominate idx?)

from PyGMO import *
prob = problem.zdt(1)
pop = population(prob,10)
c = pop.get_domination_count(1)

compute_pareto_fronts()

Returns the Pareto fronts of the population in form of a list of lists each one containing the idx of the individuals belonging to a particular Pareto Front

from PyGMO import *
prob = problem.zdt(1)
pop = population(prob,10)
pf = pop.compute_pareto_fronts()

plot_pareto_fronts(comp = [0,1])

Plots the pareto fronts in a sliced 2-D graph representing the two objective function components specified in comp

from PyGMO import *
prob = problem.zdt(1)
pop = population(prob,100)
pf = pop.plot_pareto_fronts()

get_best_idx((int) n)

Returns the n best indexes of the PyGMO.individual in a population. The best PyGMO.individual are computed according to non-dominated sorting in populations that have a multi-objective problem.

get_worst_idx()

Returns the index of the worst PyGMO.individual in a population. The worst PyGMO.individual is computed according to non-dominated sorting in populations that have a multi-objective problem.

from PyGMO import *
prob = problem.zdt(3)
pop = population(prob,3) #population with 3 individuals
best_guy = pop.get_best_idx()
worst_guy = pop.get_worst_idx()

mean_velocity()

Evaluates the population mean velocity

from PyGMO import *
prob = problem.schwefel(3)
pop = population(prob,30)
v = pop.mean_velocity()

race((int) n_winners, (int) min_trials=0, (int) max_feval=500, (float) delta=0.05, (list) racers_idx=[])

Races individuals in a population

• n_winners: number of winners in the race
• min_trials: minimum amount of evaluations before an individual can stop racing
• delta: Statistical test confidence
• racers_idx: indices of the individuals in pop to be raced
repair((int) idx, (:class:problem) repair_algo)

Repairs the individual at the position idx

• idx: index of the individual to repair
• repair_algo: ‘repairing’ optimization algorithm to use. It should be able to deal with population of size 1.
champion

Returns a copy of the population PyGMO.champion

problem

Returns a copy of the problem in the population

NOTE: since it is only a copy that is returned, it is impossible to modify a problem in a population directly. The following code is thus WRONG as it changes the bounds of an instance of the problem that is created on the fly and then destroyed

from PyGMO import *
prob = problem.schwefel(3)
pop = population(prob,30)
lb = list(prob.lb)
ub = list(prob.ub)
lb[0]=-10
pop.problem.set_bounds(lb,ub) #This line is completely uneffective ...