public override IOperation Apply() { ItemArray <BoolArray> cases = CasesParameter.ActualValue; ItemArray <DoubleArray> caseQualities = CaseQualitiesParameter.ActualValue; int length = cases.First().Length; if (cases.Any(x => x.Length != length) || caseQualities.Any(x => x.Length != length)) { throw new ArgumentException("Every individual has to have the same number of cases."); } double count = cases.Count(); int rows = cases.First().Length; ResultCollection results = ResultsParameter.ActualValue; DataTable casesSolvedFrequencies = CasesSolvedFrequenciesParameter.ActualValue; DataTable summedCaseQualities = SummedCaseQualitiesParameter.ActualValue; if (casesSolvedFrequencies == null || summedCaseQualities == null) { casesSolvedFrequencies = new DataTable("Cases solved", "Absolute frequency of cases solved aggregated over the whole population."); casesSolvedFrequencies.VisualProperties.YAxisTitle = "Absolute Cases Solved Frequency"; summedCaseQualities = new DataTable("Summed case qualities", "Absolute frequency of cases solved aggregated over the whole population."); summedCaseQualities.VisualProperties.YAxisTitle = "Summed Cases Qualities"; CasesSolvedFrequenciesParameter.ActualValue = casesSolvedFrequencies; SummedCaseQualitiesParameter.ActualValue = summedCaseQualities; results.Add(new Result("Cases solved", casesSolvedFrequencies)); results.Add(new Result("Summed cases qualities", summedCaseQualities)); } // all rows must have the same number of values so we can just take the first int numberOfValues = casesSolvedFrequencies.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First(); foreach (var triple in Enumerable.Range(0, cases[0].Length).Select(i => new Tuple <string, int, double>("Case " + i, cases.Count(caseArray => caseArray[i]), caseQualities.Sum(casesQualityArray => casesQualityArray[i])))) { if (!casesSolvedFrequencies.Rows.ContainsKey(triple.Item1)) { // initialize a new row for the symbol and pad with zeros DataRow row = new DataRow(triple.Item1, "", Enumerable.Repeat(0.0, numberOfValues)); row.VisualProperties.StartIndexZero = true; casesSolvedFrequencies.Rows.Add(row); row = new DataRow(triple.Item1, "", Enumerable.Repeat(0.0, numberOfValues)); row.VisualProperties.StartIndexZero = true; summedCaseQualities.Rows.Add(row); } casesSolvedFrequencies.Rows[triple.Item1].Values.Add(triple.Item2); summedCaseQualities.Rows[triple.Item1].Values.Add(triple.Item3); } return(base.Apply()); }