Open
Description
Hi there,
I'm using the multi-objective pygad implementation with parent_selection_type='nsga2'. I'm interested in the pareto optimal solutions. I can easily plot and extract the fitness values on the pareto front, but how to I access the solutions that are related to the pareto optimal fitness values. For example, if my pareto front plot looks like this:
how do I index the solutions (genes) that correspond to the pareto fitness values?
Kind regards,
Lise
Activity
ahmedfgad commentedon Jan 20, 2025
You can use the pareto_fronts property.
LisieP commentedon Jan 21, 2025
Yes, this is what I did. To give some context, I'm interested in finding the weights for capacity allocation to wind farms. If the generation of each farm is represented by , the GA must find the optimal weights, to meet some multi-objective function on the total generation. The total wind generation is expressed as
So when I access the pareto fronts using
ga_inst.pareto_fronts
I get an array of the pareto front fitness values:
array([[0, array([-1.27360746e+08, -3.72970936e+03])], [1, array([-1.27360746e+08, -3.72970936e+03])], [3, array([-1.26405006e+08, -3.73510505e+03])], [8, array([-1.25557120e+08, -3.73989184e+03])], [14, array([-1.24510645e+08, -3.74579978e+03])])
where I'm interested in the weights, , that correspond to the pareto front fitness values. Also, my two objectives have significantly different scales, will this influence the chosen optimal solution?
Also- follow up question, the way I ensure that is by applying a large penalty in the fitness function when the sum of the weights exceed one. Is there another work around for constraints in which variables are related to one another? For example I could scale the weights in the
on_mutation()
callback to force all the solutions in the new generation to adhere to the constraint. This is what I've come up with:I have a helper function called
apply_constraints()
which applies the sum constraint to a solution similar to this. So myon_mutation()
function looks like this:when the fitness of each solution is calculated as:
I still get solutions that violate the constraints, also, I get many instances of
solution_idx = None
ahmedfgad commentedon Feb 6, 2025
The first value of each element in
ga_inst.pareto_fronts
represents the index of the solution in thega_inst.population
array. If you want the actual chromosome/solution, you can retrieve it. For example,ga_inst.population[ga_inst.pareto_fronts[0][0]
.Unfortunately applying constraints is not supported yet. Your suggested solution works. You can also restrict the values of each gene using the
gene_space
parameter. Not sure if this is going to work but if you have like 5 genes, you can split the range from 0 to 1 into 5 sets (0-0.2, 0.2-0.4, 0.4-0.6,0.6-0.8,0.8-1.0) and assign each gene a single range.