Example #1
0
        public void Mutate(Mutator mutator, int maxSize, float percent, float countPercent)
        {
            int flipCount = (int)((_knapsack.ItemValues.Length * percent) * 0.5f);
            int count     = (int)((maxSize * percent) * 0.5f);

            Mutator.Shuffle(_configurations);
            List <Configuration> newConfigs = new List <Configuration>(count);

            for (int i = 0; i < count && i < _configurations.Count; i++)
            {
                Configuration config = new Configuration(_configurations[i]);
                config.Mutate(mutator, flipCount);
                newConfigs.Add(config);
            }
            _configurations.AddRange(newConfigs);
        }
Example #2
0
        public void Cross(Mutator mutator, int maxSize, Generation other, float percent, float countPercent)
        {
            int crossCount = (int)((_knapsack.ItemValues.Length * percent) * 0.5f);
            int count      = (int)((maxSize * percent) * 0.5f);

            Configuration[] prevConfigs = new Configuration[other._configurations.Count];
            other._configurations.CopyTo(prevConfigs);
            Mutator.Shuffle(_configurations);
            List <Configuration> newConfigs = new List <Configuration>(count);

            for (int i = 0; i < count && i < other._configurations.Count; i++)
            {
                Configuration config = new Configuration(_configurations[i]);
                config.Cross(mutator, prevConfigs[i], crossCount);
                newConfigs.Add(config);
            }
            _configurations.AddRange(newConfigs);
        }