~alexreg/darwindotnet/0.1

« back to all changes in this revision

Viewing changes to DarwinDotNet/Selectors/RandomSelector.cs

  • Committer: Alex Regueiro
  • Date: 2009-03-27 19:00:22 UTC
  • Revision ID: alexreg@gmail.com-20090327190022-f571a7jsdwv3dny5
Updated XML comments for documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
            int selectionMaxIndex = 0; // exclusive maximum
33
33
            int[] selectionIndices = null;
34
 
            if (!this.PerformReplacement)
 
34
            if (!PerformReplacement)
35
35
                selectionIndices = new int[count];
36
36
 
37
37
            var newListCapacity = newChromosomes.Capacity;
38
38
            int curSelectionIndex;
39
39
            while (newChromosomes.Count < newListCapacity)
40
40
            {
41
 
                if (!this.PerformReplacement && selectionMaxIndex == 0)
 
41
                if (!PerformReplacement && selectionMaxIndex == 0)
42
42
                {
43
43
                    selectionMaxIndex = count;
44
44
                    for (int i = 0; i < selectionMaxIndex; i++)
45
45
                        selectionIndices[i] = i;
46
46
                }
47
47
 
48
 
                if (this.PerformReplacement)
 
48
                if (PerformReplacement)
49
49
                {
50
 
                    newChromosomes.Add(chromosomes[_rand.Next(count)].Clone(false));
 
50
                    newChromosomes.Add(chromosomes[rand.Next(count)].Clone(false));
51
51
                }
52
52
                else
53
53
                {
54
 
                    curSelectionIndex = _rand.Next(selectionMaxIndex);
 
54
                    curSelectionIndex = rand.Next(selectionMaxIndex);
55
55
                    newChromosomes.Add(chromosomes[selectionIndices[curSelectionIndex]].Clone(false));
56
56
                    selectionIndices[curSelectionIndex] = selectionIndices[--selectionMaxIndex];
57
57
                }