public void CalculateDifferences(GeneticPopulation population, GeneticBlackBox blackBox)
 {
     foreach (GeneticSample sample in population.Samples)
     {
         sample.DifferenceUnits = blackBox.GetDifferenceUnits(sample.Color);
         sample.DifferencePercents = blackBox.GetDifferencePercents(sample.Color);
         sample.SimilarityUnits = blackBox.GetSimilarityUnits(sample.Color);
         sample.SimilarityPercents = blackBox.GetSimilarityPercents(sample.Color);
     }
 }
        private void Work()
        {
            State = States.Working;

            CalculationStarted();

            GeneticPopulation population;

            InitPopulation(out population);

            var blackBox = new GeneticBlackBox(_settings.Target,
                (GeneticBlackBox.ComparsionMethods)_settings.Comparsion);

            int i;
            for (i = 0; i < _settings.Iterations; i++)
            {
                if (State == States.Aborting)
                    break;

                CalculateDifferences(population,blackBox);
                SortPopulation(population);

                PopulationCalculated(Convert.ToByte(100*i/_settings.Iterations), population);

                if (population.Elite.DifferenceUnits == 0)
                    break;
                if (i < _settings.Iterations-1)
                    CrossPopulation(population);
            }

            if (State == States.Aborting)
                CalculationAborted(100, population);
            else
                CalculationSucess(100, population);

            State = States.Idle;
        }