Skip to content

Commit

Permalink
Parallel population generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Danilo Corallo committed Jan 11, 2019
1 parent bf3c513 commit 6ea5a9f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/GeneticSharp.Domain/Populations/Population.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using GeneticSharp.Domain.Chromosomes;
using GeneticSharp.Infrastructure.Framework.Commons;

Expand Down Expand Up @@ -117,9 +120,8 @@ public virtual void CreateInitialGeneration()
Generations = new List<Generation>();
GenerationsNumber = 0;

var chromosomes = new List<IChromosome>();

for (int i = 0; i < MinSize; i++)
var chromosomes = new ConcurrentBag<IChromosome>();
Parallel.For(0, MinSize, i =>
{
var c = AdamChromosome.CreateNew();
Expand All @@ -131,9 +133,9 @@ public virtual void CreateInitialGeneration()
c.ValidateGenes();
chromosomes.Add(c);
}
});

CreateNewGeneration(chromosomes);
CreateNewGeneration(chromosomes.ToList());
}

/// <summary>
Expand Down

0 comments on commit 6ea5a9f

Please sign in to comment.