Beispiel #1
0
        /// <summary>
        /// Gets a new Decision Vector where elements which pass the conditions have potentially been mutated.
        /// </summary>
        /// <param name="decisionVector"><see cref="DecisionVector"/> to mutate.</param>
        /// <returns>A mutated Decision Vector.</returns>
        public DecisionVector Operate(DecisionVector decisionVector)
        {
            var elementsToMutate = decisionVector.Select(e => conditions.All(c => c(e)));
            var tempDs           = new DecisionSpace(decisionVector.GetDecisionSpace().Where((d, i) => elementsToMutate.ElementAt(i)));
            var tempDv           = DecisionVector.CreateFromArray(tempDs, decisionVector.Where((e, i) => elementsToMutate.ElementAt(i)));
            var newElements      = mutation.Operate(tempDv);

            var newVector = decisionVector.ToArray();
            var item      = 0;

            for (var i = 0; i < newVector.Length; i++)
            {
                if (elementsToMutate.ElementAt(i))
                {
                    newVector[i] = newElements.ElementAt(item);
                    item++;
                }
            }

            return(DecisionVector.CreateFromArray(decisionVector.GetDecisionSpace(), newVector));
        }