public override IOperation Apply() { ItemArray <RealVector> parameterVectors = ParameterVectorParameter.ActualValue; ItemArray <DoubleValue> qualities = QualityParameter.ActualValue; bool max = MaximizationParameter.ActualValue.Value; DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; var solutions = parameterVectors.Zip(qualities, (ParameterVector, Quality) => new { ParameterVector, Quality }); if (max) { solutions = solutions.MaxItems(s => s.Quality.Value); } else { solutions = solutions.MinItems(s => s.Quality.Value); } if (BestQualityParameter.ActualValue == null) { if (max) { BestQualityParameter.ActualValue = new DoubleValue(double.MinValue); } else { BestQualityParameter.ActualValue = new DoubleValue(double.MaxValue); } } if (PreviousBestQualityParameter.ActualValue == null) { PreviousBestQualityParameter.ActualValue = (DoubleValue)BestQualityParameter.ActualValue.Clone(); } //add result for best solutions ResultCollection results = ResultsParameter.ActualValue; if (!results.ContainsKey(BestSolutionsResultName)) { results.Add(new Result(BestSolutionsResultName, new ItemSet <DoubleArray>(new DoubleArrayEqualityComparer()))); } var previousBestQuality = PreviousBestQualityParameter.ActualValue.Value; var bestQuality = solutions.First().Quality.Value; var bestSolutions = (ItemSet <DoubleArray>)results[BestSolutionsResultName].Value; //clear best solutions if new found quality is better than the existing one if (max && bestQuality > previousBestQuality || !max && bestQuality < previousBestQuality) { bestSolutions.Clear(); } //add new found solutions if (max && bestQuality >= BestQualityParameter.ActualValue.Value || !max && bestQuality <= BestQualityParameter.ActualValue.Value) { foreach (var solution in solutions) { var newSolution = (DoubleArray)solution.ParameterVector.Clone(); newSolution.ElementNames = ParameterNamesParameter.ActualValue; bestSolutions.Add(newSolution); } } //update best quality if (max && bestQuality >= BestQualityParameter.ActualValue.Value || !max && bestQuality <= BestQualityParameter.ActualValue.Value) { BestQualityParameter.ActualValue.Value = bestQuality; } //update best known quality if (bestKnownQuality == null || max && bestQuality > bestKnownQuality.Value || !max && bestQuality < bestKnownQuality.Value) { BestKnownQualityParameter.ActualValue = new DoubleValue(bestQuality); } PreviousBestQualityParameter.ActualValue = (DoubleValue)BestQualityParameter.ActualValue.Clone(); return(base.Apply()); }