/// <summary> /// Construct the object, weighted problems. /// </summary> /// <param name="optimizer">Optimize to be used.</param> /// <param name="weightedProblems">Array of weighted problems to be optimized.</param> /// <param name="numRuns">Number of optimization runs per problem.</param> public MetaFitness(Optimizer optimizer, WeightedProblem[] weightedProblems, int numRuns) : base() { Optimizer = optimizer; NumRuns = numRuns; ProblemIndex = new ProblemIndex(weightedProblems); }
/// <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)); } }
/// <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)); } }