Accord.Genetic.OptimizationFunction2D.Translate C# (CSharp) Method

Translate() public method

Translates genotype to phenotype
The method returns array of two double values, which represent function's input point (X and Y) encoded by the specified chromosome.
public Translate ( IChromosome chromosome ) : double[]
chromosome IChromosome Chromosome, which genoteype should be /// translated to phenotype
return double[]
        public double[] Translate(IChromosome chromosome)
        {
            // get chromosome's value
            ulong val = ((BinaryChromosome)chromosome).Value;
            // chromosome's length
            int length = ((BinaryChromosome)chromosome).Length;
            // length of X component
            int xLength = length / 2;
            // length of Y component
            int yLength = length - xLength;
            // X maximum value - equal to X mask
            ulong xMax = 0xFFFFFFFFFFFFFFFF >> (64 - xLength);
            // Y maximum value
            ulong yMax = 0xFFFFFFFFFFFFFFFF >> (64 - yLength);
            // X component
            double xPart = val & xMax;
            // Y component;
            double yPart = val >> xLength;

            // translate to optimization's funtion space
            double[] ret = new double[2];

            ret[0] = xPart * rangeX.Length / xMax + rangeX.Min;
            ret[1] = yPart * rangeY.Length / yMax + rangeY.Min;

            return ret;
        }