Skip to content

Commit 68674ea

Browse files
committed
Make k parameter of tournament configurable
1 parent ba1f22f commit 68674ea

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

‎mlp-ea-decentralized/common/ga/poolModel.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ type PoolModel struct {
4545
BestCallback func(*PoolModel)
4646
GenerationCallback func(*PoolModel)
4747

48-
CrossRate float64
49-
MutRate float64
48+
NCandidates int
49+
CrossRate float64
50+
MutRate float64
5051

5152
PopSize int
5253
MaxEvaluations int
@@ -85,6 +86,7 @@ func MakePool(
8586
pool := &PoolModel{
8687
Rnd: rnd,
8788
PopSize: popSize,
89+
NCandidates: 4,
8890
population: MakePopulation(),
8991
popSemaphore: make(semaphore, popSize),
9092
evaluations: 0,
@@ -150,10 +152,10 @@ func (pool *PoolModel) Minimize() {
150152

151153
// At least nOffsprings shold be available in the population
152154
// tu run this operator
153-
pool.popSemaphore.Acquire(4)
155+
pool.popSemaphore.Acquire(pool.NCandidates)
154156

155157
// take here randomly from population
156-
offsprings = pool.selection(4, 4)
158+
offsprings = pool.selection(4, pool.NCandidates)
157159
offsprings = pool.crossover(offsprings)
158160
offsprings = pool.mutate(offsprings)
159161

0 commit comments

Comments
 (0)