Example #1
0
        public IChromosome FlipNodeOnChromosoe(IChromosome chromosome, int maxDiffBetweenNode, IMatrix matrix)
        {
            var         maxIteration     = 20;
            var         currentIteration = 0;
            IChromosome temp;

            do
            {
                temp = chromosome.DeepCopy();

                var(left, rigth) = GetLeftAndRigthUniqueNodeNumbers(temp);

                temp = FlipNodeAndRecalculateFactors(matrix, temp, left, rigth);

                currentIteration++;

                if (IsNodeCountValid(temp.Distribution, maxDiffBetweenNode) == true)
                {
                    return(temp.DeepCopy());
                }

                if (currentIteration > maxIteration)
                {
                    return(chromosome.DeepCopy());
                }
            } while (IsNodeCountValid(temp.Distribution, maxDiffBetweenNode) == false);

            return(chromosome.DeepCopy());
        }
Example #2
0
        private IChromosome FlipNodeAndRecalculateFactors(IMatrix matrix, IChromosome temp, int left, int rigth)
        {
            temp.Distribution[left]  = ChromosomePart.Second;
            temp.Distribution[rigth] = ChromosomePart.First;

            temp.Factors = GetChromosomeFactors(temp.Distribution, matrix);

            return(temp.DeepCopy());
        }