Esempio n. 1
0
        /// <summary>
        /// Construct the ProblemIndex-object.
        /// </summary>
        /// <param name="weightedProblems">The problems to be indexed.</param>
        public ProblemIndex(WeightedProblem[] weightedProblems)
            : base()
        {
            Index = new List<ProblemFitness>(weightedProblems.Count());

            double weightSum = weightedProblems.Sum(o => o.Weight);

            foreach (WeightedProblem weightedProblem in weightedProblems)
            {
                Problem problem = weightedProblem.Problem;
                double weight = weightedProblem.Weight;
                double weightNormalized = weight / weightSum;

                Debug.Assert(weight > 0);

                Index.Add(new ProblemFitness(problem, weightNormalized));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Construct the ProblemIndex-object.
        /// </summary>
        /// <param name="weightedProblems">The problems to be indexed.</param>
        public ProblemIndex(WeightedProblem[] weightedProblems)
            : base()
        {
            // Ensure array has elements.
            Debug.Assert(weightedProblems.Length > 0);

            Index = new List<ProblemFitness>(weightedProblems.Length);

            double weightSum = weightedProblems.Sum(o => o.Weight);

            foreach (WeightedProblem weightedProblem in weightedProblems)
            {
                Problem problem = weightedProblem.Problem;
                double weight = weightedProblem.Weight;
                double weightNormalized = weight / weightSum;

                // Ensure weight is positive.
                Debug.Assert(weight > 0);

                Index.Add(new ProblemFitness(problem, weightNormalized));
            }
        }