esa / pygmo2

A Python platform to perform parallel computations of optimisation tasks (global and local) via the asynchronous generalized island model.
https://esa.github.io/pygmo2/
Mozilla Public License 2.0
422 stars 57 forks source link

Population champion not updated after evolution #74

Closed JenEy-git closed 3 years ago

JenEy-git commented 3 years ago

Hello, I'm trying to use pygmo to optimize the position of some plants in a Garden. The fitness function is non linear, and I have also a non-linear equality constraint. I used the local solver of scipy "trust-constr". the problem I have is that the value of the champion does not seem to be updated after the evolution.

Printing the population before and after evoution, the individual is converging to the minimum. But the champion is not updated. What could be the problem? (See below for the prints)

The code I use is very simple: gd_pos = Pl.PlantPosition(inter_mat, lh_garden, pos_plant_fixed, radii_non_overlap, radii_inter) # user defined problem prob = pg.problem(gd_pos) algo = pg.algorithm(pg.scipy_optimize(method="trust-constr")) pop = pg.population(prob, size=1) print(pop) pop = algo.evolve(pop) print(pop)

PRINT BEFORE EVOLUTION: "Problem name: Plant Positioning C++ class name: pybind11::object

Global dimension:           6
Integer dimension:          0
Fitness dimension:          2
Number of objectives:           1
Equality constraints dimension:     1
Inequality constraints dimension:   0
Tolerances on constraints: [0]
Lower bounds: [0, 0, 0, 0, 0, ... ]
Upper bounds: [1, 1, 1, 1, 1, ... ]
Has batch fitness evaluation: false

Has gradient: true
User implemented gradient sparsity: false
Expected gradients: 12
Has hessians: false
User implemented hessians sparsity: false

Fitness evaluations: 1
Gradient evaluations: 0

Thread safety: none

Extra info:

Number of plants: 3

[XY] size of the garden: [1 1]

Matrix interaction: [[0 1 1] [1 0 1] [1 1 0]]

Radii vector: [0.1 0.1 0.1]

Population size: 1

List of individuals:

0:

ID:         11859392664243719972
Decision vector:    [0.411191, 0.620839, 0.740699, 0.543479, 0.922681, ... ]
Fitness vector:     [-3.37961, 0]

Champion decision vector: [0.411191, 0.620839, 0.740699, 0.543479, 0.922681, ... ] Champion fitness: [-3.37961, 0] "

PRINT AFTER THE EVOLUTION: "Problem name: Plant Positioning C++ class name: pybind11::object

Global dimension:           6
Integer dimension:          0
Fitness dimension:          2
Number of objectives:           1
Equality constraints dimension:     1
Inequality constraints dimension:   0
Tolerances on constraints: [0]
Lower bounds: [0, 0, 0, 0, 0, ... ]
Upper bounds: [1, 1, 1, 1, 1, ... ]
Has batch fitness evaluation: false

Has gradient: true
User implemented gradient sparsity: false
Expected gradients: 12
Has hessians: false
User implemented hessians sparsity: false

Fitness evaluations: 171
Gradient evaluations: 169

Thread safety: none

Extra info:

Number of plants: 3

[XY] size of the garden: [1 1]

Matrix interaction: [[0 1 1] [1 0 1] [1 1 0]]

Radii vector: [0.1 0.1 0.1]

Population size: 1

List of individuals:

0:

ID:         11859392664243719972
Decision vector:    [0.454543, 0.577233, 0.652667, 0.45644, 0.61438, ... ]
Fitness vector:     [-5.67577, 7.33971e-17]

Champion decision vector: [0.411191, 0.620839, 0.740699, 0.543479, 0.922681, ... ] Champion fitness: [-3.37961, 0] "

bluescarni commented 3 years ago

I am pinging @mlooz on this as he originally wrote the scipy wrapper.

I am a bit confused, because this looks like a multiobjective problem, but I thought the scipy algorithms solve only single-objective problems?

mlooz commented 3 years ago

It is not multi-objective, but has a constraint. I think that since the new individual with fitness [-5.67577, 7.33971e-17] technically violates the constraint (by 7.33971e-17), it is not regarded as a feasible solution to be the new champion.

What happens if you set the constraint tolerance c_tol of the problem to something bigger, i.e. 1e-16?

JenEy-git commented 3 years ago

Hello, Increasing constraint tolerance solves the problem ! This is linked to the ordering of the population for a constrained problem Thank your for your answer. Julien

Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ Le mercredi 2 juin 2021 à 00:30, Moritz v. Looz @.***> a écrit :

It is not multi-objective, but has a constraint. I think that since the new individual with fitness [-5.67577, 7.33971e-17] technically violates the constraint (by 7.33971e-17), it is not regarded as a feasible solution to be the new champion.

What happens if you set the constraint tolerance c_tol of the problem to something bigger, i.e. 1e-16?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.