コード例 #1
0
        private int SelectParentIndex(int?blockedIndex)
        {
            var indices = new List <int>();

            for (var i = 0; i < _generation.Count; i++)
            {
                if (blockedIndex.HasValue && blockedIndex.Value == i)
                {
                    continue;
                }
                for (var j = 0; j < _generation[i].NormalizedScore; j++)
                {
                    indices.Add(i);
                }
            }

            var result = GoodRandom.Next(indices.Count);

            return(indices[result]);
        }
コード例 #2
0
        private void KillHalfOfTheGeneration()
        {
            var indicesOfGraphsToRemove = new List <int>();
            var index = 0;

            while (indicesOfGraphsToRemove.Count < _generationSize / 2)
            {
                if (GoodRandom.Next(_generationSize) > index && !indicesOfGraphsToRemove.Contains(index))
                {
                    indicesOfGraphsToRemove.Add(index);
                }

                index = (index + 1) % _generationSize;
            }

            indicesOfGraphsToRemove.Sort((index1, index2) => - index1.CompareTo(index2));
            foreach (var i in indicesOfGraphsToRemove)
            {
                _generation.RemoveAt(i);
            }
        }