From 5e4eee885368b4082518bbf44a21b0d2682c05f4 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 21 Feb 2023 22:03:10 +0100 Subject: [PATCH] ga/population: idiomaticise init --- algo/ga/population.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/algo/ga/population.go b/algo/ga/population.go index e4dcd6f..1b2fac9 100644 --- a/algo/ga/population.go +++ b/algo/ga/population.go @@ -230,16 +230,12 @@ func (p *Population) Size() int { // newPopulation returns a pointer to a new, uninitialised population. func newPopulation(benchProblem string, np, dimen int) *Population { - p := &Population{} - - p.Problem = benchProblem - - p.ProblemFunc = cec2020.Functions[benchProblem] - - p.Dimen = dimen - - // pre-alloc. - p.Population = make([]PopulationIndividual, np) + p := &Population{ + Problem: benchProblem, + ProblemFunc: cec2020.Functions[benchProblem], + Dimen: dimen, + Population: make([]PopulationIndividual, np), + } return p }