Example #1
0
        /// <summary>
        /// Example method evaluating optimization cycles of different matchers with 100 generated dummy participants
        /// </summary>
        public void TaskRunCompareMatchersOptimization()
        {
            GroupFormationAlgorithm    gf;
            TextFileCohortReaderWriter CohortWriter = new TextFileCohortReaderWriter();
            string filename = "ExampleOptimizationProcessForeachMatcher.csv";
            // columns header of CSV file
            string output = "MatcherName" + separator + "Cycle" + separator + "CohortPerformanceIndex" + separator + "CohortAverage" + separator + "OptimizationCount" + newLine;

            CohortWriter.WriteTemporaryResultsToFile(output, filename, true);

            List <IMatcher> matchers = new List <IMatcher> {
                new GroupALGroupCentricMatcher(), new GroupALParticipantCentricMatcher(), new RandomMatcher()
            };

            int GroupSize            = 6;
            int cycles               = 10;
            int CountOfOptimizations = 5;

            for (int i = 0; i < cycles; i++)
            {
                participants = ParticipantGenerator.DummyEntries(100);
                foreach (IMatcher matcher in matchers)
                {
                    gf = new GroupFormationAlgorithm(participants, matcher, new GroupALEvaluator(), new GroupALOptimizer(matcher), GroupSize);
                    gf.DoOneFormation();

                    for (int j = 0; j < CountOfOptimizations; j++)
                    {
                        if (j == 0)
                        {
                            output = gf.Cohort.whichMatcherUsed + separator + i + separator + gf.Cohort.results.performanceIndex + separator + gf.Cohort.results.avg + separator + j + newLine;
                            CohortWriter.WriteTemporaryResultsToFile(output.Replace(",", replacementForNumberComma), filename, false);
                            continue;
                        }
                        gf.OptimizeCohort();
                        output = gf.Cohort.whichMatcherUsed + separator + i + separator + gf.Cohort.results.performanceIndex + separator + gf.Cohort.results.avg + separator + j + newLine;
                        CohortWriter.WriteTemporaryResultsToFile(output.Replace(",", replacementForNumberComma), filename, false);
                    }
                }
            }
        }